Skip to content

Commit 2217837

Browse files
authored
Support statistics dump summary only mode (#80745)
Add a new --summary option to statistics dump command so that it is much more light weight than the full version. Introduce a new SBStatisticsOptions API setting the verbosity of statistics dump. [PR #80218](#80218 (comment))
1 parent 1b03cbc commit 2217837

File tree

19 files changed

+297
-87
lines changed

19 files changed

+297
-87
lines changed

lldb/bindings/headers.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "lldb/API/SBScriptObject.h"
5555
#include "lldb/API/SBSection.h"
5656
#include "lldb/API/SBSourceManager.h"
57+
#include "lldb/API/SBStatisticsOptions.h"
5758
#include "lldb/API/SBStream.h"
5859
#include "lldb/API/SBStringList.h"
5960
#include "lldb/API/SBStructuredData.h"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
%feature("docstring",
2+
"A container for options to use when dumping statistics."
3+
) lldb::SBStatisticsOptions;
4+
5+
%feature("docstring", "Sets whether the statistics should only dump a summary."
6+
) lldb::SBStatisticsOptions::SetSummaryOnly;
7+
%feature("docstring", "Gets whether the statistics only dump a summary."
8+
) lldb::SBStatisticsOptions::GetSummaryOnly;

lldb/bindings/interfaces.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
%include "./interface/SBReproducerDocstrings.i"
5757
%include "./interface/SBSectionDocstrings.i"
5858
%include "./interface/SBSourceManagerDocstrings.i"
59+
%include "./interface/SBStatisticsOptionsDocstrings.i"
5960
%include "./interface/SBStreamDocstrings.i"
6061
%include "./interface/SBStringListDocstrings.i"
6162
%include "./interface/SBStructuredDataDocstrings.i"
@@ -131,6 +132,7 @@
131132
%include "lldb/API/SBScriptObject.h"
132133
%include "lldb/API/SBSection.h"
133134
%include "lldb/API/SBSourceManager.h"
135+
%include "lldb/API/SBStatisticsOptions.h"
134136
%include "lldb/API/SBStream.h"
135137
%include "lldb/API/SBStringList.h"
136138
%include "lldb/API/SBStructuredData.h"

lldb/include/lldb/API/LLDB.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "lldb/API/SBReproducer.h"
5757
#include "lldb/API/SBSection.h"
5858
#include "lldb/API/SBSourceManager.h"
59+
#include "lldb/API/SBStatisticsOptions.h"
5960
#include "lldb/API/SBStream.h"
6061
#include "lldb/API/SBStringList.h"
6162
#include "lldb/API/SBStructuredData.h"

lldb/include/lldb/API/SBDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class LLDB_API SBReproducer;
9999
class LLDB_API SBScriptObject;
100100
class LLDB_API SBSection;
101101
class LLDB_API SBSourceManager;
102+
class LLDB_API SBStatisticsOptions;
102103
class LLDB_API SBStream;
103104
class LLDB_API SBStringList;
104105
class LLDB_API SBStructuredData;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- SBStatisticsOptions.h -----------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_API_SBSTATISTICSOPTIONS_H
10+
#define LLDB_API_SBSTATISTICSOPTIONS_H
11+
12+
#include "lldb/API/SBDefines.h"
13+
14+
namespace lldb {
15+
16+
/// This class handles the verbosity when dumping statistics
17+
class LLDB_API SBStatisticsOptions {
18+
public:
19+
SBStatisticsOptions();
20+
SBStatisticsOptions(const lldb::SBStatisticsOptions &rhs);
21+
~SBStatisticsOptions();
22+
23+
const SBStatisticsOptions &operator=(const lldb::SBStatisticsOptions &rhs);
24+
25+
void SetSummaryOnly(bool b);
26+
bool GetSummaryOnly();
27+
28+
protected:
29+
friend class SBTarget;
30+
const lldb_private::StatisticsOptions &ref() const;
31+
32+
private:
33+
std::unique_ptr<lldb_private::StatisticsOptions> m_opaque_up;
34+
};
35+
} // namespace lldb
36+
#endif // LLDB_API_SBSTATISTICSOPTIONS_H

lldb/include/lldb/API/SBTarget.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "lldb/API/SBFileSpec.h"
1818
#include "lldb/API/SBFileSpecList.h"
1919
#include "lldb/API/SBLaunchInfo.h"
20+
#include "lldb/API/SBStatisticsOptions.h"
2021
#include "lldb/API/SBSymbolContextList.h"
2122
#include "lldb/API/SBType.h"
2223
#include "lldb/API/SBValue.h"
@@ -90,6 +91,15 @@ class LLDB_API SBTarget {
9091
/// A SBStructuredData with the statistics collected.
9192
lldb::SBStructuredData GetStatistics();
9293

94+
/// Returns a dump of the collected statistics.
95+
///
96+
/// \param[in] options
97+
/// An objects object that contains all options for the statistics dumping.
98+
///
99+
/// \return
100+
/// A SBStructuredData with the statistics collected.
101+
lldb::SBStructuredData GetStatistics(SBStatisticsOptions options);
102+
93103
/// Return the platform object associated with the target.
94104
///
95105
/// After return, the platform object should be checked for

lldb/include/lldb/Target/Statistics.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,15 @@ struct ConstStringStats {
130130
ConstString::MemoryStats stats = ConstString::GetMemoryStats();
131131
};
132132

133+
struct StatisticsOptions {
134+
bool summary_only = false;
135+
};
136+
133137
/// A class that represents statistics for a since lldb_private::Target.
134138
class TargetStats {
135139
public:
136-
llvm::json::Value ToJSON(Target &target);
140+
llvm::json::Value ToJSON(Target &target,
141+
const lldb_private::StatisticsOptions &options);
137142

138143
void SetLaunchOrAttachTime();
139144
void SetFirstPrivateStopTime();
@@ -171,9 +176,15 @@ class DebuggerStats {
171176
/// The single target to emit statistics for if non NULL, otherwise dump
172177
/// statistics only for the specified target.
173178
///
179+
/// \param summary_only
180+
/// If true, only report high level summary statistics without
181+
/// targets/modules/breakpoints etc.. details.
182+
///
174183
/// \return
175184
/// Returns a JSON value that contains all target metrics.
176-
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target);
185+
static llvm::json::Value
186+
ReportStatistics(Debugger &debugger, Target *target,
187+
const lldb_private::StatisticsOptions &options);
177188

178189
protected:
179190
// Collecting stats can be set to true to collect stats that are expensive

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,8 @@ 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
1603+
ReportStatistics(const lldb_private::StatisticsOptions &options);
16031604

16041605
TargetStats &GetStatistics() { return m_stats; }
16051606

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ struct CompilerContext;
298298
struct LineEntry;
299299
struct PropertyDefinition;
300300
struct ScriptSummaryFormat;
301+
struct StatisticsOptions;
301302
struct StringSummaryFormat;
302303
template <unsigned N> class StreamBuffer;
303304

lldb/source/API/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
6969
SBScriptObject.cpp
7070
SBSection.cpp
7171
SBSourceManager.cpp
72+
SBStatisticsOptions.cpp
7273
SBStream.cpp
7374
SBStringList.cpp
7475
SBStructuredData.cpp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===-- SBStatisticsOptions.cpp -------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "lldb/API/SBStatisticsOptions.h"
10+
#include "lldb/Target/Statistics.h"
11+
#include "lldb/Utility/Instrumentation.h"
12+
13+
#include "Utils.h"
14+
15+
using namespace lldb;
16+
using namespace lldb_private;
17+
18+
SBStatisticsOptions::SBStatisticsOptions()
19+
: m_opaque_up(new StatisticsOptions()) {
20+
LLDB_INSTRUMENT_VA(this);
21+
m_opaque_up->summary_only = false;
22+
}
23+
24+
SBStatisticsOptions::SBStatisticsOptions(const SBStatisticsOptions &rhs) {
25+
LLDB_INSTRUMENT_VA(this, rhs);
26+
27+
m_opaque_up = clone(rhs.m_opaque_up);
28+
}
29+
30+
SBStatisticsOptions::~SBStatisticsOptions() = default;
31+
32+
const SBStatisticsOptions &
33+
SBStatisticsOptions::operator=(const SBStatisticsOptions &rhs) {
34+
LLDB_INSTRUMENT_VA(this, rhs);
35+
36+
if (this != &rhs)
37+
m_opaque_up = clone(rhs.m_opaque_up);
38+
return *this;
39+
}
40+
41+
void SBStatisticsOptions::SetSummaryOnly(bool b) {
42+
m_opaque_up->summary_only = b;
43+
}
44+
45+
bool SBStatisticsOptions::GetSummaryOnly() { return m_opaque_up->summary_only; }
46+
47+
const lldb_private::StatisticsOptions &SBStatisticsOptions::ref() const {
48+
return *m_opaque_up;
49+
}

lldb/source/API/SBTarget.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,22 @@ SBDebugger SBTarget::GetDebugger() const {
199199

200200
SBStructuredData SBTarget::GetStatistics() {
201201
LLDB_INSTRUMENT_VA(this);
202+
SBStatisticsOptions options;
203+
return GetStatistics(options);
204+
}
205+
206+
SBStructuredData SBTarget::GetStatistics(SBStatisticsOptions options) {
207+
LLDB_INSTRUMENT_VA(this);
202208

203209
SBStructuredData data;
204210
TargetSP target_sp(GetSP());
205211
if (!target_sp)
206212
return data;
207213
std::string json_str =
208-
llvm::formatv("{0:2}",
209-
DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
210-
target_sp.get())).str();
214+
llvm::formatv("{0:2}", DebuggerStats::ReportStatistics(
215+
target_sp->GetDebugger(), target_sp.get(),
216+
options.ref()))
217+
.str();
211218
data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
212219
return data;
213220
}

lldb/source/Commands/CommandObjectStats.cpp

Lines changed: 9 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_stats_options.summary_only = true;
80+
break;
7881
default:
7982
llvm_unreachable("Unimplemented option");
8083
}
@@ -83,13 +86,17 @@ class CommandObjectStatsDump : public CommandObjectParsed {
8386

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

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

96+
const StatisticsOptions &GetStatisticsOptions() { return m_stats_options; }
97+
9298
bool m_all_targets = false;
99+
StatisticsOptions m_stats_options = StatisticsOptions();
93100
};
94101

95102
public:
@@ -109,7 +116,8 @@ class CommandObjectStatsDump : public CommandObjectParsed {
109116
target = m_exe_ctx.GetTargetPtr();
110117

111118
result.AppendMessageWithFormatv(
112-
"{0:2}", DebuggerStats::ReportStatistics(GetDebugger(), target));
119+
"{0:2}", DebuggerStats::ReportStatistics(
120+
GetDebugger(), target, m_options.GetStatisticsOptions()));
113121
result.SetStatus(eReturnStatusSuccessFinishResult);
114122
}
115123

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)