26 if (LLVM_LIKELY(llvm::json::isUTF8(str)))
27 obj.try_emplace(key, str);
29 obj.try_emplace(key, llvm::json::fixUTF8(str));
32 json::Value StatsSuccessFail::ToJSON()
const {
33 return json::Object{{
"successes", successes}, {
"failures", failures}};
38 end.time_since_epoch() - start.time_since_epoch();
42 void TargetStats::CollectStats(
Target &target) {
43 m_module_identifiers.clear();
45 m_module_identifiers.emplace_back((intptr_t)module_sp.get());
48 json::Value ModuleStats::ToJSON()
const {
53 module.try_emplace(
"identifier", identifier);
54 module.try_emplace(
"symbolTableParseTime", symtab_parse_time);
55 module.try_emplace(
"symbolTableIndexTime", symtab_index_time);
56 module.try_emplace(
"symbolTableLoadedFromCache", symtab_loaded_from_cache);
57 module.try_emplace(
"symbolTableSavedToCache", symtab_saved_to_cache);
58 module.try_emplace(
"debugInfoParseTime", debug_parse_time);
59 module.try_emplace(
"debugInfoIndexTime", debug_index_time);
60 module.try_emplace(
"debugInfoByteSize", (int64_t)debug_info_size);
61 module.try_emplace(
"debugInfoIndexLoadedFromCache",
62 debug_info_index_loaded_from_cache);
63 module.try_emplace(
"debugInfoIndexSavedToCache",
64 debug_info_index_saved_to_cache);
65 module.try_emplace(
"debugInfoEnabled", debug_info_enabled);
66 module.try_emplace(
"symbolTableStripped", symtab_stripped);
67 if (!symfile_path.empty())
68 module.try_emplace(
"symbolFilePath", symfile_path);
70 if (!symfile_modules.empty()) {
71 json::Array symfile_ids;
72 for (
const auto symfile_id: symfile_modules)
73 symfile_ids.emplace_back(symfile_id);
74 module.try_emplace(
"symbolFileModuleIdentifiers", std::move(symfile_ids));
79 llvm::json::Value ConstStringStats::ToJSON()
const {
81 obj.try_emplace<int64_t>(
"bytesTotal", stats.GetBytesTotal());
82 obj.try_emplace<int64_t>(
"bytesUsed", stats.GetBytesUsed());
83 obj.try_emplace<int64_t>(
"bytesUnused", stats.GetBytesUnused());
87 json::Value TargetStats::ToJSON(
Target &target) {
90 json::Array json_module_uuid_array;
91 for (
auto module_identifier : m_module_identifiers)
92 json_module_uuid_array.emplace_back(module_identifier);
94 json::Object target_metrics_json{
95 {m_expr_eval.name, m_expr_eval.ToJSON()},
96 {m_frame_var.name, m_frame_var.ToJSON()},
97 {
"moduleIdentifiers", std::move(json_module_uuid_array)}};
99 if (m_launch_or_attach_time && m_first_private_stop_time) {
100 double elapsed_time =
101 elapsed(*m_launch_or_attach_time, *m_first_private_stop_time);
102 target_metrics_json.try_emplace(
"launchOrAttachTime", elapsed_time);
104 if (m_launch_or_attach_time && m_first_public_stop_time) {
105 double elapsed_time =
106 elapsed(*m_launch_or_attach_time, *m_first_public_stop_time);
107 target_metrics_json.try_emplace(
"firstStopTime", elapsed_time);
109 target_metrics_json.try_emplace(
"targetCreateTime",
110 m_create_time.get().count());
112 json::Array breakpoints_array;
113 double totalBreakpointResolveTime = 0.0;
115 for (
int i = 0; i < 2; ++i) {
117 std::unique_lock<std::recursive_mutex> lock;
119 size_t num_breakpoints = breakpoints.
GetSize();
120 for (
size_t i = 0; i < num_breakpoints; i++) {
129 UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals();
131 target_metrics_json.try_emplace(
"signals",
132 unix_signals_sp->GetHitCountStatistics());
133 uint32_t stop_id = process_sp->GetStopID();
134 target_metrics_json.try_emplace(
"stopCount", stop_id);
136 target_metrics_json.try_emplace(
"breakpoints", std::move(breakpoints_array));
137 target_metrics_json.try_emplace(
"totalBreakpointResolveTime",
138 totalBreakpointResolveTime);
140 return target_metrics_json;
143 void TargetStats::SetLaunchOrAttachTime() {
144 m_launch_or_attach_time = StatsClock::now();
145 m_first_private_stop_time = llvm::None;
148 void TargetStats::SetFirstPrivateStopTime() {
152 if (!m_first_private_stop_time)
153 m_first_private_stop_time = StatsClock::now();
156 void TargetStats::SetFirstPublicStopTime() {
160 if (!m_first_public_stop_time)
161 m_first_public_stop_time = StatsClock::now();
164 bool DebuggerStats::g_collecting_stats =
false;
166 llvm::json::Value DebuggerStats::ReportStatistics(
Debugger &debugger,
168 json::Array json_targets;
169 json::Array json_modules;
170 double symtab_parse_time = 0.0;
171 double symtab_index_time = 0.0;
172 double debug_parse_time = 0.0;
173 double debug_index_time = 0.0;
178 uint64_t debug_info_size = 0;
185 std::vector<ModuleStats> modules;
186 std::lock_guard<std::recursive_mutex> guard(
187 Module::GetAllocationModuleCollectionMutex());
188 const uint64_t num_modules = Module::GetNumberAllocatedModules();
189 uint32_t num_debug_info_enabled_modules = 0;
190 uint32_t num_modules_has_debug_info = 0;
192 for (
size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
193 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
198 module_stat.
path.append(1,
'(');
199 module_stat.
path.append(object_name.GetStringRef().str());
200 module_stat.
path.append(1,
')');
227 ++debug_index_loaded;
233 for (
const auto &symbol_module: symbol_modules.
Modules())
237 ++num_stripped_modules;
241 ++num_debug_info_enabled_modules;
243 ++num_modules_has_debug_info;
250 json_modules.emplace_back(module_stat.
ToJSON());
254 json::Object json_memory{
255 {
"strings", const_string_stats.
ToJSON()},
258 json::Object global_stats{
259 {
"targets", std::move(json_targets)},
260 {
"modules", std::move(json_modules)},
261 {
"memory", std::move(json_memory)},
262 {
"totalSymbolTableParseTime", symtab_parse_time},
263 {
"totalSymbolTableIndexTime", symtab_index_time},
264 {
"totalSymbolTablesLoadedFromCache", symtabs_loaded},
265 {
"totalSymbolTablesSavedToCache", symtabs_saved},
266 {
"totalDebugInfoParseTime", debug_parse_time},
267 {
"totalDebugInfoIndexTime", debug_index_time},
268 {
"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
269 {
"totalDebugInfoIndexSavedToCache", debug_index_saved},
270 {
"totalDebugInfoByteSize", debug_info_size},
271 {
"totalModuleCount", num_modules},
272 {
"totalModuleCountHasDebugInfo", num_modules_has_debug_info},
273 {
"totalDebugInfoEnabled", num_debug_info_enabled_modules},
274 {
"totalSymbolTableStripped", num_stripped_modules},
276 return std::move(global_stats);