Skip to content

Conversation

@oontvoo
Copy link
Member

@oontvoo oontvoo commented Jun 26, 2025

No description provided.

@oontvoo oontvoo requested a review from labath June 26, 2025 19:20
@oontvoo oontvoo requested a review from JDevlieghere as a code owner June 26, 2025 19:20
@llvmbot llvmbot added the lldb label Jun 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-lldb

Author: Vy Nguyen (oontvoo)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/145954.diff

1 Files Affected:

  • (modified) lldb/source/Core/Telemetry.cpp (+19-15)
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 6434b11a63ad4..464c1d4071a73 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -119,6 +119,19 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
   return llvm::Error::success();
 }
 
+// Helper for extracting time field from a Dictionary.
+static std::optional<std::chrono::nanoseconds>
+GetAsNanosec(StructuredData::Dictionary *dict, llvm::StringRef key) {
+  auto value = dict->GetValueForKey(key);
+  if (!value->IsValid()) {
+    LLDB_LOG(GetLog(LLDBLog::Object),
+             "Cannot determine {0} from client-telemetry entry", key);
+    return std::nullopt;
+  }
+
+  return std::chrono::nanoseconds(value->GetUnsignedIntegerValue(0));
+}
+
 void TelemetryManager::DispatchClientTelemetry(
     const lldb_private::StructuredDataImpl &entry, Debugger *debugger) {
   if (!m_config->enable_client_telemetry)
@@ -148,23 +161,14 @@ void TelemetryManager::DispatchClientTelemetry(
     LLDB_LOG(GetLog(LLDBLog::Object),
              "Cannot determine client_data from client-telemetry entry");
 
-  int64_t start_time;
-  if (dict->GetValueForKeyAsInteger("start_time", start_time)) {
-    client_info.start_time +=
-        std::chrono::nanoseconds(static_cast<size_t>(start_time));
-  } else {
-    LLDB_LOG(GetLog(LLDBLog::Object),
-             "Cannot determine start-time from client-telemetry entry");
-  }
+  auto start_time = GetAsNanosec(dict, "start_time");
+  if (start_time.has_value())
+    client_info.start_time += start_time.value();
 
-  int64_t end_time;
-  if (dict->GetValueForKeyAsInteger("end_time", end_time)) {
+  auto end_time = GetAsNanosec(dict, "end_time");
+  if (end_time.has_value()) {
     SteadyTimePoint epoch;
-    client_info.end_time =
-        epoch + std::chrono::nanoseconds(static_cast<size_t>(end_time));
-  } else {
-    LLDB_LOG(GetLog(LLDBLog::Object),
-             "Cannot determine end-time from client-telemetry entry");
+    client_info.end_time = epoch + end_time.value();
   }
 
   llvm::StringRef error_msg;

@github-actions
Copy link

github-actions bot commented Jun 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@oontvoo
Copy link
Member Author

oontvoo commented Jun 30, 2025

Thanks!

@oontvoo oontvoo merged commit 5548f4d into llvm:main Jun 30, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants