Skip to content

Commit f63080b

Browse files
committed
Move to a unified function for the kind name
1 parent aa71d5f commit f63080b

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

lldb/include/lldb/DataFormatters/TypeSummary.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class TypeSummaryImpl {
264264

265265
/// Get the name of the kind of Summary Provider, either c++, summary string,
266266
/// script or python.
267-
virtual std::string GetSummaryKindName() = 0;
267+
virtual std::string GetSummaryKindName();
268268

269269
uint32_t &GetRevision() { return m_my_revision; }
270270

@@ -302,7 +302,6 @@ struct StringSummaryFormat : public TypeSummaryImpl {
302302
std::string GetDescription() override;
303303

304304
std::string GetName() override;
305-
std::string GetSummaryKindName() override;
306305

307306
static bool classof(const TypeSummaryImpl *S) {
308307
return S->GetKind() == Kind::eSummaryString;
@@ -352,7 +351,6 @@ struct CXXFunctionSummaryFormat : public TypeSummaryImpl {
352351
}
353352

354353
std::string GetName() override;
355-
std::string GetSummaryKindName() override;
356354

357355
typedef std::shared_ptr<CXXFunctionSummaryFormat> SharedPointer;
358356

@@ -400,7 +398,6 @@ struct ScriptSummaryFormat : public TypeSummaryImpl {
400398
std::string GetDescription() override;
401399

402400
std::string GetName() override;
403-
std::string GetSummaryKindName() override;
404401

405402
static bool classof(const TypeSummaryImpl *S) {
406403
return S->GetKind() == Kind::eScript;

lldb/include/lldb/Target/Statistics.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace lldb_private {
2828

2929
using StatsClock = std::chrono::high_resolution_clock;
3030
using StatsTimepoint = std::chrono::time_point<StatsClock>;
31+
class SummaryStatistics;
32+
// Declaring here as there is no private forward
33+
typedef std::shared_ptr<SummaryStatistics> SummaryStatisticsSP;
3134

3235
class StatsDuration {
3336
public:
@@ -201,7 +204,7 @@ class SummaryStatistics {
201204
/// Basic RAII class to increment the summary count when the call is complete.
202205
class SummaryInvocation {
203206
public:
204-
SummaryInvocation(std::shared_ptr<SummaryStatistics> summary_stats)
207+
SummaryInvocation(SummaryStatisticsSP summary_stats)
205208
: m_stats(summary_stats),
206209
m_elapsed_time(summary_stats->GetDurationReference()) {}
207210
~SummaryInvocation() { m_stats->OnInvoked(); }
@@ -214,7 +217,7 @@ class SummaryStatistics {
214217
/// @}
215218

216219
private:
217-
std::shared_ptr<SummaryStatistics> m_stats;
220+
SummaryStatisticsSP m_stats;
218221
ElapsedTime m_elapsed_time;
219222
};
220223

@@ -226,9 +229,6 @@ class SummaryStatistics {
226229
std::atomic<uint64_t> m_count;
227230
};
228231

229-
// Declaring here as there is no private forward
230-
typedef std::shared_ptr<SummaryStatistics> SummaryStatisticsSP;
231-
232232
/// A class that wraps a std::map of SummaryStatistics objects behind a mutex.
233233
class SummaryStatisticsCache {
234234
public:

lldb/source/DataFormatters/TypeSummary.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ TypeSummaryOptions::SetCapping(lldb::TypeSummaryCapping cap) {
4848
TypeSummaryImpl::TypeSummaryImpl(Kind kind, const TypeSummaryImpl::Flags &flags)
4949
: m_flags(flags), m_kind(kind) {}
5050

51+
std::string TypeSummaryImpl::GetSummaryKindName() {
52+
switch (m_kind) {
53+
case Kind::eSummaryString:
54+
return "string";
55+
case Kind::eCallback:
56+
return "callback";
57+
case Kind::eScript:
58+
return "python";
59+
case Kind::eInternal:
60+
return "c++";
61+
}
62+
}
63+
5164
StringSummaryFormat::StringSummaryFormat(const TypeSummaryImpl::Flags &flags,
5265
const char *format_cstr)
5366
: TypeSummaryImpl(Kind::eSummaryString, flags), m_format_str() {
@@ -117,7 +130,6 @@ std::string StringSummaryFormat::GetDescription() {
117130
}
118131

119132
std::string StringSummaryFormat::GetName() { return m_format_str; }
120-
std::string StringSummaryFormat::GetSummaryKindName() { return "string"; }
121133

122134
CXXFunctionSummaryFormat::CXXFunctionSummaryFormat(
123135
const TypeSummaryImpl::Flags &flags, Callback impl, const char *description)
@@ -150,8 +162,6 @@ std::string CXXFunctionSummaryFormat::GetDescription() {
150162

151163
std::string CXXFunctionSummaryFormat::GetName() { return m_description; }
152164

153-
std::string CXXFunctionSummaryFormat::GetSummaryKindName() { return "c++"; }
154-
155165
ScriptSummaryFormat::ScriptSummaryFormat(const TypeSummaryImpl::Flags &flags,
156166
const char *function_name,
157167
const char *python_script)
@@ -220,10 +230,3 @@ std::string ScriptSummaryFormat::GetDescription() {
220230
}
221231

222232
std::string ScriptSummaryFormat::GetName() { return m_script_formatter_name; }
223-
224-
std::string ScriptSummaryFormat::GetSummaryKindName() {
225-
if (!m_python_script.empty())
226-
return "python";
227-
228-
return "script";
229-
}

lldb/test/API/commands/statistics/basic/TestStats.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ def test_summary_statistics_providers(self):
943943
self.assertIn("'count': 1", summary_provider_str)
944944
self.assertIn("'totalTime':", summary_provider_str)
945945
# We may hit the std::string C++ provider, or a summary provider string
946-
self.assertRegex(r"'type': '(c++|string)'", summary_provider_str)
946+
self.assertIn("'type':", summary_provider_str)
947+
self.assertTrue("c++" in summary_provider_str or "string" in summary_provider_str)
947948

948949
self.runCmd("continue")
949950
self.runCmd("command script import BoxFormatter.py")
@@ -952,7 +953,7 @@ def test_summary_statistics_providers(self):
952953
self.assertIn("summaryProviderStatistics", stats)
953954
summary_providers = stats["summaryProviderStatistics"]
954955
summary_provider_str = str(summary_providers)
955-
self.assertRegex("'name': 'BoxFormatter.summary'", summary_provider_str)
956+
self.assertIn("'name': 'BoxFormatter.summary'", summary_provider_str)
956957
self.assertIn("'count': 1", summary_provider_str)
957958
self.assertIn("'totalTime':", summary_provider_str)
958959
self.assertIn("'type': 'python'", summary_provider_str)
@@ -977,7 +978,7 @@ def test_summary_statistics_providers_vec(self):
977978
summary_provider_str = str(summary_providers)
978979
self.assertIn("'count': 2", summary_provider_str)
979980
self.assertIn("'totalTime':", summary_provider_str)
980-
self.assertRegex(r"'type': '(c++|string)'", summary_provider_str)
981+
self.assertIn("'type':", summary_provider_str)
981982
# We may hit the std::vector C++ provider, or a summary provider string
982983
if "c++" in summary_provider_str:
983984
self.assertIn("std::vector", summary_provider_str)

0 commit comments

Comments
 (0)