[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 27 07:39:46 PST 2025


================
@@ -73,9 +106,46 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr<llvm::telemetry::Config> m_config;
+  // Each instance of a TelemetryManager is assigned a unique ID.
+  const std::string m_id;
+
   static std::unique_ptr<TelemetryManager> g_instance;
 };
 
+/// Helper RAII class for collecting telemetry.
+class ScopeTelemetryCollector {
+public:
+  ScopeTelemetryCollector() {
+    if (TelemetryEnabled())
+      m_start = std::chrono::steady_clock::now();
+  }
+
+  ~ScopeTelemetryCollector() {
+    while (!m_exit_funcs.empty()) {
+      (m_exit_funcs.top())();
+      m_exit_funcs.pop();
+    }
+  }
+
+  bool TelemetryEnabled() {
+    TelemetryManager *instance = TelemetryManager::GetInstance();
+    return instance != nullptr && instance->GetConfig()->EnableTelemetry;
----------------
labath wrote:

Okay, but why does GetInstance return a valid object if telemetry is disabled (at runtime)? Why does the TelemetryManager object even get created in this case? (Maybe there is a reason for that, but in that case, I'd like to understand why)

https://github.com/llvm/llvm-project/pull/127696


More information about the lldb-commits mailing list