/
TracepointProvider.h
83 lines (68 loc) · 2.04 KB
/
TracepointProvider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_TRACEPOINT_PROVIDER_H
#define CEPH_TRACEPOINT_PROVIDER_H
#include "include/int_types.h"
#include "common/ceph_context.h"
#include "common/config_obs.h"
#include "common/Mutex.h"
#include <dlfcn.h>
#include <set>
#include <string>
#include <boost/noncopyable.hpp>
struct md_config_t;
class TracepointProvider : public md_config_obs_t, boost::noncopyable {
public:
struct Traits {
const char *library;
const char *config_key;
Traits(const char *library, const char *config_key)
: library(library), config_key(config_key) {
}
};
class Singleton {
public:
Singleton(CephContext *cct, const char *library, const char *config_key)
: tracepoint_provider(new TracepointProvider(cct, library, config_key)) {
}
~Singleton() {
delete tracepoint_provider;
}
inline bool is_enabled() const {
return tracepoint_provider->m_enabled;
}
private:
TracepointProvider *tracepoint_provider;
};
template <const Traits &traits>
class TypedSingleton : public Singleton {
public:
TypedSingleton(CephContext *cct)
: Singleton(cct, traits.library, traits.config_key) {
}
};
TracepointProvider(CephContext *cct, const char *library,
const char *config_key);
virtual ~TracepointProvider();
template <const Traits &traits>
static void initialize(CephContext *cct) {
#if WITH_LTTNG
TypedSingleton<traits> *singleton;
cct->lookup_or_create_singleton_object(singleton, traits.library);
#endif
}
protected:
virtual const char** get_tracked_conf_keys() const {
return m_config_keys;
}
virtual void handle_conf_change(const struct md_config_t *conf,
const std::set <std::string> &changed);
private:
CephContext *m_cct;
std::string m_library;
mutable const char* m_config_keys[2];
Mutex m_lock;
bool m_enabled;
void verify_config(const struct md_config_t *conf);
};
#endif // CEPH_TRACEPOINT_PROVIDER_H