12
12
#include " lldb/Core/Module.h"
13
13
#include " lldb/Interpreter/CommandInterpreter.h"
14
14
#include " lldb/Symbol/SymbolFile.h"
15
+ #include " lldb/Target/DynamicLoader.h"
15
16
#include " lldb/Target/Process.h"
16
17
#include " lldb/Target/Target.h"
17
18
#include " lldb/Target/UnixSignals.h"
@@ -74,7 +75,7 @@ json::Value ModuleStats::ToJSON() const {
74
75
75
76
if (!symfile_modules.empty ()) {
76
77
json::Array symfile_ids;
77
- for (const auto symfile_id: symfile_modules)
78
+ for (const auto symfile_id : symfile_modules)
78
79
symfile_ids.emplace_back (symfile_id);
79
80
module .try_emplace (" symbolFileModuleIdentifiers" , std::move (symfile_ids));
80
81
}
@@ -100,60 +101,91 @@ llvm::json::Value ConstStringStats::ToJSON() const {
100
101
return obj;
101
102
}
102
103
103
- json::Value TargetStats::ToJSON (Target &target) {
104
- CollectStats (target);
104
+ json::Value TargetStats::ToJSON (Target &target, bool summary_only) {
105
+ json::Object target_metrics_json;
106
+ ProcessSP process_sp = target.GetProcessSP ();
107
+ if (!summary_only) {
108
+ CollectStats (target);
105
109
106
- json::Array json_module_uuid_array;
107
- for (auto module_identifier : m_module_identifiers)
108
- json_module_uuid_array.emplace_back (module_identifier);
110
+ json::Array json_module_uuid_array;
111
+ for (auto module_identifier : m_module_identifiers)
112
+ json_module_uuid_array.emplace_back (module_identifier);
109
113
110
- json::Object target_metrics_json{
111
- {m_expr_eval. name , m_expr_eval .ToJSON ()},
112
- {m_frame_var. name , m_frame_var. ToJSON ()} ,
113
- { " moduleIdentifiers " , std::move (json_module_uuid_array)}} ;
114
+ target_metrics_json. try_emplace (m_expr_eval. name , m_expr_eval. ToJSON ());
115
+ target_metrics_json. try_emplace (m_frame_var. name , m_frame_var .ToJSON ());
116
+ target_metrics_json. try_emplace ( " moduleIdentifiers " ,
117
+ std::move (json_module_uuid_array)) ;
114
118
115
- if (m_launch_or_attach_time && m_first_private_stop_time) {
116
- double elapsed_time =
117
- elapsed (*m_launch_or_attach_time, *m_first_private_stop_time);
118
- target_metrics_json.try_emplace (" launchOrAttachTime" , elapsed_time);
119
- }
120
- if (m_launch_or_attach_time && m_first_public_stop_time) {
121
- double elapsed_time =
122
- elapsed (*m_launch_or_attach_time, *m_first_public_stop_time);
123
- target_metrics_json.try_emplace (" firstStopTime" , elapsed_time);
119
+ if (m_launch_or_attach_time && m_first_private_stop_time) {
120
+ double elapsed_time =
121
+ elapsed (*m_launch_or_attach_time, *m_first_private_stop_time);
122
+ target_metrics_json.try_emplace (" launchOrAttachTime" , elapsed_time);
123
+ }
124
+ if (m_launch_or_attach_time && m_first_public_stop_time) {
125
+ double elapsed_time =
126
+ elapsed (*m_launch_or_attach_time, *m_first_public_stop_time);
127
+ target_metrics_json.try_emplace (" firstStopTime" , elapsed_time);
128
+ }
129
+ target_metrics_json.try_emplace (" targetCreateTime" ,
130
+ m_create_time.get ().count ());
131
+
132
+ json::Array breakpoints_array;
133
+ double totalBreakpointResolveTime = 0.0 ;
134
+ // Rport both the normal breakpoint list and the internal breakpoint list.
135
+ for (int i = 0 ; i < 2 ; ++i) {
136
+ BreakpointList &breakpoints = target.GetBreakpointList (i == 1 );
137
+ std::unique_lock<std::recursive_mutex> lock;
138
+ breakpoints.GetListMutex (lock);
139
+ size_t num_breakpoints = breakpoints.GetSize ();
140
+ for (size_t i = 0 ; i < num_breakpoints; i++) {
141
+ Breakpoint *bp = breakpoints.GetBreakpointAtIndex (i).get ();
142
+ breakpoints_array.push_back (bp->GetStatistics ());
143
+ totalBreakpointResolveTime += bp->GetResolveTime ().count ();
144
+ }
145
+ }
146
+ target_metrics_json.try_emplace (" breakpoints" ,
147
+ std::move (breakpoints_array));
148
+ target_metrics_json.try_emplace (" totalBreakpointResolveTime" ,
149
+ totalBreakpointResolveTime);
150
+
151
+ if (process_sp) {
152
+ UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals ();
153
+ if (unix_signals_sp)
154
+ target_metrics_json.try_emplace (
155
+ " signals" , unix_signals_sp->GetHitCountStatistics ());
156
+ }
124
157
}
125
- target_metrics_json.try_emplace (" targetCreateTime" ,
126
- m_create_time.get ().count ());
127
-
128
- json::Array breakpoints_array;
129
- double totalBreakpointResolveTime = 0.0 ;
130
- // Rport both the normal breakpoint list and the internal breakpoint list.
131
- for (int i = 0 ; i < 2 ; ++i) {
132
- BreakpointList &breakpoints = target.GetBreakpointList (i == 1 );
158
+
159
+ // Counting "totalSharedLibraryEventHitCount" from breakpoints of kind
160
+ // "shared-library-event".
161
+ {
162
+ uint32_t shared_library_event_breakpoint_hit_count = 0 ;
163
+ // The "shared-library-event" is only found in the internal breakpoint list.
164
+ BreakpointList &breakpoints = target.GetBreakpointList (/* internal */ true );
133
165
std::unique_lock<std::recursive_mutex> lock;
134
166
breakpoints.GetListMutex (lock);
135
167
size_t num_breakpoints = breakpoints.GetSize ();
136
168
for (size_t i = 0 ; i < num_breakpoints; i++) {
137
169
Breakpoint *bp = breakpoints.GetBreakpointAtIndex (i).get ();
138
- breakpoints_array. push_back ( bp->GetStatistics ());
139
- totalBreakpointResolveTime += bp->GetResolveTime (). count ();
170
+ if ( strcmp ( bp->GetBreakpointKind (), " shared-library-event " ) == 0 )
171
+ shared_library_event_breakpoint_hit_count += bp->GetHitCount ();
140
172
}
173
+
174
+ target_metrics_json.try_emplace (" totalSharedLibraryEventHitCount" ,
175
+ shared_library_event_breakpoint_hit_count);
141
176
}
142
177
143
- ProcessSP process_sp = target.GetProcessSP ();
144
178
if (process_sp) {
145
- UnixSignalsSP unix_signals_sp = process_sp->GetUnixSignals ();
146
- if (unix_signals_sp)
147
- target_metrics_json.try_emplace (" signals" ,
148
- unix_signals_sp->GetHitCountStatistics ());
149
179
uint32_t stop_id = process_sp->GetStopID ();
150
180
target_metrics_json.try_emplace (" stopCount" , stop_id);
151
- }
152
- target_metrics_json.try_emplace (" breakpoints" , std::move (breakpoints_array));
153
- target_metrics_json.try_emplace (" totalBreakpointResolveTime" ,
154
- totalBreakpointResolveTime);
155
- target_metrics_json.try_emplace (" sourceMapDeduceCount" , m_source_map_deduce_count);
156
181
182
+ llvm::StringRef dyld_plugin_name;
183
+ if (process_sp->GetDynamicLoader ())
184
+ dyld_plugin_name = process_sp->GetDynamicLoader ()->GetPluginName ();
185
+ target_metrics_json.try_emplace (" dyldPluginName" , dyld_plugin_name);
186
+ }
187
+ target_metrics_json.try_emplace (" sourceMapDeduceCount" ,
188
+ m_source_map_deduce_count);
157
189
return target_metrics_json;
158
190
}
159
191
@@ -185,7 +217,8 @@ void TargetStats::IncreaseSourceMapDeduceCount() {
185
217
bool DebuggerStats::g_collecting_stats = false ;
186
218
187
219
llvm::json::Value DebuggerStats::ReportStatistics (Debugger &debugger,
188
- Target *target) {
220
+ Target *target,
221
+ bool summary_only) {
189
222
json::Array json_targets;
190
223
json::Array json_modules;
191
224
double symtab_parse_time = 0.0 ;
@@ -197,12 +230,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
197
230
uint32_t debug_index_loaded = 0 ;
198
231
uint32_t debug_index_saved = 0 ;
199
232
uint64_t debug_info_size = 0 ;
200
- if (target) {
201
- json_targets.emplace_back (target->ReportStatistics ());
202
- } else {
203
- for (const auto &target : debugger.GetTargetList ().Targets ())
204
- json_targets.emplace_back (target->ReportStatistics ());
205
- }
233
+
206
234
std::vector<ModuleStats> modules;
207
235
std::lock_guard<std::recursive_mutex> guard (
208
236
Module::GetAllocationModuleCollectionMutex ());
@@ -215,15 +243,6 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
215
243
for (size_t image_idx = 0 ; image_idx < num_modules; ++image_idx) {
216
244
Module *module = Module::GetAllocatedModuleAtIndex (image_idx);
217
245
ModuleStats module_stat;
218
- module_stat.identifier = (intptr_t )module ;
219
- module_stat.path = module ->GetFileSpec ().GetPath ();
220
- if (ConstString object_name = module ->GetObjectName ()) {
221
- module_stat.path .append (1 , ' (' );
222
- module_stat.path .append (object_name.GetStringRef ().str ());
223
- module_stat.path .append (1 , ' )' );
224
- }
225
- module_stat.uuid = module ->GetUUID ().GetAsString ();
226
- module_stat.triple = module ->GetArchitecture ().GetTriple ().str ();
227
246
module_stat.symtab_parse_time = module ->GetSymtabParseTime ().get ().count ();
228
247
module_stat.symtab_index_time = module ->GetSymtabIndexTime ().get ().count ();
229
248
Symtab *symtab = module ->GetSymtab ();
@@ -237,13 +256,14 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
237
256
}
238
257
SymbolFile *sym_file = module ->GetSymbolFile ();
239
258
if (sym_file) {
240
-
241
- if (sym_file->GetObjectFile () != module ->GetObjectFile ())
242
- module_stat.symfile_path =
243
- sym_file->GetObjectFile ()->GetFileSpec ().GetPath ();
244
- module_stat.debug_index_time = sym_file->GetDebugInfoIndexTime ().count ();
245
- module_stat.debug_parse_time = sym_file->GetDebugInfoParseTime ().count ();
246
- module_stat.debug_info_size = sym_file->GetDebugInfoSize ();
259
+ if (!summary_only) {
260
+ if (sym_file->GetObjectFile () != module ->GetObjectFile ())
261
+ module_stat.symfile_path =
262
+ sym_file->GetObjectFile ()->GetFileSpec ().GetPath ();
263
+ ModuleList symbol_modules = sym_file->GetDebugInfoModules ();
264
+ for (const auto &symbol_module : symbol_modules.Modules ())
265
+ module_stat.symfile_modules .push_back ((intptr_t )symbol_module.get ());
266
+ }
247
267
module_stat.debug_info_index_loaded_from_cache =
248
268
sym_file->GetDebugInfoIndexWasLoadedFromCache ();
249
269
if (module_stat.debug_info_index_loaded_from_cache )
@@ -252,9 +272,9 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
252
272
sym_file->GetDebugInfoIndexWasSavedToCache ();
253
273
if (module_stat.debug_info_index_saved_to_cache )
254
274
++debug_index_saved;
255
- ModuleList symbol_modules = sym_file->GetDebugInfoModules ();
256
- for ( const auto &symbol_module: symbol_modules. Modules ())
257
- module_stat.symfile_modules . push_back (( intptr_t )symbol_module. get () );
275
+ module_stat. debug_index_time = sym_file->GetDebugInfoIndexTime (). count ();
276
+ module_stat. debug_parse_time = sym_file-> GetDebugInfoParseTime (). count ();
277
+ module_stat.debug_info_size = sym_file-> GetDebugInfoSize ( );
258
278
module_stat.symtab_stripped = module ->GetObjectFile ()->IsStripped ();
259
279
if (module_stat.symtab_stripped )
260
280
++num_stripped_modules;
@@ -284,21 +304,21 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
284
304
if (module_stat.debug_info_had_incomplete_types )
285
305
++num_modules_with_incomplete_types;
286
306
287
- json_modules.emplace_back (module_stat.ToJSON ());
307
+ if (!summary_only) {
308
+ module_stat.identifier = (intptr_t )module ;
309
+ module_stat.path = module ->GetFileSpec ().GetPath ();
310
+ if (ConstString object_name = module ->GetObjectName ()) {
311
+ module_stat.path .append (1 , ' (' );
312
+ module_stat.path .append (object_name.GetStringRef ().str ());
313
+ module_stat.path .append (1 , ' )' );
314
+ }
315
+ module_stat.uuid = module ->GetUUID ().GetAsString ();
316
+ module_stat.triple = module ->GetArchitecture ().GetTriple ().str ();
317
+ json_modules.emplace_back (module_stat.ToJSON ());
318
+ }
288
319
}
289
320
290
- ConstStringStats const_string_stats;
291
- json::Object json_memory{
292
- {" strings" , const_string_stats.ToJSON ()},
293
- };
294
-
295
- json::Value cmd_stats = debugger.GetCommandInterpreter ().GetStatistics ();
296
-
297
321
json::Object global_stats{
298
- {" targets" , std::move (json_targets)},
299
- {" modules" , std::move (json_modules)},
300
- {" memory" , std::move (json_memory)},
301
- {" commands" , std::move (cmd_stats)},
302
322
{" totalSymbolTableParseTime" , symtab_parse_time},
303
323
{" totalSymbolTableIndexTime" , symtab_index_time},
304
324
{" totalSymbolTablesLoadedFromCache" , symtabs_loaded},
@@ -316,5 +336,25 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
316
336
{" totalDebugInfoEnabled" , num_debug_info_enabled_modules},
317
337
{" totalSymbolTableStripped" , num_stripped_modules},
318
338
};
339
+
340
+ if (target) {
341
+ json_targets.emplace_back (target->ReportStatistics (summary_only));
342
+ } else {
343
+ for (const auto &target : debugger.GetTargetList ().Targets ())
344
+ json_targets.emplace_back (target->ReportStatistics (summary_only));
345
+ }
346
+ global_stats.try_emplace (" targets" , std::move (json_targets));
347
+
348
+ if (!summary_only) {
349
+ ConstStringStats const_string_stats;
350
+ json::Object json_memory{
351
+ {" strings" , const_string_stats.ToJSON ()},
352
+ };
353
+ json::Value cmd_stats = debugger.GetCommandInterpreter ().GetStatistics ();
354
+ global_stats.try_emplace (" modules" , std::move (json_modules));
355
+ global_stats.try_emplace (" memory" , std::move (json_memory));
356
+ global_stats.try_emplace (" commands" , std::move (cmd_stats));
357
+ }
358
+
319
359
return std::move (global_stats);
320
360
}
0 commit comments