[LLDB][NFC] Refactor code extracting timestamp from StructuredData (#145954)

Co-authored-by: Alex Langford <nirvashtzero@gmail.com>
This commit is contained in:
Vy Nguyen
2025-06-30 14:25:11 -04:00
committed by GitHub
parent 125dbe103e
commit 5548f4d5ef

View File

@@ -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,12 @@ 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");
}
if (auto maybe_start_time = GetAsNanosec(dict, "start_time"))
client_info.start_time += *maybe_start_time;
int64_t end_time;
if (dict->GetValueForKeyAsInteger("end_time", end_time)) {
if (auto maybe_end_time = GetAsNanosec(dict, "end_time")) {
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 + *maybe_end_time;
}
llvm::StringRef error_msg;