Skip to content

Commit 3291d92

Browse files
royitaqiIanWood1
authored andcommitted
[lldb] Add symbol/table count into statistics (llvm#136226)
# New stats The following stats are added and are available in both "statistics dump" command and in python API. 1. In summary: 1. Add `totalSymbolsLoaded`. The total number of symbols loaded in all modules. 2. Add `totalSymbolTablesLoaded `. The total number symbol tables loaded in all modules. 2. In each module's stats: 1. Add `symbolsLoaded`. The number of symbols loaded in the current module. # Example Example `statistics dump` output: ``` (lldb) statistics dump { ..., "modules": [ { "path": "/Users/<username>/demo/simple/a.out", "symbolsLoaded": 6, ... }, ... ], ... "totalSymbolTablesLoaded": 42, "totalSymbolsLoaded": 32198 } ``` # Tests **Manual test**: Built and ran lldb on a helloworld program. Ran `statistics dump`. Verified the above stats. **Unit test**: Ran the following tests: ``` $ bin/lldb-dotest -p TestStats.py ~/llvm-sand/external/llvm-project/lldb/test/API/commands/statistics/basic/ ... Ran 18 tests in 192.676s OK (skipped=3) ```
1 parent 74b2146 commit 3291d92

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

lldb/include/lldb/Target/Statistics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct ModuleStats {
120120
llvm::StringMap<llvm::json::Value> type_system_stats;
121121
double symtab_parse_time = 0.0;
122122
double symtab_index_time = 0.0;
123+
uint32_t num_symbols_loaded = 0;
123124
double debug_parse_time = 0.0;
124125
double debug_index_time = 0.0;
125126
uint64_t debug_info_size = 0;

lldb/source/Target/Statistics.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ json::Value ModuleStats::ToJSON() const {
7171
module.try_emplace("debugInfoHadIncompleteTypes",
7272
debug_info_had_incomplete_types);
7373
module.try_emplace("symbolTableStripped", symtab_stripped);
74+
module.try_emplace("symbolsLoaded", num_symbols_loaded);
7475
if (!symfile_path.empty())
7576
module.try_emplace("symbolFilePath", symfile_path);
7677

@@ -293,7 +294,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
293294
double debug_parse_time = 0.0;
294295
double debug_index_time = 0.0;
295296
uint32_t symtabs_loaded = 0;
296-
uint32_t symtabs_saved = 0;
297+
uint32_t symtabs_loaded_from_cache = 0;
298+
uint32_t symtabs_saved_to_cache = 0;
297299
uint32_t debug_index_loaded = 0;
298300
uint32_t debug_index_saved = 0;
299301
uint64_t debug_info_size = 0;
@@ -309,6 +311,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
309311
uint32_t num_modules_with_variable_errors = 0;
310312
uint32_t num_modules_with_incomplete_types = 0;
311313
uint32_t num_stripped_modules = 0;
314+
uint32_t num_symbols_loaded = 0;
312315
for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
313316
Module *module = target != nullptr
314317
? target->GetImages().GetModuleAtIndex(image_idx).get()
@@ -318,12 +321,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
318321
module_stat.symtab_index_time = module->GetSymtabIndexTime().get().count();
319322
Symtab *symtab = module->GetSymtab(/*can_create=*/false);
320323
if (symtab) {
324+
module_stat.num_symbols_loaded = symtab->GetNumSymbols();
325+
num_symbols_loaded += module_stat.num_symbols_loaded;
326+
++symtabs_loaded;
321327
module_stat.symtab_loaded_from_cache = symtab->GetWasLoadedFromCache();
322328
if (module_stat.symtab_loaded_from_cache)
323-
++symtabs_loaded;
329+
++symtabs_loaded_from_cache;
324330
module_stat.symtab_saved_to_cache = symtab->GetWasSavedToCache();
325331
if (module_stat.symtab_saved_to_cache)
326-
++symtabs_saved;
332+
++symtabs_saved_to_cache;
327333
}
328334
SymbolFile *sym_file = module->GetSymbolFile(/*can_create=*/false);
329335
if (sym_file) {
@@ -393,8 +399,9 @@ llvm::json::Value DebuggerStats::ReportStatistics(
393399
json::Object global_stats{
394400
{"totalSymbolTableParseTime", symtab_parse_time},
395401
{"totalSymbolTableIndexTime", symtab_index_time},
396-
{"totalSymbolTablesLoadedFromCache", symtabs_loaded},
397-
{"totalSymbolTablesSavedToCache", symtabs_saved},
402+
{"totalSymbolTablesLoaded", symtabs_loaded},
403+
{"totalSymbolTablesLoadedFromCache", symtabs_loaded_from_cache},
404+
{"totalSymbolTablesSavedToCache", symtabs_saved_to_cache},
398405
{"totalDebugInfoParseTime", debug_parse_time},
399406
{"totalDebugInfoIndexTime", debug_index_time},
400407
{"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
@@ -407,6 +414,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
407414
num_modules_with_incomplete_types},
408415
{"totalDebugInfoEnabled", num_debug_info_enabled_modules},
409416
{"totalSymbolTableStripped", num_stripped_modules},
417+
{"totalSymbolsLoaded", num_symbols_loaded},
410418
};
411419

412420
if (include_targets) {

lldb/test/API/commands/statistics/basic/TestStats.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ def test_default_no_run(self):
159159
"""
160160
self.build()
161161
target = self.createTestTarget()
162+
163+
# Verify top-level keys.
162164
debug_stats = self.get_stats()
163165
debug_stat_keys = [
164166
"memory",
@@ -168,23 +170,44 @@ def test_default_no_run(self):
168170
"totalSymbolTableIndexTime",
169171
"totalSymbolTablesLoadedFromCache",
170172
"totalSymbolTablesSavedToCache",
173+
"totalSymbolsLoaded",
174+
"totalSymbolTablesLoaded",
171175
"totalDebugInfoByteSize",
172176
"totalDebugInfoIndexTime",
173177
"totalDebugInfoIndexLoadedFromCache",
174178
"totalDebugInfoIndexSavedToCache",
175179
"totalDebugInfoParseTime",
176180
]
177181
self.verify_keys(debug_stats, '"debug_stats"', debug_stat_keys, None)
178-
stats = debug_stats["targets"][0]
179-
keys_exist = [
182+
self.assertGreater(debug_stats["totalSymbolsLoaded"], 0)
183+
self.assertGreater(debug_stats["totalSymbolTablesLoaded"], 0)
184+
185+
# Verify target stats keys.
186+
target_stats = debug_stats["targets"][0]
187+
target_stat_keys_exist = [
180188
"expressionEvaluation",
181189
"frameVariable",
182190
"moduleIdentifiers",
183191
"targetCreateTime",
184192
]
185-
keys_missing = ["firstStopTime", "launchOrAttachTime"]
186-
self.verify_keys(stats, '"stats"', keys_exist, keys_missing)
187-
self.assertGreater(stats["targetCreateTime"], 0.0)
193+
target_stat_keys_missing = ["firstStopTime", "launchOrAttachTime"]
194+
self.verify_keys(
195+
target_stats,
196+
'"target_stats"',
197+
target_stat_keys_exist,
198+
target_stat_keys_missing,
199+
)
200+
self.assertGreater(target_stats["targetCreateTime"], 0.0)
201+
202+
# Verify module stats keys.
203+
for module_stats in debug_stats["modules"]:
204+
module_stat_keys_exist = [
205+
"symbolsLoaded",
206+
]
207+
self.verify_keys(
208+
module_stats, '"module_stats"', module_stat_keys_exist, None
209+
)
210+
self.assertGreater(module_stats["symbolsLoaded"], 0)
188211

189212
def test_default_with_run(self):
190213
"""Test "statistics dump" when running the target to a breakpoint.

0 commit comments

Comments
 (0)