Skip to content

Commit 36c84ce

Browse files
committed
Support statistics dump summary only mode
Summary: Added a new --summary option to statistics dump command so that it is much light weight than the full version. With this change, statistics dump --summary can now be included in lldb command line telemetry without slowing down lldb exiting.
1 parent a7bc9cb commit 36c84ce

File tree

9 files changed

+164
-88
lines changed

9 files changed

+164
-88
lines changed

lldb/include/lldb/API/SBTarget.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
8686

8787
/// Returns a dump of the collected statistics.
8888
///
89+
/// \param[in] summary_only
90+
/// If true, only report high level summary statistics without
91+
/// targets/modules/breakpoints etc.. details.
92+
///
8993
/// \return
9094
/// A SBStructuredData with the statistics collected.
91-
lldb::SBStructuredData GetStatistics();
95+
lldb::SBStructuredData GetStatistics(bool summary_only = false);
9296

9397
/// Return the platform object associated with the target.
9498
///
@@ -326,7 +330,7 @@ class LLDB_API SBTarget {
326330
uint32_t GetAddressByteSize();
327331

328332
const char *GetTriple();
329-
333+
330334
const char *GetABIName();
331335

332336
const char *GetLabel() const;

lldb/include/lldb/Target/Statistics.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct ConstStringStats {
133133
/// A class that represents statistics for a since lldb_private::Target.
134134
class TargetStats {
135135
public:
136-
llvm::json::Value ToJSON(Target &target);
136+
llvm::json::Value ToJSON(Target &target, bool summary_only = false);
137137

138138
void SetLaunchOrAttachTime();
139139
void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
171171
/// The single target to emit statistics for if non NULL, otherwise dump
172172
/// statistics only for the specified target.
173173
///
174+
/// \param summary_only
175+
/// If true, only report high level summary statistics without
176+
/// targets/modules/breakpoints etc.. details.
177+
///
174178
/// \return
175179
/// Returns a JSON value that contains all target metrics.
176-
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target);
180+
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
181+
bool summary_only = false);
177182

178183
protected:
179184
// Collecting stats can be set to true to collect stats that are expensive

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ class Target : public std::enable_shared_from_this<Target>,
15991599
///
16001600
/// \return
16011601
/// Returns a JSON value that contains all target metrics.
1602-
llvm::json::Value ReportStatistics();
1602+
llvm::json::Value ReportStatistics(bool summary_only = false);
16031603

16041604
TargetStats &GetStatistics() { return m_stats; }
16051605

lldb/source/API/SBTarget.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,18 @@ SBDebugger SBTarget::GetDebugger() const {
197197
return debugger;
198198
}
199199

200-
SBStructuredData SBTarget::GetStatistics() {
200+
SBStructuredData SBTarget::GetStatistics(bool summary_only) {
201201
LLDB_INSTRUMENT_VA(this);
202202

203203
SBStructuredData data;
204204
TargetSP target_sp(GetSP());
205205
if (!target_sp)
206206
return data;
207207
std::string json_str =
208-
llvm::formatv("{0:2}",
209-
DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
210-
target_sp.get())).str();
208+
llvm::formatv(
209+
"{0:2}", DebuggerStats::ReportStatistics(
210+
target_sp->GetDebugger(), target_sp.get(), summary_only))
211+
.str();
211212
data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
212213
return data;
213214
}

lldb/source/Commands/CommandObjectStats.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
7575
case 'a':
7676
m_all_targets = true;
7777
break;
78+
case 's':
79+
m_summary_only = true;
80+
break;
7881
default:
7982
llvm_unreachable("Unimplemented option");
8083
}
@@ -83,13 +86,15 @@ class CommandObjectStatsDump : public CommandObjectParsed {
8386

8487
void OptionParsingStarting(ExecutionContext *execution_context) override {
8588
m_all_targets = false;
89+
m_summary_only = false;
8690
}
8791

8892
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
8993
return llvm::ArrayRef(g_statistics_dump_options);
9094
}
9195

9296
bool m_all_targets = false;
97+
bool m_summary_only = false;
9398
};
9499

95100
public:
@@ -109,7 +114,8 @@ class CommandObjectStatsDump : public CommandObjectParsed {
109114
target = m_exe_ctx.GetTargetPtr();
110115

111116
result.AppendMessageWithFormatv(
112-
"{0:2}", DebuggerStats::ReportStatistics(GetDebugger(), target));
117+
"{0:2}", DebuggerStats::ReportStatistics(GetDebugger(), target,
118+
m_options.m_summary_only));
113119
result.SetStatus(eReturnStatusSuccessFinishResult);
114120
}
115121

lldb/source/Commands/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,4 +1412,7 @@ let Command = "trace schema" in {
14121412
let Command = "statistics dump" in {
14131413
def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
14141414
Desc<"Include statistics for all targets.">;
1415+
def statistics_dump_summary: Option<"summary", "s">, Group<1>,
1416+
Desc<"Dump only high level summary statistics."
1417+
"Exclude targets, modules, breakpoints etc.. details.">;
14151418
}

0 commit comments

Comments
 (0)