27 const std::string &str) {
30 if (LLVM_LIKELY(llvm::json::isUTF8(str)))
31 obj.try_emplace(key, str);
33 obj.try_emplace(key, llvm::json::fixUTF8(str));
42 end.time_since_epoch() - start.time_since_epoch();
57 module.try_emplace("identifier", identifier);
58 module.try_emplace("symbolTableParseTime", symtab_parse_time);
59 module.try_emplace("symbolTableIndexTime", symtab_index_time);
60 module.try_emplace("symbolTableLoadedFromCache", symtab_loaded_from_cache);
61 module.try_emplace("symbolTableSavedToCache", symtab_saved_to_cache);
62 module.try_emplace("debugInfoParseTime", debug_parse_time);
63 module.try_emplace("debugInfoIndexTime", debug_index_time);
64 module.try_emplace("debugInfoByteSize", (int64_t)debug_info_size);
65 module.try_emplace("debugInfoIndexLoadedFromCache",
66 debug_info_index_loaded_from_cache);
67 module.try_emplace("debugInfoIndexSavedToCache",
68 debug_info_index_saved_to_cache);
69 module.try_emplace("debugInfoEnabled", debug_info_enabled);
70 module.try_emplace("debugInfoHadVariableErrors",
71 debug_info_had_variable_errors);
72 module.try_emplace("debugInfoHadIncompleteTypes",
73 debug_info_had_incomplete_types);
74 module.try_emplace("symbolTableStripped", symtab_stripped);
75 module.try_emplace("symbolTableSymbolCount", symtab_symbol_count);
76 module.try_emplace("dwoFileCount", dwo_stats.dwo_file_count);
77 module.try_emplace("loadedDwoFileCount", dwo_stats.loaded_dwo_file_count);
78 module.try_emplace("dwoErrorCount", dwo_stats.dwo_error_count);
83 obj.try_emplace(entry.first().str(), entry.second);
84 module.try_emplace("symbolLocatorTime", std::move(obj));
88 module.try_emplace("symbolFilePath", symfile_path);
91 json::Array symfile_ids;
93 symfile_ids.emplace_back(symfile_id);
94 module.try_emplace("symbolFileModuleIdentifiers", std::move(symfile_ids));
98 json::Array type_systems;
101 obj.try_emplace(entry.first().str(), entry.second);
102 type_systems.emplace_back(std::move(obj));
104 module.try_emplace("typeSystemInfo", std::move(type_systems));
112 obj.try_emplace<int64_t>(
"bytesTotal",
stats.GetBytesTotal());
113 obj.try_emplace<int64_t>(
"bytesUsed",
stats.GetBytesUsed());
114 obj.try_emplace<int64_t>(
"bytesUnused",
stats.GetBytesUnused());
121 json::Object target_metrics_json;
128 json::Array json_module_uuid_array;
130 json_module_uuid_array.emplace_back(module_identifier);
135 target_metrics_json.try_emplace(
"moduleIdentifiers",
136 std::move(json_module_uuid_array));
139 double elapsed_time =
141 target_metrics_json.try_emplace(
"launchOrAttachTime", elapsed_time);
144 double elapsed_time =
146 target_metrics_json.try_emplace(
"firstStopTime", elapsed_time);
148 target_metrics_json.try_emplace(
"targetCreateTime",
151 json::Array breakpoints_array;
152 double totalBreakpointResolveTime = 0.0;
154 for (
int i = 0; i < 2; ++i) {
156 std::unique_lock<std::recursive_mutex> lock;
158 size_t num_breakpoints = breakpoints.
GetSize();
159 for (
size_t i = 0; i < num_breakpoints; i++) {
165 target_metrics_json.try_emplace(
"breakpoints",
166 std::move(breakpoints_array));
167 target_metrics_json.try_emplace(
"totalBreakpointResolveTime",
168 totalBreakpointResolveTime);
171 UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals();
173 target_metrics_json.try_emplace(
174 "signals", unix_signals_sp->GetHitCountStatistics());
181 uint32_t shared_library_event_breakpoint_hit_count = 0;
184 std::unique_lock<std::recursive_mutex> lock;
186 size_t num_breakpoints = breakpoints.
GetSize();
187 for (
size_t i = 0; i < num_breakpoints; i++) {
190 shared_library_event_breakpoint_hit_count += bp->
GetHitCount();
193 target_metrics_json.try_emplace(
"totalSharedLibraryEventHitCount",
194 shared_library_event_breakpoint_hit_count);
198 uint32_t stop_id = process_sp->GetStopID();
199 target_metrics_json.try_emplace(
"stopCount", stop_id);
201 llvm::StringRef dyld_plugin_name;
202 if (process_sp->GetDynamicLoader())
203 dyld_plugin_name = process_sp->GetDynamicLoader()->GetPluginName();
204 target_metrics_json.try_emplace(
"dyldPluginName", dyld_plugin_name);
206 target_metrics_json.try_emplace(
"sourceMapDeduceCount",
208 target_metrics_json.try_emplace(
"sourceRealpathAttemptCount",
210 target_metrics_json.try_emplace(
"sourceRealpathCompatibleCount",
212 target_metrics_json.try_emplace(
"summaryProviderStatistics",
214 return target_metrics_json;
222 for (
int i = 0; i < 2; ++i) {
224 std::unique_lock<std::recursive_mutex> lock;
226 size_t num_breakpoints = breakpoints.
GetSize();
227 for (
size_t i = 0; i < num_breakpoints; i++) {
271 std::lock_guard<std::recursive_mutex> guard(
273 const uint64_t num_modules = target !=
nullptr
276 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
277 Module *module = target !=
nullptr
280 if (module ==
nullptr)
282 module->ResetStatistics();
303 json::Array json_targets;
304 json::Array json_modules;
306 double symtab_parse_time = 0.0;
307 double symtab_index_time = 0.0;
308 double debug_parse_time = 0.0;
309 double debug_index_time = 0.0;
310 uint32_t symtabs_loaded = 0;
311 uint32_t symtabs_loaded_from_cache = 0;
312 uint32_t symtabs_saved_to_cache = 0;
313 uint32_t debug_index_loaded = 0;
314 uint32_t debug_index_saved = 0;
315 uint64_t debug_info_size = 0;
317 std::lock_guard<std::recursive_mutex> guard(
319 const uint64_t num_modules = target !=
nullptr
322 uint32_t num_debug_info_enabled_modules = 0;
323 uint32_t num_modules_has_debug_info = 0;
324 uint32_t num_modules_with_variable_errors = 0;
325 uint32_t num_modules_with_incomplete_types = 0;
326 uint32_t num_stripped_modules = 0;
327 uint32_t symtab_symbol_count = 0;
329 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
330 Module *module = target !=
nullptr
338 Symtab *symtab =
module->GetSymtab(false);
345 ++symtabs_loaded_from_cache;
348 ++symtabs_saved_to_cache;
350 SymbolFile *sym_file =
module->GetSymbolFile(false);
357 for (
const auto &symbol_module : symbol_modules.
Modules())
361 module_stat.
dwo_stats += current_dwo_stats;
362 total_dwo_stats += current_dwo_stats;
366 ++debug_index_loaded;
377 ++num_stripped_modules;
383 ++num_debug_info_enabled_modules;
385 ++num_modules_has_debug_info;
387 ++num_modules_with_variable_errors;
394 module->ForEachTypeSystem([&](lldb::TypeSystemSP ts) {
395 if (auto stats = ts->ReportStatistics())
396 module_stat.type_system_stats.insert({ts->GetPluginName(), *stats});
397 if (ts->GetHasForcefullyCompletedTypes())
401 if (module_stat.debug_info_had_incomplete_types)
402 ++num_modules_with_incomplete_types;
404 if (include_modules) {
405 module_stat.identifier = (intptr_t)module;
406 module_stat.path =
module->GetFileSpec().GetPath();
407 if (
ConstString object_name = module->GetObjectName()) {
408 module_stat.path.append(1,
'(');
409 module_stat.path.append(object_name.GetStringRef().str());
410 module_stat.path.append(1,
')');
412 module_stat.uuid =
module->GetUUID().GetAsString();
413 module_stat.triple =
module->GetArchitecture().GetTriple().str();
414 json_modules.emplace_back(module_stat.ToJSON());
418 json::Object global_stats{
419 {
"totalSymbolTableParseTime", symtab_parse_time},
420 {
"totalSymbolTableIndexTime", symtab_index_time},
421 {
"totalSymbolTablesLoaded", symtabs_loaded},
422 {
"totalSymbolTablesLoadedFromCache", symtabs_loaded_from_cache},
423 {
"totalSymbolTablesSavedToCache", symtabs_saved_to_cache},
424 {
"totalDebugInfoParseTime", debug_parse_time},
425 {
"totalDebugInfoIndexTime", debug_index_time},
426 {
"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
427 {
"totalDebugInfoIndexSavedToCache", debug_index_saved},
428 {
"totalDebugInfoByteSize", debug_info_size},
429 {
"totalModuleCount", num_modules},
430 {
"totalModuleCountHasDebugInfo", num_modules_has_debug_info},
431 {
"totalModuleCountWithVariableErrors", num_modules_with_variable_errors},
432 {
"totalModuleCountWithIncompleteTypes",
433 num_modules_with_incomplete_types},
434 {
"totalDebugInfoEnabled", num_debug_info_enabled_modules},
435 {
"totalSymbolTableStripped", num_stripped_modules},
436 {
"totalSymbolTableSymbolCount", symtab_symbol_count},
437 {
"totalLoadedDwoFileCount", total_dwo_stats.loaded_dwo_file_count},
438 {
"totalDwoFileCount", total_dwo_stats.dwo_file_count},
439 {
"totalDwoErrorCount", total_dwo_stats.dwo_error_count},
442 if (include_targets) {
444 json_targets.emplace_back(target->ReportStatistics(options));
446 for (
const auto &target : debugger.GetTargetList().Targets())
447 json_targets.emplace_back(target->ReportStatistics(options));
449 global_stats.try_emplace(
"targets", std::move(json_targets));
452 if (!symbol_locator_total_time.map.empty()) {
454 for (
const auto &entry : symbol_locator_total_time.map)
455 obj.try_emplace(entry.first().str(), entry.second);
456 global_stats.try_emplace(
"totalSymbolLocatorTime", std::move(obj));
460 json::Object json_memory{
461 {
"strings", const_string_stats.
ToJSON()},
463 global_stats.try_emplace(
"memory", std::move(json_memory));
465 json::Value cmd_stats = debugger.GetCommandInterpreter().GetStatistics();
466 global_stats.try_emplace(
"commands", std::move(cmd_stats));
469 if (include_modules) {
470 global_stats.try_emplace(
"modules", std::move(json_modules));
473 if (include_transcript) {
492 debugger.GetCommandInterpreter().GetTranscript();
493 if (transcript.
GetSize() != 0) {
495 llvm::raw_string_ostream ss(buffer);
496 json::OStream json_os(ss);
498 if (
auto json_transcript = llvm::json::parse(buffer))
499 global_stats.try_emplace(
"transcript",
500 std::move(json_transcript.get()));
504 if (include_plugins) {
508 return std::move(global_stats);
512 return json::Object{{
522 json::Array json_summary_stats;
524 json_summary_stats.emplace_back(summary_stat.second->ToJSON());
526 return json_summary_stats;
531 summary_stat.second->Reset();
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
static void EmplaceSafeString(llvm::json::Object &obj, llvm::StringRef key, const std::string &str)
General Outline: Allows adding and removing breakpoints and find by ID and index.
void GetListMutex(std::unique_lock< std::recursive_mutex > &lock)
Sets the passed in Locker to hold the Breakpoint List mutex.
size_t GetSize() const
Returns the number of elements in this breakpoint list.
lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const
Returns a shared pointer to the breakpoint with index i.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
llvm::json::Value GetStatistics()
Get statistics associated with this breakpoint in JSON format.
const char * GetBreakpointKind() const
Return the "kind" description for a breakpoint.
uint32_t GetHitCount() const
Return the current hit count for all locations.
StatsDuration::Duration GetResolveTime() const
Get the time it took to resolve all locations in this breakpoint.
A uniqued constant string class.
static bool g_collecting_stats
static void ResetStatistics(Debugger &debugger, Target *target)
Reset metrics associated with one or all targets in a debugger.
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target, const lldb_private::StatisticsOptions &options)
Get metrics associated with one or all targets in a debugger in JSON format.
A class to manage flag bits.
TargetList & GetTargetList()
Get accessor for the target list.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
A collection class for Module objects.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
ModuleIterable Modules() const
size_t GetSize() const
Gets the size of the module list.
A class that describes an executable image and its associated object and symbol files.
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
static Module * GetAllocatedModuleAtIndex(size_t idx)
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
static size_t GetNumberAllocatedModules()
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
static llvm::json::Object GetJSON(llvm::StringRef pattern="")
A class to count time for plugins.
void merge(StatisticsMap map_to_merge)
std::chrono::duration< double > Duration
void Serialize(llvm::json::OStream &s) const override
llvm::StringMap< SummaryStatisticsSP > m_summary_stats_map
llvm::json::Value ToJSON()
double GetTotalTime() const
llvm::json::Value ToJSON() const
std::string GetSummaryKindName() const
std::string GetName() const
uint64_t GetSummaryCount() const
Provides public interface for all SymbolFiles.
virtual uint64_t GetDebugInfoSize(bool load_all_debug_info=false)=0
Metrics gathering functions.
virtual bool GetDebugInfoIndexWasLoadedFromCache() const =0
Accessors for the bool that indicates if the debug info index was loaded from, or saved to the module...
virtual DWOStats GetDwoStats()
Retrieves statistics about DWO files associated with this symbol file.
virtual bool GetDebugInfoIndexWasSavedToCache() const =0
virtual StatsDuration::Duration GetDebugInfoParseTime()
Return the time taken to parse the debug information.
virtual bool GetLoadDebugInfoEnabled()
Whether debug info will be loaded or not.
virtual bool GetDebugInfoHadFrameVariableErrors() const =0
Accessors for the bool that indicates if there was debug info, but errors stopped variables from bein...
virtual ModuleList GetDebugInfoModules()
Get the additional modules that this symbol file uses to parse debug info.
virtual StatsDuration::Duration GetDebugInfoIndexTime()
Return the time it took to index the debug information in the object file.
virtual ObjectFile * GetObjectFile()=0
bool GetWasLoadedFromCache() const
Accessors for the bool that indicates if the debug info index was loaded from, or saved to the module...
size_t GetNumSymbols() const
bool GetWasSavedToCache() const
void IncreaseSourceMapDeduceCount()
void Reset(Target &target)
StatsSuccessFail m_frame_var
std::optional< StatsTimepoint > m_launch_or_attach_time
uint32_t m_source_map_deduce_count
void CollectStats(Target &target)
llvm::json::Value ToJSON(Target &target, const lldb_private::StatisticsOptions &options)
StatsDuration m_create_time
std::optional< StatsTimepoint > m_first_public_stop_time
void IncreaseSourceRealpathAttemptCount(uint32_t count)
uint32_t m_source_realpath_compatible_count
void SetFirstPrivateStopTime()
StatsSuccessFail m_expr_eval
std::vector< intptr_t > m_module_identifiers
void SetFirstPublicStopTime()
uint32_t m_source_realpath_attempt_count
void SetLaunchOrAttachTime()
void IncreaseSourceRealpathCompatibleCount(uint32_t count)
std::optional< StatsTimepoint > m_first_private_stop_time
BreakpointList & GetBreakpointList(bool internal=false)
lldb_private::SummaryStatisticsCache & GetSummaryStatisticsCache()
const lldb::ProcessSP & GetProcessSP() const
const ModuleList & GetImages() const
Get accessor for the images for this process.
A class that represents a running process on the host machine.
std::chrono::time_point< StatsClock > StatsTimepoint
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Module > ModuleSP
ConstString::MemoryStats stats
llvm::json::Value ToJSON() const
Holds statistics about DWO (Debug With Object) files.
A class that represents statistics for a since lldb_private::Module.
bool debug_info_index_saved_to_cache
bool debug_info_had_variable_errors
uint32_t symtab_symbol_count
llvm::json::Value ToJSON() const
llvm::StringMap< llvm::json::Value > type_system_stats
StatisticsMap symbol_locator_time
bool debug_info_had_incomplete_types
bool symtab_saved_to_cache
std::vector< intptr_t > symfile_modules
bool symtab_loaded_from_cache
bool debug_info_index_loaded_from_cache
bool GetIncludeTranscript() const
bool GetIncludeModules() const
bool GetIncludePlugins() const
bool GetSummaryOnly() const
bool GetIncludeTargets() const
bool GetLoadAllDebugInfo() const
llvm::json::Value ToJSON() const