aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@fb.com>2021-10-20 14:49:09 -0700
committerGreg Clayton <gclayton@fb.com>2021-10-21 12:14:21 -0700
commitd7b338537cf360568474d31c2be86110ac22dc32 (patch)
tree452bea87995e1af2dcdfad1a5f326b04cfd7f9b3 /lldb/source/Commands
parent0472e83ffcc6c0506b0cd67844b97cb34eaa302e (diff)
downloadllvm-d7b338537cf360568474d31c2be86110ac22dc32.zip
llvm-d7b338537cf360568474d31c2be86110ac22dc32.tar.gz
llvm-d7b338537cf360568474d31c2be86110ac22dc32.tar.bz2
Modify "statistics dump" to dump JSON.
This patch is a smaller version of a previous patch https://reviews.llvm.org/D110804. This patch modifies the output of "statistics dump" to be able to get stats from the current target. It adds 3 new stats as well. The output of "statistics dump" is now emitted as JSON so that it can be used to track performance and statistics and the output could be used to populate a database that tracks performance. Sample output looks like: (lldb) statistics dump { "expressionEvaluation": { "failures": 0, "successes": 0 }, "firstStopTime": 0.34164492800000001, "frameVariable": { "failures": 0, "successes": 0 }, "launchOrAttachTime": 0.31969605400000001, "targetCreateTime": 0.0040863039999999998 } The top level keys are: "expressionEvaluation" which replaces the previous stats that were emitted as plain text. This dictionary contains the success and fail counts. "frameVariable" which replaces the previous stats for "frame variable" that were emitted as plain text. This dictionary contains the success and fail counts. "targetCreateTime" contains the number of seconds it took to create the target and load dependent libraries (if they were enabled) and also will contain symbol preloading times if that setting is enabled. "launchOrAttachTime" is the time it takes from when the launch/attach is initiated to when the first private stop occurs. "firstStopTime" is the time in seconds that it takes to stop at the first stop that is presented to the user via the LLDB interface. This value will only have meaning if you set a known breakpoint or stop location in your code that you want to measure as a performance test. This diff is also meant as a place to discuess what we want out of the "statistics dump" command before adding more funcionality. It is also meant to clean up the previous code that was storting statistics in a vector of numbers within the lldb_private::Target class. Differential Revision: https://reviews.llvm.org/D111686
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp5
-rw-r--r--lldb/source/Commands/CommandObjectFrame.cpp6
-rw-r--r--lldb/source/Commands/CommandObjectStats.cpp73
-rw-r--r--lldb/source/Commands/Options.td5
4 files changed, 60 insertions, 29 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index a93cc15b..9d13cca 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -659,13 +659,8 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command,
fixed_command.append(m_fixed_expression);
history.AppendString(fixed_command);
}
- // Increment statistics to record this expression evaluation success.
- target.IncrementStats(StatisticKind::ExpressionSuccessful);
return true;
}
-
- // Increment statistics to record this expression evaluation failure.
- target.IncrementStats(StatisticKind::ExpressionFailure);
result.SetStatus(eReturnStatusFailed);
return false;
}
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 9e5d79c..2b9f531 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -708,11 +708,11 @@ protected:
// Increment statistics.
bool res = result.Succeeded();
- Target &target = GetSelectedOrDummyTarget();
+ TargetStats &target_stats = GetSelectedOrDummyTarget().GetStatistics();
if (res)
- target.IncrementStats(StatisticKind::FrameVarSuccess);
+ target_stats.GetFrameVariableStats().NotifySuccess();
else
- target.IncrementStats(StatisticKind::FrameVarFailure);
+ target_stats.GetFrameVariableStats().NotifyFailure();
return res;
}
diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp
index 23c7dbb..70d63af 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
#include "CommandObjectStats.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Target/Target.h"
@@ -24,14 +26,12 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- Target &target = GetSelectedOrDummyTarget();
-
- if (target.GetCollectingStats()) {
+ if (DebuggerStats::GetCollectingStats()) {
result.AppendError("statistics already enabled");
return false;
}
- target.SetCollectingStats(true);
+ DebuggerStats::SetCollectingStats(true);
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
@@ -48,44 +48,75 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- Target &target = GetSelectedOrDummyTarget();
-
- if (!target.GetCollectingStats()) {
+ if (!DebuggerStats::GetCollectingStats()) {
result.AppendError("need to enable statistics before disabling them");
return false;
}
- target.SetCollectingStats(false);
+ DebuggerStats::SetCollectingStats(false);
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
};
+#define LLDB_OPTIONS_statistics_dump
+#include "CommandOptions.inc"
+
class CommandObjectStatsDump : public CommandObjectParsed {
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() { OptionParsingStarting(nullptr); }
+
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override {
+ Status error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'a':
+ m_all_targets = true;
+ break;
+ default:
+ llvm_unreachable("Unimplemented option");
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_all_targets = false;
+ }
+
+ llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+ return llvm::makeArrayRef(g_statistics_dump_options);
+ }
+
+ bool m_all_targets = false;
+ };
+
public:
CommandObjectStatsDump(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "dump", "Dump statistics results",
- nullptr, eCommandProcessMustBePaused) {}
+ : CommandObjectParsed(
+ interpreter, "statistics dump", "Dump metrics in JSON format",
+ "statistics dump [<options>]", eCommandRequiresTarget) {}
~CommandObjectStatsDump() override = default;
+ Options *GetOptions() override { return &m_options; }
+
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- Target &target = GetSelectedOrDummyTarget();
-
- uint32_t i = 0;
- for (auto &stat : target.GetStatistics()) {
- result.AppendMessageWithFormat(
- "%s : %u\n",
- lldb_private::GetStatDescription(
- static_cast<lldb_private::StatisticKind>(i))
- .c_str(),
- stat);
- i += 1;
+ if (m_options.m_all_targets) {
+ result.AppendMessageWithFormatv(
+ "{0:2}", DebuggerStats::ReportStatistics(GetDebugger()));
+ } else {
+ Target &target = m_exe_ctx.GetTargetRef();
+ result.AppendMessageWithFormatv("{0:2}", target.ReportStatistics());
}
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
+
+ CommandOptions m_options;
};
CommandObjectStats::CommandObjectStats(CommandInterpreter &interpreter)
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index b9f8950..3e89eb0 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1305,3 +1305,8 @@ let Command = "trace schema" in {
def trace_schema_verbose : Option<"verbose", "v">, Group<1>,
Desc<"Show verbose trace schema logging for debugging the plug-in.">;
}
+
+let Command = "statistics dump" in {
+ def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+ Desc<"Include statistics for all targets.">;
+}