[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 21 01:20:47 PST 2025
================
@@ -43,29 +77,79 @@ void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) const {
serializer.write("end_time", ToNanosec(end_time.value()));
}
-[[maybe_unused]] static std::string MakeUUID(Debugger *debugger) {
- uint8_t random_bytes[16];
- if (auto ec = llvm::getRandomBytes(random_bytes, 16)) {
- LLDB_LOG(GetLog(LLDBLog::Object),
- "Failed to generate random bytes for UUID: {0}", ec.message());
- // Fallback to using timestamp + debugger ID.
- return llvm::formatv(
- "{0}_{1}", std::chrono::steady_clock::now().time_since_epoch().count(),
- debugger->GetID());
+void DebuggerInfo::serialize(Serializer &serializer) const {
+ LLDBBaseTelemetryInfo::serialize(serializer);
+
+ serializer.write("username", username);
+ serializer.write("lldb_git_sha", lldb_git_sha);
+ serializer.write("lldb_path", lldb_path);
+ serializer.write("cwd", cwd);
+ if (exit_desc.has_value()) {
+ serializer.write("exit_code", exit_desc->exit_code);
+ serializer.write("exit_desc", exit_desc->description);
}
- return UUID(random_bytes).GetAsString();
+}
+
+void MiscTelemetryInfo::serialize(Serializer &serializer) const {
+ LLDBBaseTelemetryInfo::serialize(serializer);
+ serializer.write("target_uuid", target_uuid);
+ serializer.beginObject("meta_data");
+ for (const auto &kv : meta_data)
+ serializer.write(kv.first, kv.second);
+ serializer.endObject();
}
TelemetryManager::TelemetryManager(std::unique_ptr<Config> config)
- : m_config(std::move(config)) {}
+ : m_config(std::move(config)), m_id(MakeUUID) {}
llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
- // Do nothing for now.
- // In up-coming patch, this would be where the manager
- // attach the session_uuid to the entry.
+ // Look up the session_id to assign to this entry or make one
+ // if none had been computed for this debugger.
+ LLDBBaseTelemetryInfo *lldb_entry =
+ llvm::dyn_cast<LLDBBaseTelemetryInfo>(entry);
+ std::string session_id = m_id;
+ if (Debugger *debugger = lldb_entry->debugger) {
+ auto session_id_pos = session_ids.find(debugger->getID());
----------------
labath wrote:
Can we drop the map? I doubt copying the string is noticably faster than constructing it each time (particularly if you use lower level constructs like `raw_string_ostream(lldb_entry->SessionId) << m_id << "_" << debugger->getID()`
Or even better, use two fields like I originally suggested? Then there's no copying and it has the advantage that you can choose how to do the analysis: I can imagine that in some situations you may want to see all events from a particular Debugger object, but in others you may want to see "everything that happens within a single process". I think that would be easier to do if the fields are separate.
https://github.com/llvm/llvm-project/pull/127696
More information about the lldb-commits
mailing list