28 const std::string &str) {
31 if (LLVM_LIKELY(llvm::json::isUTF8(str)))
32 obj.try_emplace(key, str);
34 obj.try_emplace(key, llvm::json::fixUTF8(str));
43 end.time_since_epoch() - start.time_since_epoch();
58 module.try_emplace("identifier", identifier);
59 module.try_emplace("symbolTableParseTime", symtab_parse_time);
60 module.try_emplace("symbolTableIndexTime", symtab_index_time);
61 module.try_emplace("symbolTableLoadedFromCache", symtab_loaded_from_cache);
62 module.try_emplace("symbolTableSavedToCache", symtab_saved_to_cache);
63 module.try_emplace("debugInfoParseTime", debug_parse_time);
64 module.try_emplace("debugInfoIndexTime", debug_index_time);
65 module.try_emplace("debugInfoByteSize", (int64_t)debug_info_size);
66 module.try_emplace("debugInfoIndexLoadedFromCache",
67 debug_info_index_loaded_from_cache);
68 module.try_emplace("debugInfoIndexSavedToCache",
69 debug_info_index_saved_to_cache);
70 module.try_emplace("debugInfoEnabled", debug_info_enabled);
71 module.try_emplace("debugInfoHadVariableErrors",
72 debug_info_had_variable_errors);
73 module.try_emplace("debugInfoHadIncompleteTypes",
74 debug_info_had_incomplete_types);
75 module.try_emplace("symbolTableStripped", symtab_stripped);
76 module.try_emplace("symbolTableSymbolCount", symtab_symbol_count);
77 module.try_emplace("dwoFileCount", dwo_stats.dwo_file_count);
78 module.try_emplace("loadedDwoFileCount", dwo_stats.loaded_dwo_file_count);
79 module.try_emplace("dwoErrorCount", dwo_stats.dwo_error_count);
84 obj.try_emplace(entry.first().str(), entry.second);
85 module.try_emplace("symbolLocatorTime", std::move(obj));
89 module.try_emplace("symbolFilePath", symfile_path);
92 json::Array symfile_ids;
94 symfile_ids.emplace_back(symfile_id);
95 module.try_emplace("symbolFileModuleIdentifiers", std::move(symfile_ids));
99 json::Array type_systems;
102 obj.try_emplace(entry.first().str(), entry.second);
103 type_systems.emplace_back(std::move(obj));
105 module.try_emplace("typeSystemInfo", std::move(type_systems));
113 obj.try_emplace<int64_t>(
"bytesTotal",
stats.GetBytesTotal());
114 obj.try_emplace<int64_t>(
"bytesUsed",
stats.GetBytesUsed());
115 obj.try_emplace<int64_t>(
"bytesUnused",
stats.GetBytesUnused());
122 json::Object target_metrics_json;
129 json::Array json_module_uuid_array;
131 json_module_uuid_array.emplace_back(module_identifier);
133 target_metrics_json.try_emplace(
"expressionEvaluation",
135 target_metrics_json.try_emplace(
"frameVariable",
m_frame_var.ToJSON());
137 target_metrics_json.try_emplace(
"moduleIdentifiers",
138 std::move(json_module_uuid_array));
141 double elapsed_time =
143 target_metrics_json.try_emplace(
"launchOrAttachTime", elapsed_time);
146 double elapsed_time =
148 target_metrics_json.try_emplace(
"firstStopTime", elapsed_time);
150 target_metrics_json.try_emplace(
"targetCreateTime",
154 target_metrics_json.try_emplace(
"loadCoreTime",
158 json::Array breakpoints_array;
159 double totalBreakpointResolveTime = 0.0;
161 for (
int i = 0; i < 2; ++i) {
163 std::unique_lock<std::recursive_mutex> lock;
165 size_t num_breakpoints = breakpoints.
GetSize();
166 for (
size_t i = 0; i < num_breakpoints; i++) {
172 target_metrics_json.try_emplace(
"breakpoints",
173 std::move(breakpoints_array));
174 target_metrics_json.try_emplace(
"totalBreakpointResolveTime",
175 totalBreakpointResolveTime);
178 UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals();
180 target_metrics_json.try_emplace(
181 "signals", unix_signals_sp->GetHitCountStatistics());
188 uint32_t shared_library_event_breakpoint_hit_count = 0;
191 std::unique_lock<std::recursive_mutex> lock;
193 size_t num_breakpoints = breakpoints.
GetSize();
194 for (
size_t i = 0; i < num_breakpoints; i++) {
197 shared_library_event_breakpoint_hit_count += bp->
GetHitCount();
200 target_metrics_json.try_emplace(
"totalSharedLibraryEventHitCount",
201 shared_library_event_breakpoint_hit_count);
205 uint32_t stop_id = process_sp->GetStopID();
206 target_metrics_json.try_emplace(
"stopCount", stop_id);
208 llvm::StringRef dyld_plugin_name;
209 if (process_sp->GetDynamicLoader())
210 dyld_plugin_name = process_sp->GetDynamicLoader()->GetPluginName();
211 target_metrics_json.try_emplace(
"dyldPluginName", dyld_plugin_name);
213 if (process_sp->GetCoreFile())
214 target_metrics_json.try_emplace(
"coreFile",
215 process_sp->GetCoreFile().GetFilename());
217 target_metrics_json.try_emplace(
"sourceMapDeduceCount",
219 target_metrics_json.try_emplace(
"sourceRealpathAttemptCount",
221 target_metrics_json.try_emplace(
"sourceRealpathCompatibleCount",
223 target_metrics_json.try_emplace(
"summaryProviderStatistics",
225 return target_metrics_json;
233 for (
int i = 0; i < 2; ++i) {
235 std::unique_lock<std::recursive_mutex> lock;
237 size_t num_breakpoints = breakpoints.
GetSize();
238 for (
size_t i = 0; i < num_breakpoints; i++) {
282 std::lock_guard<std::recursive_mutex> guard(
284 const uint64_t num_modules = target !=
nullptr
287 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
288 Module *module = target !=
nullptr
291 if (module ==
nullptr)
293 module->ResetStatistics();
314 json::Array json_targets;
315 json::Array json_modules;
317 double symtab_parse_time = 0.0;
318 double symtab_index_time = 0.0;
319 double debug_parse_time = 0.0;
320 double debug_index_time = 0.0;
321 uint32_t symtabs_loaded = 0;
322 uint32_t symtabs_loaded_from_cache = 0;
323 uint32_t symtabs_saved_to_cache = 0;
324 uint32_t debug_index_loaded = 0;
325 uint32_t debug_index_saved = 0;
326 uint64_t debug_info_size = 0;
328 std::lock_guard<std::recursive_mutex> guard(
330 const uint64_t num_modules = target !=
nullptr
333 uint32_t num_debug_info_enabled_modules = 0;
334 uint32_t num_modules_has_debug_info = 0;
335 uint32_t num_modules_with_variable_errors = 0;
336 uint32_t num_modules_with_incomplete_types = 0;
337 uint32_t num_stripped_modules = 0;
338 uint32_t symtab_symbol_count = 0;
340 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
341 Module *module = target !=
nullptr
349 Symtab *symtab =
module->GetSymtab(false);
356 ++symtabs_loaded_from_cache;
359 ++symtabs_saved_to_cache;
361 SymbolFile *sym_file =
module->GetSymbolFile(false);
368 for (
const auto &symbol_module : symbol_modules.
Modules())
372 module_stat.
dwo_stats += current_dwo_stats;
373 total_dwo_stats += current_dwo_stats;
377 ++debug_index_loaded;
388 ++num_stripped_modules;
394 ++num_debug_info_enabled_modules;
396 ++num_modules_has_debug_info;
398 ++num_modules_with_variable_errors;
405 module->ForEachTypeSystem([&](lldb::TypeSystemSP ts) {
406 if (auto stats = ts->ReportStatistics())
407 module_stat.type_system_stats.insert({ts->GetPluginName(), *stats});
408 if (ts->GetHasForcefullyCompletedTypes())
412 if (module_stat.debug_info_had_incomplete_types)
413 ++num_modules_with_incomplete_types;
415 if (include_modules) {
416 module_stat.identifier = (intptr_t)module;
417 module_stat.path =
module->GetFileSpec().GetPath();
418 if (
ConstString object_name = module->GetObjectName()) {
419 module_stat.path.append(1,
'(');
420 module_stat.path.append(object_name.GetStringRef().str());
421 module_stat.path.append(1,
')');
423 module_stat.uuid =
module->GetUUID().GetAsString();
424 module_stat.triple =
module->GetArchitecture().GetTriple().str();
425 json_modules.emplace_back(module_stat.ToJSON());
429 json::Object global_stats{
430 {
"totalSymbolTableParseTime", symtab_parse_time},
431 {
"totalSymbolTableIndexTime", symtab_index_time},
432 {
"totalSymbolTablesLoaded", symtabs_loaded},
433 {
"totalSymbolTablesLoadedFromCache", symtabs_loaded_from_cache},
434 {
"totalSymbolTablesSavedToCache", symtabs_saved_to_cache},
435 {
"totalDebugInfoParseTime", debug_parse_time},
436 {
"totalDebugInfoIndexTime", debug_index_time},
437 {
"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
438 {
"totalDebugInfoIndexSavedToCache", debug_index_saved},
439 {
"totalDebugInfoByteSize", debug_info_size},
440 {
"totalModuleCount", num_modules},
441 {
"totalModuleCountHasDebugInfo", num_modules_has_debug_info},
442 {
"totalModuleCountWithVariableErrors", num_modules_with_variable_errors},
443 {
"totalModuleCountWithIncompleteTypes",
444 num_modules_with_incomplete_types},
445 {
"totalDebugInfoEnabled", num_debug_info_enabled_modules},
446 {
"totalSymbolTableStripped", num_stripped_modules},
447 {
"totalSymbolTableSymbolCount", symtab_symbol_count},
448 {
"totalLoadedDwoFileCount", total_dwo_stats.loaded_dwo_file_count},
449 {
"totalDwoFileCount", total_dwo_stats.dwo_file_count},
450 {
"totalDwoErrorCount", total_dwo_stats.dwo_error_count},
453 if (include_targets) {
455 json_targets.emplace_back(target->ReportStatistics(options));
457 for (
const auto &target : debugger.GetTargetList().Targets())
458 json_targets.emplace_back(target->ReportStatistics(options));
460 global_stats.try_emplace(
"targets", std::move(json_targets));
463 if (!symbol_locator_total_time.map.empty()) {
465 for (
const auto &entry : symbol_locator_total_time.map)
466 obj.try_emplace(entry.first().str(), entry.second);
467 global_stats.try_emplace(
"totalSymbolLocatorTime", std::move(obj));
471 json::Object json_memory{
472 {
"strings", const_string_stats.
ToJSON()},
474 global_stats.try_emplace(
"memory", std::move(json_memory));
476 json::Value cmd_stats = debugger.GetCommandInterpreter().GetStatistics();
477 global_stats.try_emplace(
"commands", std::move(cmd_stats));
480 if (include_modules) {
481 global_stats.try_emplace(
"modules", std::move(json_modules));
484 if (include_transcript) {
503 debugger.GetCommandInterpreter().GetTranscript();
504 if (transcript.
GetSize() != 0) {
506 llvm::raw_string_ostream ss(buffer);
507 json::OStream json_os(ss);
509 if (
auto json_transcript = llvm::json::parse(buffer))
510 global_stats.try_emplace(
"transcript",
511 std::move(json_transcript.get()));
514 "failed to parse transcript JSON: {0}");
518 if (include_plugins) {
522 return std::move(global_stats);
526 return json::Object{{
536 json::Array json_summary_stats;
538 json_summary_stats.emplace_back(summary_stat.second->ToJSON());
540 return json_summary_stats;
545 summary_stat.second->Reset();
#define LLDB_LOG_ERROR(log, error,...)
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.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
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