Skip to content

Support statistics dump summary only mode #80745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/bindings/headers.swig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "lldb/API/SBScriptObject.h"
#include "lldb/API/SBSection.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStatisticsOptions.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBStructuredData.h"
Expand Down
8 changes: 8 additions & 0 deletions lldb/bindings/interface/SBStatisticsOptionsDocStrings.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%feature("docstring",
"A container for options to use when dumping statistics."
) lldb::SBStatisticsOptions;

%feature("docstring", "Sets whether the statistics should only dump a summary."
) lldb::SBStatisticsOptions::SetSummaryOnly;
%feature("docstring", "Gets whether the statistics only dump a summary."
) lldb::SBStatisticsOptions::GetSummaryOnly;
2 changes: 2 additions & 0 deletions lldb/bindings/interfaces.swig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
%include "./interface/SBReproducerDocstrings.i"
%include "./interface/SBSectionDocstrings.i"
%include "./interface/SBSourceManagerDocstrings.i"
%include "./interface/SBStatisticsOptionsDocstrings.i"
%include "./interface/SBStreamDocstrings.i"
%include "./interface/SBStringListDocstrings.i"
%include "./interface/SBStructuredDataDocstrings.i"
Expand Down Expand Up @@ -131,6 +132,7 @@
%include "lldb/API/SBScriptObject.h"
%include "lldb/API/SBSection.h"
%include "lldb/API/SBSourceManager.h"
%include "lldb/API/SBStatisticsOptions.h"
%include "lldb/API/SBStream.h"
%include "lldb/API/SBStringList.h"
%include "lldb/API/SBStructuredData.h"
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/LLDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "lldb/API/SBReproducer.h"
#include "lldb/API/SBSection.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStatisticsOptions.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBStructuredData.h"
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class LLDB_API SBReproducer;
class LLDB_API SBScriptObject;
class LLDB_API SBSection;
class LLDB_API SBSourceManager;
class LLDB_API SBStatisticsOptions;
class LLDB_API SBStream;
class LLDB_API SBStringList;
class LLDB_API SBStructuredData;
Expand Down
36 changes: 36 additions & 0 deletions lldb/include/lldb/API/SBStatisticsOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===-- SBStatisticsOptions.h -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_API_SBSTATISTICSOPTIONS_H
#define LLDB_API_SBSTATISTICSOPTIONS_H

#include "lldb/API/SBDefines.h"

namespace lldb {

/// This class handles the verbosity when dumping statistics
class LLDB_API SBStatisticsOptions {
public:
SBStatisticsOptions();
SBStatisticsOptions(const lldb::SBStatisticsOptions &rhs);
~SBStatisticsOptions();

const SBStatisticsOptions &operator=(const lldb::SBStatisticsOptions &rhs);

void SetSummaryOnly(bool b);
bool GetSummaryOnly();

protected:
friend class SBTarget;
const lldb_private::StatisticsOptions &ref() const;

private:
std::unique_ptr<lldb_private::StatisticsOptions> m_opaque_up;
};
} // namespace lldb
#endif // LLDB_API_SBSTATISTICSOPTIONS_H
10 changes: 10 additions & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBFileSpecList.h"
#include "lldb/API/SBLaunchInfo.h"
#include "lldb/API/SBStatisticsOptions.h"
#include "lldb/API/SBSymbolContextList.h"
#include "lldb/API/SBType.h"
#include "lldb/API/SBValue.h"
Expand Down Expand Up @@ -90,6 +91,15 @@ class LLDB_API SBTarget {
/// A SBStructuredData with the statistics collected.
lldb::SBStructuredData GetStatistics();

/// Returns a dump of the collected statistics.
///
/// \param[in] options
/// An objects object that contains all options for the statistics dumping.
///
/// \return
/// A SBStructuredData with the statistics collected.
lldb::SBStructuredData GetStatistics(SBStatisticsOptions options);

/// Return the platform object associated with the target.
///
/// After return, the platform object should be checked for
Expand Down
15 changes: 13 additions & 2 deletions lldb/include/lldb/Target/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ struct ConstStringStats {
ConstString::MemoryStats stats = ConstString::GetMemoryStats();
};

struct StatisticsOptions {
bool summary_only = false;
};

/// A class that represents statistics for a since lldb_private::Target.
class TargetStats {
public:
llvm::json::Value ToJSON(Target &target);
llvm::json::Value ToJSON(Target &target,
const lldb_private::StatisticsOptions &options);

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

protected:
// Collecting stats can be set to true to collect stats that are expensive
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,8 @@ class Target : public std::enable_shared_from_this<Target>,
///
/// \return
/// Returns a JSON value that contains all target metrics.
llvm::json::Value ReportStatistics();
llvm::json::Value
ReportStatistics(const lldb_private::StatisticsOptions &options);

TargetStats &GetStatistics() { return m_stats; }

Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ struct CompilerContext;
struct LineEntry;
struct PropertyDefinition;
struct ScriptSummaryFormat;
struct StatisticsOptions;
struct StringSummaryFormat;
template <unsigned N> class StreamBuffer;

Expand Down
1 change: 1 addition & 0 deletions lldb/source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
SBScriptObject.cpp
SBSection.cpp
SBSourceManager.cpp
SBStatisticsOptions.cpp
SBStream.cpp
SBStringList.cpp
SBStructuredData.cpp
Expand Down
49 changes: 49 additions & 0 deletions lldb/source/API/SBStatisticsOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===-- SBStatisticsOptions.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/API/SBStatisticsOptions.h"
#include "lldb/Target/Statistics.h"
#include "lldb/Utility/Instrumentation.h"

#include "Utils.h"

using namespace lldb;
using namespace lldb_private;

SBStatisticsOptions::SBStatisticsOptions()
: m_opaque_up(new StatisticsOptions()) {
LLDB_INSTRUMENT_VA(this);
m_opaque_up->summary_only = false;
}

SBStatisticsOptions::SBStatisticsOptions(const SBStatisticsOptions &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);

m_opaque_up = clone(rhs.m_opaque_up);
}

SBStatisticsOptions::~SBStatisticsOptions() = default;

const SBStatisticsOptions &
SBStatisticsOptions::operator=(const SBStatisticsOptions &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);

if (this != &rhs)
m_opaque_up = clone(rhs.m_opaque_up);
return *this;
}

