@@ -43,7 +43,7 @@ static uint64_t ToNanosec(const SteadyTimePoint Point) {
4343
4444// Generate a unique string. This should be unique across different runs.
4545// We build such string by combining three parts:
46- // <16 random bytes>_<timestamp>_<hash of username>
46+ // <16 random bytes>_<timestamp>
4747// This reduces the chances of getting the same UUID, even when the same
4848// user runs the two copies of binary at the same time.
4949static std::string MakeUUID () {
@@ -56,17 +56,9 @@ static std::string MakeUUID() {
5656 randomString = UUID (random_bytes).GetAsString ();
5757 }
5858
59- std::string username = " _" ;
60- UserIDResolver &resolver = lldb_private::HostInfo::GetUserIDResolver ();
61- std::optional<llvm::StringRef> opt_username =
62- resolver.GetUserName (lldb_private::HostInfo::GetUserID ());
63- if (opt_username)
64- username = *opt_username;
65-
6659 return llvm::formatv (
67- " {0}_{1}_{2}" , randomString,
68- std::chrono::steady_clock::now ().time_since_epoch ().count (),
69- llvm::MD5Hash (username));
60+ " {0}_{1}" , randomString,
61+ std::chrono::steady_clock::now ().time_since_epoch ().count ());
7062}
7163
7264void LLDBBaseTelemetryInfo::serialize (Serializer &serializer) const {
@@ -90,74 +82,63 @@ void DebuggerInfo::serialize(Serializer &serializer) const {
9082 }
9183}
9284
93- void MiscTelemetryInfo::serialize (Serializer &serializer) const {
94- LLDBBaseTelemetryInfo::serialize (serializer);
95- serializer.write (" target_uuid" , target_uuid);
96- serializer.beginObject (" meta_data" );
97- for (const auto &kv : meta_data)
98- serializer.write (kv.first , kv.second );
99- serializer.endObject ();
100- }
101-
10285TelemetryManager::TelemetryManager (std::unique_ptr<Config> config)
10386 : m_config(std::move(config)), m_id(MakeUUID) {}
10487
10588llvm::Error TelemetryManager::preDispatch (TelemetryInfo *entry) {
106- // Look up the session_id to assign to this entry or make one
107- // if none had been computed for this debugger.
89+ // Assign the manager_id, and debugger_id, if available, to this entry.
10890 LLDBBaseTelemetryInfo *lldb_entry =
10991 llvm::dyn_cast<LLDBBaseTelemetryInfo>(entry);
110- std::string session_id = m_id;
111- if (Debugger *debugger = lldb_entry->debugger ) {
112- auto session_id_pos = session_ids.find (debugger->getID ());
113- if (session_id_pos != session_ids.end ())
114- session_id = session_id_pos->second ;
115- else
116- session_id_pos->second = session_id =
117- llvm::formatv (" {0}_{1}" , m_id, debugger->getID ());
118- }
119- lldb_entry->SessionId = session_id;
92+ lldb_entry->SessionId = m_id;
93+ if (Debugger *debugger = lldb_entry->debugger )
94+ lldb_entry->debugger_id = debugger->GetID ();
12095
12196 return llvm::Error::success ();
12297}
12398
12499const Config *getConfig () { return m_config.get (); }
125100
126101void TelemetryManager::AtDebuggerStartup (DebuggerInfo *entry) {
127- if (auto er = dispatch (entry)) {
128- LLDB_LOG (GetLog (LLDBLog::Object), " Failed to dispatch entry at startup" );
102+ if (llvm::Error er = dispatch (entry)) {
103+ LLDB_LOG_ERROR (GetLog (LLDBLog::Object), std::move (er),
104+ " Failed to dispatch entry at debugger startup: {0}" );
129105 }
130- }
131106
132- void TelemetryManager::AtDebuggerExit (DebuggerInfo *entry) {
133- // There must be a reference to the debugger at this point.
134- assert (entry->debugger != nullptr );
135-
136- if (auto *selected_target =
137- entry->debugger ->GetSelectedExecutionContext ().GetTargetPtr ()) {
138- if (!selected_target->IsDummyTarget ()) {
139- const lldb::ProcessSP proc = selected_target->GetProcessSP ();
140- if (proc == nullptr ) {
141- // no process has been launched yet.
142- entry->exit_desc = {-1 , " no process launched." };
143- } else {
144- entry->exit_desc = {proc->GetExitStatus (), " " };
145- if (const char *description = proc->GetExitDescription ())
146- entry->exit_desc ->description = std::string (description);
107+ void TelemetryManager::AtDebuggerExit (DebuggerInfo * entry) {
108+ // There must be a reference to the debugger at this point.
109+ assert (entry->debugger != nullptr );
110+
111+ if (auto *selected_target =
112+ entry->debugger ->GetSelectedExecutionContext ().GetTargetPtr ()) {
113+ if (!selected_target->IsDummyTarget ()) {
114+ const lldb::ProcessSP proc = selected_target->GetProcessSP ();
115+ if (proc == nullptr ) {
116+ // no process has been launched yet.
117+ entry->exit_desc = {-1 , " no process launched." };
118+ } else {
119+ entry->exit_desc = {proc->GetExitStatus (), " " };
120+ if (const char *description = proc->GetExitDescription ())
121+ entry->exit_desc ->description = std::string (description);
122+ }
147123 }
148124 }
149- }
150- dispatch (entry);
151- }
152125
153- std::unique_ptr<TelemetryManager> TelemetryManager::g_instance = nullptr ;
154- TelemetryManager *TelemetryManager::getInstance () { return g_instance.get (); }
126+ if (llvm::Error er = dispatch (entry)) {
127+ LLDB_LOG_ERROR (GetLog (LLDBLog::Object), std::move (er),
128+ " Failed to dispatch entry at debugger exit: {0}" );
129+ }
155130
156- void TelemetryManager::setInstance (std::unique_ptr<TelemetryManager> manager) {
157- g_instance = std::move (manager);
158- }
131+ std::unique_ptr<TelemetryManager> TelemetryManager::g_instance = nullptr ;
132+ TelemetryManager *TelemetryManager::getInstance () {
133+ return g_instance.get ();
134+ }
135+
136+ void TelemetryManager::setInstance (
137+ std::unique_ptr<TelemetryManager> manager) {
138+ g_instance = std::move (manager);
139+ }
159140
160- } // namespace telemetry
141+ } // namespace telemetry
161142} // namespace lldb_private
162143
163144#endif // LLVM_BUILD_TELEMETRY
0 commit comments