@@ -119,6 +119,19 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
119119 return llvm::Error::success ();
120120}
121121
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+
122135void TelemetryManager::DispatchClientTelemetry (
123136 const lldb_private::StructuredDataImpl &entry, Debugger *debugger) {
124137 if (!m_config->enable_client_telemetry )
@@ -148,23 +161,14 @@ void TelemetryManager::DispatchClientTelemetry(
148161 LLDB_LOG (GetLog (LLDBLog::Object),
149162 " Cannot determine client_data from client-telemetry entry" );
150163
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+ auto start_time = GetAsNanosec (dict, " start_time" );
165+ if (start_time.has_value ())
166+ client_info.start_time += start_time.value ();
159167
160- int64_t end_time;
161- if (dict-> GetValueForKeyAsInteger ( " end_time" , end_time )) {
168+ auto end_time = GetAsNanosec (dict, " end_time " ) ;
169+ if (end_time. has_value ( )) {
162170 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" );
171+ client_info.end_time = epoch + end_time.value ();
168172 }
169173
170174 llvm::StringRef error_msg;
0 commit comments