@@ -119,6 +119,19 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
119
119
return llvm::Error::success ();
120
120
}
121
121
122
+ // Helper for extracting time field from a Dictionary.
123
+ static std::optional<std::chrono::nanoseconds>
124
+ GetAsNanosec (StructuredData::Dictionary *dict, llvm::StringRef key) {
125
+ auto value = dict->GetValueForKey (key);
126
+ if (!value->IsValid ()) {
127
+ LLDB_LOG (GetLog (LLDBLog::Object),
128
+ " Cannot determine {0} from client-telemetry entry" , key);
129
+ return std::nullopt;
130
+ }
131
+
132
+ return std::chrono::nanoseconds (value->GetUnsignedIntegerValue (0 ));
133
+ }
134
+
122
135
void TelemetryManager::DispatchClientTelemetry (
123
136
const lldb_private::StructuredDataImpl &entry, Debugger *debugger) {
124
137
if (!m_config->enable_client_telemetry )
@@ -148,23 +161,12 @@ void TelemetryManager::DispatchClientTelemetry(
148
161
LLDB_LOG (GetLog (LLDBLog::Object),
149
162
" Cannot determine client_data from client-telemetry entry" );
150
163
151
- int64_t start_time;
152
- if (dict->GetValueForKeyAsInteger (" start_time" , start_time)) {
153
- client_info.start_time +=
154
- std::chrono::nanoseconds (static_cast <size_t >(start_time));
155
- } else {
156
- LLDB_LOG (GetLog (LLDBLog::Object),
157
- " Cannot determine start-time from client-telemetry entry" );
158
- }
164
+ if (auto maybe_start_time = GetAsNanosec (dict, " start_time" ))
165
+ client_info.start_time += *maybe_start_time;
159
166
160
- int64_t end_time;
161
- if (dict->GetValueForKeyAsInteger (" end_time" , end_time)) {
167
+ if (auto maybe_end_time = GetAsNanosec (dict, " end_time" )) {
162
168
SteadyTimePoint epoch;
163
- client_info.end_time =
164
- epoch + std::chrono::nanoseconds (static_cast <size_t >(end_time));
165
- } else {
166
- LLDB_LOG (GetLog (LLDBLog::Object),
167
- " Cannot determine end-time from client-telemetry entry" );
169
+ client_info.end_time = epoch + *maybe_end_time;
168
170
}
169
171
170
172
llvm::StringRef error_msg;
0 commit comments