Skip to content

[lldb] Add symbol/table count into statistics #136226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/include/lldb/Target/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct ModuleStats {
llvm::StringMap<llvm::json::Value> type_system_stats;
double symtab_parse_time = 0.0;
double symtab_index_time = 0.0;
uint32_t num_symbols_loaded = 0;
double debug_parse_time = 0.0;
double debug_index_time = 0.0;
uint64_t debug_info_size = 0;
Expand Down
18 changes: 13 additions & 5 deletions lldb/source/Target/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ json::Value ModuleStats::ToJSON() const {
module.try_emplace("debugInfoHadIncompleteTypes",
debug_info_had_incomplete_types);
module.try_emplace("symbolTableStripped", symtab_stripped);
module.try_emplace("symbolsLoaded", num_symbols_loaded);
if (!symfile_path.empty())
module.try_emplace("symbolFilePath", symfile_path);

Expand Down Expand Up @@ -293,7 +294,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
double debug_parse_time = 0.0;
double debug_index_time = 0.0;
uint32_t symtabs_loaded = 0;
uint32_t symtabs_saved = 0;
uint32_t symtabs_loaded_from_cache = 0;
uint32_t symtabs_saved_to_cache = 0;
uint32_t debug_index_loaded = 0;
uint32_t debug_index_saved = 0;
uint64_t debug_info_size = 0;
Expand All @@ -309,6 +311,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
uint32_t num_modules_with_variable_errors = 0;
uint32_t num_modules_with_incomplete_types = 0;
uint32_t num_stripped_modules = 0;
uint32_t num_symbols_loaded = 0;
for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
Module *module = target != nullptr
? target->GetImages().GetModuleAtIndex(image_idx).get()
Expand All @@ -318,12 +321,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
module_stat.symtab_index_time = module->GetSymtabIndexTime().get().count();
Symtab *symtab = module->GetSymtab(/*can_create=*/false);
if (symtab) {
module_stat.num_symbols_loaded = symtab->GetNumSymbols();
num_symbols_loaded += module_stat.num_symbols_loaded;
++symtabs_loaded;
module_stat.symtab_loaded_from_cache = symtab->GetWasLoadedFromCache();
if (module_stat.symtab_loaded_from_cache)
++symtabs_loaded;
++symtabs_loaded_from_cache;
module_stat.symtab_saved_to_cache = symtab->GetWasSavedToCache();
if (module_stat.symtab_saved_to_cache)
++symtabs_saved;
++symtabs_saved_to_cache;
}
SymbolFile *sym_file = module->GetSymbolFile(/*can_create=*/false);
if (sym_file) {
Expand Down Expand Up @@ -393,8 +399,9 @@ llvm::json::Value DebuggerStats::ReportStatistics(
json::Object global_stats{
{"totalSymbolTableParseTime", symtab_parse_time},
{"totalSymbolTableIndexTime", symtab_index_time},
{"totalSymbolTablesLoadedFromCache", symtabs_loaded},
{"totalSymbolTablesSavedToCache", symtabs_saved},
{"totalSymbolTablesLoaded", symtabs_loaded},
{"totalSymbolTablesLoadedFromCache", symtabs_loaded_from_cache},
{"totalSymbolTablesSavedToCache", symtabs_saved_to_cache},
{"totalDebugInfoParseTime", debug_parse_time},
{"totalDebugInfoIndexTime", debug_index_time},
{"totalDebugInfoIndexLoadedFromCache", debug_index_loaded},
Expand All @@ -407,6 +414,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
num_modules_with_incomplete_types},
{"totalDebugInfoEnabled", num_debug_info_enabled_modules},
{"totalSymbolTableStripped", num_stripped_modules},
{"totalSymbolsLoaded", num_symbols_loaded},
};

if (include_targets) {
Expand Down
33 changes: 28 additions & 5 deletions lldb/test/API/commands/statistics/basic/TestStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def test_default_no_run(self):
"""
self.build()
target = self.createTestTarget()

# Verify top-level keys.
debug_stats = self.get_stats()
debug_stat_keys = [
"memory",
Expand All @@ -168,23 +170,44 @@ def test_default_no_run(self):
"totalSymbolTableIndexTime",
"totalSymbolTablesLoadedFromCache",
"totalSymbolTablesSavedToCache",
"totalSymbolsLoaded",
"totalSymbolTablesLoaded",
"totalDebugInfoByteSize",
"totalDebugInfoIndexTime",
"totalDebugInfoIndexLoadedFromCache",
"totalDebugInfoIndexSavedToCache",
"totalDebugInfoParseTime",
]
self.verify_keys(debug_stats, '"debug_stats"', debug_stat_keys, None)
stats = debug_stats["targets"][0]
keys_exist = [
self.assertGreater(debug_stats["totalSymbolsLoaded"], 0)
self.assertGreater(debug_stats["totalSymbolTablesLoaded"], 0)

# Verify target stats keys.
target_stats = debug_stats["targets"][0]
target_stat_keys_exist = [
"expressionEvaluation",
"frameVariable",
"moduleIdentifiers",
"targetCreateTime",
]
keys_missing = ["firstStopTime", "launchOrAttachTime"]
self.verify_keys(stats, '"stats"', keys_exist, keys_missing)
self.assertGreater(stats["targetCreateTime"], 0.0)
target_stat_keys_missing = ["firstStopTime", "launchOrAttachTime"]
self.verify_keys(
target_stats,
'"target_stats"',
target_stat_keys_exist,
target_stat_keys_missing,
)
self.assertGreater(target_stats["targetCreateTime"], 0.0)

# Verify module stats keys.
for module_stats in debug_stats["modules"]:
module_stat_keys_exist = [
"symbolsLoaded",
]
self.verify_keys(
module_stats, '"module_stats"', module_stat_keys_exist, None
)
self.assertGreater(module_stats["symbolsLoaded"], 0)

def test_default_with_run(self):
"""Test "statistics dump" when running the target to a breakpoint.
Expand Down
Loading