Skip to content

Commit acb54eb

Browse files
committed
Create SBStatisticsOptions API
Summary: We can't take away or change a previously available public API function. To avoid future changes, we intruduce an option type that we can extend without modifying existing APIs.
1 parent 1d521d7 commit acb54eb

File tree

13 files changed

+126
-18
lines changed

13 files changed

+126
-18
lines changed

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
class LLDB_API SBStatisticsOptions {
17+
public:
18+
SBStatisticsOptions();
19+
SBStatisticsOptions(const lldb::SBStatisticsOptions &rhs);
20+
~SBStatisticsOptions();
21+
22+
const SBStatisticsOptions &operator=(const lldb::SBStatisticsOptions &rhs);
23+
24+
void SetSummaryOnly(bool b);
25+
lldb_private::StatisticsOptions GetStatisticsOptions();
26+
27+
private:
28+
std::unique_ptr<lldb_private::StatisticsOptions> m_opaque_up;
29+
};
30+
} // namespace lldb
31+
#endif // LLDB_API_SBSTATISTICSOPTIONS_H

lldb/include/lldb/API/SBTarget.h

Lines changed: 10 additions & 4 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"
@@ -86,13 +87,18 @@ class LLDB_API SBTarget {
8687

8788
/// Returns a dump of the collected statistics.
8889
///
89-
/// \param[in] summary_only
90-
/// If true, only report high level summary statistics without
91-
/// targets/modules/breakpoints etc.. details.
90+
/// \return
91+
/// A SBStructuredData with the statistics collected.
92+
lldb::SBStructuredData GetStatistics();
93+
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.
9298
///
9399
/// \return
94100
/// A SBStructuredData with the statistics collected.
95-
lldb::SBStructuredData GetStatistics(bool summary_only = false);
101+
lldb::SBStructuredData GetStatistics(SBStatisticsOptions options);
96102

97103
/// Return the platform object associated with the target.
98104
///

lldb/include/lldb/Target/Statistics.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ 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:
@@ -177,8 +181,9 @@ class DebuggerStats {
177181
///
178182
/// \return
179183
/// Returns a JSON value that contains all target metrics.
180-
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
181-
bool summary_only = false);
184+
static llvm::json::Value
185+
ReportStatistics(Debugger &debugger, Target *target,
186+
const lldb_private::StatisticsOptions &options);
182187

183188
protected:
184189
// 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(bool summary_only = false);
1602+
llvm::json::Value ReportStatistics(const lldb_private::StatisticsOptions &options);
16031603

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

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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}
22+
23+
SBStatisticsOptions::SBStatisticsOptions(const SBStatisticsOptions &rhs) {
24+
LLDB_INSTRUMENT_VA(this, rhs);
25+
26+
m_opaque_up = clone(rhs.m_opaque_up);
27+
}
28+
29+
SBStatisticsOptions::~SBStatisticsOptions() = default;
30+
31+
const SBStatisticsOptions &
32+
SBStatisticsOptions::operator=(const SBStatisticsOptions &rhs) {
33+
LLDB_INSTRUMENT_VA(this, rhs);
34+
35+
if (this != &rhs)
36+
m_opaque_up = clone(rhs.m_opaque_up);
37+
return *this;
38+
}
39+
40+
void SBStatisticsOptions::SetSummaryOnly(bool b) {
41+
m_opaque_up->summary_only = b;
42+
}
43+
44+
lldb_private::StatisticsOptions SBStatisticsOptions::GetStatisticsOptions() {
45+
return *m_opaque_up;
46+
}

lldb/source/API/SBTarget.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,14 @@ SBDebugger SBTarget::GetDebugger() const {
197197
return debugger;
198198
}
199199

200-
SBStructuredData SBTarget::GetStatistics(bool summary_only) {
200+
SBStructuredData SBTarget::GetStatistics() {
201+
LLDB_INSTRUMENT_VA(this);
202+
SBStatisticsOptions options;
203+
options.SetSummaryOnly(false);
204+
return GetStatistics(options);
205+
}
206+
207+
SBStructuredData SBTarget::GetStatistics(SBStatisticsOptions options) {
201208
LLDB_INSTRUMENT_VA(this);
202209

203210
SBStructuredData data;
@@ -207,7 +214,7 @@ SBStructuredData SBTarget::GetStatistics(bool summary_only) {
207214
std::string json_str =
208215
llvm::formatv(
209216
"{0:2}", DebuggerStats::ReportStatistics(
210-
target_sp->GetDebugger(), target_sp.get(), summary_only))
217+
target_sp->GetDebugger(), target_sp.get(), options.GetStatisticsOptions()))
211218
.str();
212219
data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
213220
return data;

lldb/source/Commands/CommandObjectStats.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
9393
return llvm::ArrayRef(g_statistics_dump_options);
9494
}
9595

96+
StatisticsOptions GetStatisticsOptions() {
97+
StatisticsOptions options;
98+
options.summary_only = m_summary_only;
99+
return options;
100+
}
101+
96102
bool m_all_targets = false;
97103
bool m_summary_only = false;
98104
};
@@ -114,8 +120,8 @@ class CommandObjectStatsDump : public CommandObjectParsed {
114120
target = m_exe_ctx.GetTargetPtr();
115121

116122
result.AppendMessageWithFormatv(
117-
"{0:2}", DebuggerStats::ReportStatistics(GetDebugger(), target,
118-
m_options.m_summary_only));
123+
"{0:2}", DebuggerStats::ReportStatistics(
124+
GetDebugger(), target, m_options.GetStatisticsOptions()));
119125
result.SetStatus(eReturnStatusSuccessFinishResult);
120126
}
121127

lldb/source/Target/Statistics.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ void TargetStats::IncreaseSourceMapDeduceCount() {
216216

217217
bool DebuggerStats::g_collecting_stats = false;
218218

219-
llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
220-
Target *target,
221-
bool summary_only) {
219+
llvm::json::Value DebuggerStats::ReportStatistics(
220+
Debugger &debugger, Target *target,
221+
const lldb_private::StatisticsOptions &options) {
222+
223+
bool summary_only = options.summary_only;
224+
222225
json::Array json_targets;
223226
json::Array json_modules;
224227
double symtab_parse_time = 0.0;
@@ -338,10 +341,10 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
338341
};
339342

340343
if (target) {
341-
json_targets.emplace_back(target->ReportStatistics(summary_only));
344+
json_targets.emplace_back(target->ReportStatistics(options));
342345
} else {
343346
for (const auto &target : debugger.GetTargetList().Targets())
344-
json_targets.emplace_back(target->ReportStatistics(summary_only));
347+
json_targets.emplace_back(target->ReportStatistics(options));
345348
}
346349
global_stats.try_emplace("targets", std::move(json_targets));
347350

lldb/source/Target/Target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4962,6 +4962,6 @@ std::recursive_mutex &Target::GetAPIMutex() {
49624962
}
49634963

49644964
/// Get metrics associated with this target in JSON format.
4965-
llvm::json::Value Target::ReportStatistics(bool summary_only) {
4966-
return m_stats.ToJSON(*this, summary_only);
4965+
llvm::json::Value Target::ReportStatistics(const lldb_private::StatisticsOptions &options) {
4966+
return m_stats.ToJSON(*this, options.summary_only);
49674967
}

0 commit comments

Comments
 (0)