void SBStatisticsOptions::SetSummaryOnly(bool b) {
m_opaque_up->summary_only = b;
}

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

const lldb_private::StatisticsOptions &SBStatisticsOptions::ref() const {
return *m_opaque_up;
}
13 changes: 10 additions & 3 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,22 @@ SBDebugger SBTarget::GetDebugger() const {

SBStructuredData SBTarget::GetStatistics() {
LLDB_INSTRUMENT_VA(this);
SBStatisticsOptions options;
return GetStatistics(options);
}

SBStructuredData SBTarget::GetStatistics(SBStatisticsOptions options) {
LLDB_INSTRUMENT_VA(this);

SBStructuredData data;
TargetSP target_sp(GetSP());
if (!target_sp)
return data;
std::string json_str =
llvm::formatv("{0:2}",
DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
target_sp.get())).str();
llvm::formatv("{0:2}", DebuggerStats::ReportStatistics(
target_sp->GetDebugger(), target_sp.get(),
options.ref()))
.str();
data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
return data;
}
Expand Down
10 changes: 9 additions & 1 deletion lldb/source/Commands/CommandObjectStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
case 'a':
m_all_targets = true;
break;
case 's':
m_stats_options.summary_only = true;
break;
default:
llvm_unreachable("Unimplemented option");
}
Expand All @@ -83,13 +86,17 @@ class CommandObjectStatsDump : public CommandObjectParsed {

void OptionParsingStarting(ExecutionContext *execution_context) override {
m_all_targets = false;
m_stats_options = StatisticsOptions();
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_statistics_dump_options);
}

const StatisticsOptions &GetStatisticsOptions() { return m_stats_options; }

bool m_all_targets = false;
StatisticsOptions m_stats_options = StatisticsOptions();
};

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

result.AppendMessageWithFormatv(
"{0:2}", DebuggerStats::ReportStatistics(GetDebugger(), target));
"{0:2}", DebuggerStats::ReportStatistics(
GetDebugger(), target, m_options.GetStatisticsOptions()));
result.SetStatus(eReturnStatusSuccessFinishResult);
}

Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1412,4 +1412,7 @@ let Command = "trace schema" in {
let Command = "statistics dump" in {
def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
Desc<"Include statistics for all targets.">;
def statistics_dump_summary: Option<"summary", "s">, Group<1>,
Desc<"Dump only high-level summary statistics."
"Exclude targets, modules, breakpoints etc... details.">;
}
Loading