26 const std::string &str) {
29 if (LLVM_LIKELY(llvm::json::isUTF8(str)))
30 obj.try_emplace(key, str);
32 obj.try_emplace(key, llvm::json::fixUTF8(str));
41 end.time_since_epoch() - start.time_since_epoch();
64 module.try_emplace(
"debugInfoIndexLoadedFromCache",
66 module.try_emplace(
"debugInfoIndexSavedToCache",
69 module.try_emplace(
"debugInfoHadVariableErrors",
71 module.try_emplace(
"debugInfoHadIncompleteTypes",
78 json::Array symfile_ids;
80 symfile_ids.emplace_back(symfile_id);
81 module.try_emplace(
"symbolFileModuleIdentifiers", std::move(symfile_ids));
85 json::Array type_systems;
88 obj.try_emplace(entry.first().str(), entry.second);
89 type_systems.emplace_back(std::move(obj));
91 module.try_emplace(
"typeSystemInfo", std::move(type_systems));
108 json::Object target_metrics_json;
115 json::Array json_module_uuid_array;
117 json_module_uuid_array.emplace_back(module_identifier);
122 target_metrics_json.try_emplace(
"moduleIdentifiers",
123 std::move(json_module_uuid_array));
126 double elapsed_time =
128 target_metrics_json.try_emplace(
"launchOrAttachTime", elapsed_time);
131 double elapsed_time =
133 target_metrics_json.try_emplace(
"firstStopTime", elapsed_time);
135 target_metrics_json.try_emplace(
"targetCreateTime",
138 json::Array breakpoints_array;
139 double totalBreakpointResolveTime = 0.0;
141 for (
int i = 0; i < 2; ++i) {
143 std::unique_lock<std::recursive_mutex> lock;
145 size_t num_breakpoints = breakpoints.
GetSize();
146 for (
size_t i = 0; i < num_breakpoints; i++) {
152 target_metrics_json.try_emplace(
"breakpoints",
153 std::move(breakpoints_array));
154 target_metrics_json.try_emplace(
"totalBreakpointResolveTime",
155 totalBreakpointResolveTime);
158 UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals();
160 target_metrics_json.try_emplace(
161 "signals", unix_signals_sp->GetHitCountStatistics());
168 uint32_t shared_library_event_breakpoint_hit_count = 0;
171 std::unique_lock<std::recursive_mutex> lock;
173 size_t num_breakpoints = breakpoints.
GetSize();
174 for (
size_t i = 0; i < num_breakpoints; i++) {
177 shared_library_event_breakpoint_hit_count += bp->
GetHitCount();
180 target_metrics_json.try_emplace(
"totalSharedLibraryEventHitCount",
181 shared_library_event_breakpoint_hit_count);
185 uint32_t stop_id = process_sp->GetStopID();
186 target_metrics_json.try_emplace(
"stopCount", stop_id);
188 llvm::StringRef dyld_plugin_name;
189 if (process_sp->GetDynamicLoader())
190 dyld_plugin_name = process_sp->GetDynamicLoader()->GetPluginName();
191 target_metrics_json.try_emplace(
"dyldPluginName", dyld_plugin_name);
193 target_metrics_json.try_emplace(
"sourceMapDeduceCount",
195 target_metrics_json.try_emplace(
"sourceRealpathAttemptCount",
197 target_metrics_json.try_emplace(
"sourceRealpathCompatibleCount",
199 return target_metrics_json;
247 json::Array json_targets;
248 json::Array json_modules;
249 double symtab_parse_time = 0.0;
250 double symtab_index_time = 0.0;
251 double debug_parse_time = 0.0;
252 double debug_index_time = 0.0;
253 uint32_t symtabs_loaded = 0;
254 uint32_t symtabs_saved = 0;
255 uint32_t debug_index_loaded = 0;
256 uint32_t debug_index_saved = 0;
257 uint64_t debug_info_size = 0;
259 std::vector<ModuleStats> modules;
260 std::lock_guard<std::recursive_mutex> guard(
263 uint32_t num_debug_info_enabled_modules = 0;
264 uint32_t num_modules_has_debug_info = 0;
265 uint32_t num_modules_with_variable_errors = 0;
266 uint32_t num_modules_with_incomplete_types = 0;
267 uint32_t num_stripped_modules = 0;
268 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
289 for (
const auto &symbol_module : symbol_modules.
Modules())
295 ++debug_index_loaded;
306 ++num_stripped_modules;
312 ++num_debug_info_enabled_modules;
314 ++num_modules_has_debug_info;
316 ++num_modules_with_variable_errors;
324 if (
auto stats = ts->ReportStatistics())
326 if (ts->GetHasForcefullyCompletedTypes())
331 ++num_modules_with_incomplete_types;
333 if (include_modules) {
337 module_stat.
path.append(1,
'(');
338 module_stat.
path.append(object_name.GetStringRef().str());
339 module_stat.
path.append(1,
')');
343 json_modules.emplace_back(module_stat.
ToJSON());
347 json::Object global_stats{
348 {
"totalSymbolTableParseTime", symtab_parse_time},
349 {
"totalSymbolTableIndexTime", symtab_index_time},
350 {
"totalSymbolTablesLoadedFromCache", symtabs_loaded},
351 {
"totalSymbolTablesSavedToCache", symtabs_saved},
352 {
"totalDebugInfoParseTime", debug_parse_time},
353 {
"totalDebugInfoIndexTime", debug_index_time},
354 {
"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
355 {
"totalDebugInfoIndexSavedToCache", debug_index_saved},
356 {
"totalDebugInfoByteSize", debug_info_size},
357 {
"totalModuleCount", num_modules},
358 {
"totalModuleCountHasDebugInfo", num_modules_has_debug_info},
359 {
"totalModuleCountWithVariableErrors", num_modules_with_variable_errors},
360 {
"totalModuleCountWithIncompleteTypes",
361 num_modules_with_incomplete_types},
362 {
"totalDebugInfoEnabled", num_debug_info_enabled_modules},
363 {
"totalSymbolTableStripped", num_stripped_modules},
366 if (include_targets) {
373 global_stats.try_emplace(
"targets", std::move(json_targets));
377 json::Object json_memory{
378 {
"strings", const_string_stats.
ToJSON()},
380 global_stats.try_emplace(
"memory", std::move(json_memory));
383 global_stats.try_emplace(
"commands", std::move(cmd_stats));
386 if (include_modules) {
387 global_stats.try_emplace(
"modules", std::move(json_modules));
390 if (include_transcript) {
410 if (transcript.
GetSize() != 0) {
412 llvm::raw_string_ostream ss(buffer);
413 json::OStream json_os(ss);
415 if (
auto json_transcript = llvm::json::parse(ss.str()))
416 global_stats.try_emplace(
"transcript",
417 std::move(json_transcript.get()));
421 return std::move(global_stats);
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
static void EmplaceSafeString(llvm::json::Object &obj, llvm::StringRef key, const std::string &str)
llvm::Triple & GetTriple()
Architecture triple accessor.
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.
llvm::json::Value GetStatistics()
const StructuredData::Array & GetTranscript() const
A uniqued constant string class.
static bool g_collecting_stats
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.
CommandInterpreter & GetCommandInterpreter()
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.
ModuleIterable Modules() const
A class that describes an executable image and its associated object and symbol files.
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
ConstString GetObjectName() const
static Module * GetAllocatedModuleAtIndex(size_t idx)
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
static size_t GetNumberAllocatedModules()
void ForEachTypeSystem(llvm::function_ref< bool(lldb::TypeSystemSP)> callback)
Call callback for each TypeSystem in this Module.
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
StatsDuration & GetSymtabIndexTime()
Accessor for the symbol table index time metric.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
StatsDuration & GetSymtabParseTime()
Accessor for the symbol table parse time metric.
virtual bool IsStripped()=0
Detect if this object file has been stripped of local symbols.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
std::chrono::duration< double > Duration
void Serialize(llvm::json::OStream &s) const override
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 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...
bool GetWasSavedToCache() const
void IncreaseSourceMapDeduceCount()
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)
const lldb::ProcessSP & GetProcessSP() const
llvm::json::Value ReportStatistics(const lldb_private::StatisticsOptions &options)
Get metrics associated with this target in JSON format.
const ModuleList & GetImages() const
Get accessor for the images for this process.
std::string GetAsString(llvm::StringRef separator="-") const
A class that represents a running process on the host machine.
std::chrono::time_point< StatsClock > StatsTimepoint
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
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
size_t GetBytesUnused() const
size_t GetBytesTotal() const
size_t GetBytesUsed() const
A class that represents statistics for a since lldb_private::Module.
bool debug_info_index_saved_to_cache
bool debug_info_had_variable_errors
llvm::json::Value ToJSON() const
llvm::StringMap< llvm::json::Value > type_system_stats
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 GetSummaryOnly() const
bool GetIncludeTargets() const
bool GetLoadAllDebugInfo() const
llvm::json::Value ToJSON() const