5252#include " lldb/Utility/State.h"
5353#include " lldb/Utility/Stream.h"
5454#include " lldb/Utility/StreamString.h"
55+ #include " lldb/Core/Telemetry.h"
5556#include " lldb/lldb-enumerations.h"
5657
5758#if defined(_WIN32)
7071#include " llvm/Support/Threading.h"
7172#include " llvm/Support/raw_ostream.h"
7273
73- #ifdef LLVM_BUILD_TELEMETRY
74- #include " lldb/Core/Telemetry.h"
75- #include < chrono>
76- #endif
7774
75+ #include < chrono>
7876#include < cstdio>
7977#include < cstdlib>
8078#include < cstring>
@@ -767,29 +765,27 @@ void Debugger::InstanceInitialize() {
767765
768766DebuggerSP Debugger::CreateInstance (lldb::LogOutputCallback log_callback,
769767 void *baton) {
770- #ifdef LLVM_BUILD_TELEMETRY
771- lldb_private::telemetry::SteadyTimePoint start_time =
772- std::chrono::steady_clock::now ();
773- #endif
768+ lldb_private::telemetry::ScopeTelemetryCollector helper;
774769 DebuggerSP debugger_sp (new Debugger (log_callback, baton));
770+
771+ if (helper.TelemetryEnabled ()) {
772+ helper.RunAtScopeExit ([&](){
773+ lldb_private::telemetry::TelemetryManager * manager = lldb_private::telemetry::TelemetryManager::GetInstance ();
774+ lldb_private::telemetry::DebuggerInfo entry;
775+ entry.debugger = debugger_sp.get ();
776+ entry.start_time = helper.GetStartTime ();
777+ entry.end_time = helper.GetCurrentTime ();
778+ manager->AtDebuggerStartup (&entry);
779+ });
780+
781+ }
782+
775783 if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
776784 std::lock_guard<std::recursive_mutex> guard (*g_debugger_list_mutex_ptr);
777785 g_debugger_list_ptr->push_back (debugger_sp);
778786 }
779787 debugger_sp->InstanceInitialize ();
780788
781- #ifdef LLVM_BUILD_TELEMETRY
782- if (auto *telemetry_manager = telemetry::TelemetryManager::getInstance ()) {
783- if (telemetry_manager->getConfig ()->EnableTelemetry ) {
784- lldb_private::telemetry::DebuggerTelemetryInfo entry;
785- entry.start_time = start_time;
786- entry.end_time = std::chrono::steady_clock::now ();
787- entry.debugger = debugger_sp.get ();
788- telemetry_manager->atDebuggerStartup (&entry);
789- }
790- }
791- #endif
792-
793789 return debugger_sp;
794790}
795791
@@ -1010,10 +1006,20 @@ void Debugger::Clear() {
10101006 // static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp);
10111007 // static void Debugger::Terminate();
10121008 llvm::call_once (m_clear_once, [this ]() {
1013- #ifdef LLVM_BUILD_TELEMETRY
1014- lldb_private::telemetry::SteadyTimePoint quit_start_time =
1015- std::chrono::steady_clock::now ();
1016- #endif
1009+ lldb_private::telemetry::ScopeTelemetryCollector helper;
1010+ if (helper.TelemetryEnabled ()) {
1011+ // TBD: We *may* have to send off the log BEFORE the ClearIOHanders()?
1012+ helper.RunAtScopeExit ([&helper, this ](){
1013+ lldb_private::telemetry::TelemetryManager* manager
1014+ = lldb_private::telemetry::TelemetryManager::GetInstance ();
1015+ lldb_private::telemetry::DebuggerInfo entry;
1016+ entry.debugger = this ;
1017+ entry.exit_desc = {0 , " " }; // If we are here, there was no error.
1018+ entry.start_time = helper.GetStartTime ();
1019+ entry.end_time = helper.GetCurrentTime ();
1020+ manager->AtDebuggerExit (&entry);
1021+ });
1022+ }
10171023 ClearIOHandlers ();
10181024 StopIOHandlerThread ();
10191025 StopEventHandlerThread ();
@@ -1036,19 +1042,6 @@ void Debugger::Clear() {
10361042
10371043 if (Diagnostics::Enabled ())
10381044 Diagnostics::Instance ().RemoveCallback (m_diagnostics_callback_id);
1039-
1040- #ifdef LLVM_BUILD_TELEMETRY
1041- if (auto telemetry_manager = telemetry::TelemetryManager::getInstance ()) {
1042- if (telemetry_manager->getConfig ()->EnableTelemetry ) {
1043- // TBD: We *may* have to send off the log BEFORE the ClearIOHanders()?
1044- lldb_private::telemetry::DebuggerTelemetryInfo entry;
1045- entry.start_time = quit_start_time;
1046- entry.end_time = std::chrono::steady_clock::now ();
1047- entry.debugger = this ;
1048- telemetry_manager->atDebuggerExit (&entry);
1049- }
1050- }
1051- #endif
10521045 });
10531046}
10541047
0 commit comments