-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLDB][NFC] Refactor code extracting timestamp from StructuredData #145954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oontvoo
wants to merge
2
commits into
llvm:main
Choose a base branch
from
oontvoo:refactor_time
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−15
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Vy Nguyen (oontvoo) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145954.diff 1 Files Affected:
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;
|
bulbazord
reviewed
Jun 26, 2025
Comment on lines
+168
to
+171
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same suggestion here.
Co-authored-by: Alex Langford <[email protected]>
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- lldb/source/Core/Telemetry.cpp View the diff from clang-format here.diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5382c0e09..6d2848f89 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -162,7 +162,7 @@ void TelemetryManager::DispatchClientTelemetry(
"Cannot determine client_data from client-telemetry entry");
if (auto maybe_start_time = GetAsNanosec(dict, "start_time"))
- client_info.start_time += *maybe_start_time;
+ client_info.start_time += *maybe_start_time;
auto end_time = GetAsNanosec(dict, "end_time");
if (end_time.has_value()) {
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.