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