Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 "common/config_obs.h"
8 #include "common/Mutex.h"
9 #include <dlfcn.h>
10
11 struct md_config_t;
12
13 class TracepointProvider : public md_config_obs_t, boost::noncopyable {
14 public:
15   struct Traits {
16     const char *library;
17     const char *config_key;
18
19     Traits(const char *library, const char *config_key)
20       : library(library), config_key(config_key) {
21     }
22   };
23
24   class Singleton {
25   public:
26     Singleton(CephContext *cct, const char *library, const char *config_key)
27       : tracepoint_provider(new TracepointProvider(cct, library, config_key)) {
28     }
29     ~Singleton() {
30       delete tracepoint_provider;
31     }
32
33     inline bool is_enabled() const {
34       return tracepoint_provider->m_handle != nullptr;
35     }
36   private:
37     TracepointProvider *tracepoint_provider;
38   };
39
40   template <const Traits &traits>
41   class TypedSingleton : public Singleton {
42   public:
43     explicit TypedSingleton(CephContext *cct)
44       : Singleton(cct, traits.library, traits.config_key) {
45     }
46   };
47
48   TracepointProvider(CephContext *cct, const char *library,
49                      const char *config_key);
50   ~TracepointProvider() override;
51
52   template <const Traits &traits>
53   static void initialize(CephContext *cct) {
54 #ifdef WITH_LTTNG
55     TypedSingleton<traits> *singleton;
56     cct->lookup_or_create_singleton_object(singleton, traits.library);
57 #endif
58   }
59
60 protected:
61   const char** get_tracked_conf_keys() const override {
62     return m_config_keys;
63   }
64   void handle_conf_change(const struct md_config_t *conf,
65                                   const std::set <std::string> &changed) override;
66
67 private:
68   CephContext *m_cct;
69   std::string m_library;
70   mutable const char* m_config_keys[2];
71
72   Mutex m_lock;
73   void* m_handle = nullptr;
74
75   void verify_config(const struct md_config_t *conf);
76 };
77
78 #endif // CEPH_TRACEPOINT_PROVIDER_H