================ @@ -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:
Thanks for the explanation. This makes sense, though I still think it's important to have a simple and succinct way to check whether telemetry is "actually" enabled at a given moment. Right now, we sort of have that as this detail is hidden in the RAII object, but if we find ourselves writing `manager && manage->IsEnabled()` often, would like to create helper function for just that (like a function that doesn't even let you access the telemetry manager object unless you're actually supposed to send something). https://github.com/llvm/llvm-project/pull/127696 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits