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",
152 target_metrics_json.try_emplace(
"loadCoreTime",
156 json::Array breakpoints_array;
157 double totalBreakpointResolveTime = 0.0;
159 for (
int i = 0; i < 2; ++i) {
161 std::unique_lock<std::recursive_mutex> lock;
163 size_t num_breakpoints = breakpoints.
GetSize();
164 for (
size_t i = 0; i < num_breakpoints; i++) {
170 target_metrics_json.try_emplace(
"breakpoints",
171 std::move(breakpoints_array));
172 target_metrics_json.try_emplace(
"totalBreakpointResolveTime",
173 totalBreakpointResolveTime);
176 UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals();
178 target_metrics_json.try_emplace(
179 "signals", unix_signals_sp->GetHitCountStatistics());
186 uint32_t shared_library_event_breakpoint_hit_count = 0;
189 std::unique_lock<std::recursive_mutex> lock;
191 size_t num_breakpoints = breakpoints.
GetSize();
192 for (
size_t i = 0; i < num_breakpoints; i++) {
195 shared_library_event_breakpoint_hit_count += bp->
GetHitCount();
198 target_metrics_json.try_emplace(
"totalSharedLibraryEventHitCount",
199 shared_library_event_breakpoint_hit_count);
203 uint32_t stop_id = process_sp->GetStopID();
204 target_metrics_json.try_emplace(
"stopCount", stop_id);
206 llvm::StringRef dyld_plugin_name;
207 if (process_sp->GetDynamicLoader())
208 dyld_plugin_name = process_sp->GetDynamicLoader()->GetPluginName();
209 target_metrics_json.try_emplace(
"dyldPluginName", dyld_plugin_name);
211 target_metrics_json.try_emplace(
"sourceMapDeduceCount",
213 target_metrics_json.try_emplace(
"sourceRealpathAttemptCount",
215 target_metrics_json.try_emplace(
"sourceRealpathCompatibleCount",
217 target_metrics_json.try_emplace(
"summaryProviderStatistics",
219 return target_metrics_json;
227 for (
int i = 0; i < 2; ++i) {
229 std::unique_lock<std::recursive_mutex> lock;
231 size_t num_breakpoints = breakpoints.
GetSize();
232 for (
size_t i = 0; i < num_breakpoints; i++) {
276 std::lock_guard<std::recursive_mutex> guard(
278 const uint64_t num_modules = target !=
nullptr
281 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
282 Module *module = target !=
nullptr
285 if (module ==
nullptr)
287 module->ResetStatistics();
308 json::Array json_targets;
309 json::Array json_modules;
311 double symtab_parse_time = 0.0;
312 double symtab_index_time = 0.0;
313 double debug_parse_time = 0.0;
314 double debug_index_time = 0.0;
315 uint32_t symtabs_loaded = 0;
316 uint32_t symtabs_loaded_from_cache = 0;
317 uint32_t symtabs_saved_to_cache = 0;
318 uint32_t debug_index_loaded = 0;
319 uint32_t debug_index_saved = 0;
320 uint64_t debug_info_size = 0;
322 std::lock_guard<std::recursive_mutex> guard(
324 const uint64_t num_modules = target !=
nullptr
327 uint32_t num_debug_info_enabled_modules = 0;
328 uint32_t num_modules_has_debug_info = 0;
329 uint32_t num_modules_with_variable_errors = 0;
330 uint32_t num_modules_with_incomplete_types = 0;
331 uint32_t num_stripped_modules = 0;
332 uint32_t symtab_symbol_count = 0;
334 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
335 Module *module = target !=
nullptr
343 Symtab *symtab =
module->GetSymtab(false);
350 ++symtabs_loaded_from_cache;
353 ++symtabs_saved_to_cache;
355 SymbolFile *sym_file =
module->GetSymbolFile(false);
362 for (
const auto &symbol_module : symbol_modules.
Modules())
366 module_stat.
dwo_stats += current_dwo_stats;
367 total_dwo_stats += current_dwo_stats;
371 ++debug_index_loaded;
382 ++num_stripped_modules;
388 ++num_debug_info_enabled_modules;
390 ++num_modules_has_debug_info;
392 ++num_modules_with_variable_errors;
399 module->ForEachTypeSystem([&](lldb::TypeSystemSP ts) {
400 if (auto stats = ts->ReportStatistics())
401 module_stat.type_system_stats.insert({ts->GetPluginName(), *stats});
402 if (ts->GetHasForcefullyCompletedTypes())
406 if (module_stat.debug_info_had_incomplete_types)
407 ++num_modules_with_incomplete_types;
409 if (include_modules) {
410 module_stat.identifier = (intptr_t)module;
411 module_stat.path =
module->GetFileSpec().GetPath();
412 if (
ConstString object_name = module->GetObjectName()) {
413 module_stat.path.append(1,
'(');
414 module_stat.path.append(object_name.GetStringRef().str());
415 module_stat.path.append(1,
')');
417 module_stat.uuid =
module->GetUUID().GetAsString();
418 module_stat.triple =
module->GetArchitecture().GetTriple().str();
419 json_modules.emplace_back(module_stat.ToJSON());
423 json::Object global_stats{
424 {
"totalSymbolTableParseTime", symtab_parse_time},
425 {
"totalSymbolTableIndexTime", symtab_index_time},
426 {
"totalSymbolTablesLoaded", symtabs_loaded},
427 {
"totalSymbolTablesLoadedFromCache", symtabs_loaded_from_cache},
428 {
"totalSymbolTablesSavedToCache", symtabs_saved_to_cache},
429 {
"totalDebugInfoParseTime", debug_parse_time},
430 {
"totalDebugInfoIndexTime", debug_index_time},
431 {
"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
432 {
"totalDebugInfoIndexSavedToCache", debug_index_saved},
433 {
"totalDebugInfoByteSize", debug_info_size},
434 {
"totalModuleCount", num_modules},
435 {
"totalModuleCountHasDebugInfo", num_modules_has_debug_info},
436 {
"totalModuleCountWithVariableErrors", num_modules_with_variable_errors},
437 {
"totalModuleCountWithIncompleteTypes",
438 num_modules_with_incomplete_types},
439 {
"totalDebugInfoEnabled", num_debug_info_enabled_modules},
440 {
"totalSymbolTableStripped", num_stripped_modules},
441 {
"totalSymbolTableSymbolCount", symtab_symbol_count},
442 {
"totalLoadedDwoFileCount", total_dwo_stats.loaded_dwo_file_count},
443 {
"totalDwoFileCount", total_dwo_stats.dwo_file_count},
444 {
"totalDwoErrorCount", total_dwo_stats.dwo_error_count},
447 if (include_targets) {
449 json_targets.emplace_back(target->ReportStatistics(options));
451 for (
const auto &target : debugger.GetTargetList().Targets())
452 json_targets.emplace_back(target->ReportStatistics(options));
454 global_stats.try_emplace(
"targets", std::move(json_targets));
457 if (!symbol_locator_total_time.map.empty()) {
459 for (
const auto &entry : symbol_locator_total_time.map)
460 obj.try_emplace(entry.first().str(), entry.second);
461 global_stats.try_emplace(
"totalSymbolLocatorTime", std::move(obj));
465 json::Object json_memory{
466 {
"strings", const_string_stats.
ToJSON()},
468 global_stats.try_emplace(
"memory", std::move(json_memory));
470 json::Value cmd_stats = debugger.GetCommandInterpreter().GetStatistics();
471 global_stats.try_emplace(
"commands", std::move(cmd_stats));
474 if (include_modules) {
475 global_stats.try_emplace(
"modules", std::move(json_modules));
478 if (include_transcript) {
497 debugger.GetCommandInterpreter().GetTranscript();
498 if (transcript.
GetSize() != 0) {
500 llvm::raw_string_ostream ss(buffer);
501 json::OStream json_os(ss);
503 if (
auto json_transcript = llvm::json::parse(buffer))
504 global_stats.try_emplace(
"transcript",
505 std::move(json_transcript.get()));
509 if (include_plugins) {
513 return std::move(global_stats);
517 return json::Object{{
527 json::Array json_summary_stats;
529 json_summary_stats.emplace_back(summary_stat.second->ToJSON());
531 return json_summary_stats;
536 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
StatsDuration m_load_core_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