Skip to content

Commit 21ddd7f

Browse files
authored
Report only loaded debug info in statistics dump (llvm#81706)
Currently running `statistics dump` will trigger lldb to load debug info that's not yet loaded (eg. dwo files). Resulted in a delay in the command return, which, can be interrupting. This patch also added a new option `--load-all-debug-info` asking statistics to dump all possible debug info, which will force loading all debug info available if not yet loaded.
1 parent 27f2908 commit 21ddd7f

24 files changed

+346
-21
lines changed

lldb/bindings/interface/SBStatisticsOptionsDocstrings.i

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
) lldb::SBStatisticsOptions::SetSummaryOnly;
77
%feature("docstring", "Gets whether the statistics only dump a summary."
88
) lldb::SBStatisticsOptions::GetSummaryOnly;
9+
%feature("docstring", "
10+
Sets whether the statistics will force loading all possible debug info."
11+
) lldb::SBStatisticsOptions::SetReportAllAvailableDebugInfo;
12+
%feature("docstring", "
13+
Gets whether the statistics will force loading all possible debug info."
14+
) lldb::SBStatisticsOptions::GetReportAllAvailableDebugInfo;

lldb/include/lldb/API/SBStatisticsOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class LLDB_API SBStatisticsOptions {
2525
void SetSummaryOnly(bool b);
2626
bool GetSummaryOnly();
2727

28+
/// If set to true, the debugger will load all debug info that is available
29+
/// and report statistics on the total amount. If this is set to false, then
30+
/// only report statistics on the currently loaded debug information.
31+
/// This can avoid loading debug info from separate files just so it can
32+
/// report the total size which can slow down statistics reporting.
33+
void SetReportAllAvailableDebugInfo(bool b);
34+
bool GetReportAllAvailableDebugInfo();
35+
2836
protected:
2937
friend class SBTarget;
3038
const lldb_private::StatisticsOptions &ref() const;

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ class SymbolFile : public PluginInterface {
381381

382382
/// Metrics gathering functions
383383

384-
/// Return the size in bytes of all debug information in the symbol file.
384+
/// Return the size in bytes of all loaded debug information or total possible
385+
/// debug info in the symbol file.
385386
///
386387
/// If the debug information is contained in sections of an ObjectFile, then
387388
/// this call should add the size of all sections that contain debug
@@ -391,7 +392,14 @@ class SymbolFile : public PluginInterface {
391392
/// entire file should be returned. The default implementation of this
392393
/// function will iterate over all sections in a module and add up their
393394
/// debug info only section byte sizes.
394-
virtual uint64_t GetDebugInfoSize() = 0;
395+
///
396+
/// \param load_all_debug_info
397+
/// If true, force loading any symbol files if they are not yet loaded and
398+
/// add to the total size. Default to false.
399+
///
400+
/// \returns
401+
/// Total currently loaded debug info size in bytes
402+
virtual uint64_t GetDebugInfoSize(bool load_all_debug_info = false) = 0;
395403

396404
/// Return the time taken to parse the debug information.
397405
///
@@ -534,7 +542,7 @@ class SymbolFileCommon : public SymbolFile {
534542

535543
void Dump(Stream &s) override;
536544

537-
uint64_t GetDebugInfoSize() override;
545+
uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;
538546

539547
bool GetDebugInfoIndexWasLoadedFromCache() const override {
540548
return m_index_was_loaded_from_cache;

lldb/include/lldb/Symbol/SymbolFileOnDemand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile {
178178

179179
void PreloadSymbols() override;
180180

181-
uint64_t GetDebugInfoSize() override;
181+
uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;
182182
lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override;
183183
lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override;
184184

lldb/include/lldb/Target/Statistics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct ConstStringStats {
132132

133133
struct StatisticsOptions {
134134
bool summary_only = false;
135+
bool load_all_debug_info = false;
135136
};
136137

137138
/// A class that represents statistics for a since lldb_private::Target.

lldb/source/API/SBStatisticsOptions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ void SBStatisticsOptions::SetSummaryOnly(bool b) {
4444

4545
bool SBStatisticsOptions::GetSummaryOnly() { return m_opaque_up->summary_only; }
4646

47+
void SBStatisticsOptions::SetReportAllAvailableDebugInfo(bool b) {
48+
m_opaque_up->load_all_debug_info = b;
49+
}
50+
51+
bool SBStatisticsOptions::GetReportAllAvailableDebugInfo() {
52+
return m_opaque_up->load_all_debug_info;
53+
}
54+
4755
const lldb_private::StatisticsOptions &SBStatisticsOptions::ref() const {
4856
return *m_opaque_up;
4957
}

lldb/source/Commands/CommandObjectStats.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
7878
case 's':
7979
m_stats_options.summary_only = true;
8080
break;
81+
case 'f':
82+
m_stats_options.load_all_debug_info = true;
83+
break;
8184
default:
8285
llvm_unreachable("Unimplemented option");
8386
}

lldb/source/Commands/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,10 @@ let Command = "statistics dump" in {
14191419
def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
14201420
Desc<"Include statistics for all targets.">;
14211421
def statistics_dump_summary: Option<"summary", "s">, Group<1>,
1422-
Desc<"Dump only high-level summary statistics."
1422+
Desc<"Dump only high-level summary statistics. "
14231423
"Exclude targets, modules, breakpoints etc... details.">;
1424+
def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
1425+
Desc<"Dump the total possible debug info statistics. "
1426+
"Force loading all the debug information if not yet loaded, and collect "
1427+
"statistics with those.">;
14241428
}

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ void SymbolFileBreakpad::ParseUnwindData() {
918918
m_unwind_data->win.Sort();
919919
}
920920

921-
uint64_t SymbolFileBreakpad::GetDebugInfoSize() {
921+
uint64_t SymbolFileBreakpad::GetDebugInfoSize(bool load_all_debug_info) {
922922
// Breakpad files are all debug info.
923923
return m_objfile_sp->GetByteSize();
924924
}

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class SymbolFileBreakpad : public SymbolFileCommon {
141141

142142
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
143143

144-
uint64_t GetDebugInfoSize() override;
144+
uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;
145145

146146
private:
147147
// A class representing a position in the breakpad file. Useful for

0 commit comments

Comments
 (0)