summaryrefslogtreecommitdiffstats
path: root/src/common/TracepointProvider.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/common/TracepointProvider.h
parentInitial commit. (diff)
downloadceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz
ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/TracepointProvider.h')
-rw-r--r--src/common/TracepointProvider.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/common/TracepointProvider.h b/src/common/TracepointProvider.h
new file mode 100644
index 000000000..fe447677c
--- /dev/null
+++ b/src/common/TracepointProvider.h
@@ -0,0 +1,82 @@
+// -*- 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 "common/ceph_context.h"
+#include "common/config_obs.h"
+#include "common/ceph_mutex.h"
+#include "include/dlfcn_compat.h"
+
+class TracepointProvider : public md_config_obs_t {
+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_handle != nullptr;
+ }
+ private:
+ TracepointProvider *tracepoint_provider;
+ };
+
+ template <const Traits &traits>
+ class TypedSingleton : public Singleton {
+ public:
+ explicit TypedSingleton(CephContext *cct)
+ : Singleton(cct, traits.library, traits.config_key) {
+ }
+ };
+
+ TracepointProvider(CephContext *cct, const char *library,
+ const char *config_key);
+ ~TracepointProvider() override;
+
+ TracepointProvider(const TracepointProvider&) = delete;
+ TracepointProvider operator =(const TracepointProvider&) = delete;
+ TracepointProvider(TracepointProvider&&) = delete;
+ TracepointProvider operator =(TracepointProvider&&) = delete;
+
+ template <const Traits &traits>
+ static void initialize(CephContext *cct) {
+#ifdef WITH_LTTNG
+ cct->lookup_or_create_singleton_object<TypedSingleton<traits>>(
+ traits.library, false, cct);
+#endif
+ }
+
+protected:
+ const char** get_tracked_conf_keys() const override {
+ return m_config_keys;
+ }
+ void handle_conf_change(const ConfigProxy& conf,
+ const std::set <std::string> &changed) override;
+
+private:
+ CephContext *m_cct;
+ std::string m_library;
+ mutable const char* m_config_keys[2];
+
+ ceph::mutex m_lock = ceph::make_mutex("TracepointProvider::m_lock");
+ void* m_handle = nullptr;
+
+ void verify_config(const ConfigProxy& conf);
+};
+
+#endif // CEPH_TRACEPOINT_PROVIDER_H