LLDB mainline
CommandObjectStats.cpp
Go to the documentation of this file.
1//===-- CommandObjectStats.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
10#include "lldb/Core/Debugger.h"
14#include "lldb/Target/Target.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
20public:
22 : CommandObjectParsed(interpreter, "enable",
23 "Enable statistics collection", nullptr,
24 eCommandProcessMustBePaused) {}
25
26 ~CommandObjectStatsEnable() override = default;
27
28protected:
29 bool DoExecute(Args &command, CommandReturnObject &result) override {
31 result.AppendError("statistics already enabled");
32 return false;
33 }
34
37 return true;
38 }
39};
40
42public:
44 : CommandObjectParsed(interpreter, "disable",
45 "Disable statistics collection", nullptr,
46 eCommandProcessMustBePaused) {}
47
48 ~CommandObjectStatsDisable() override = default;
49
50protected:
51 bool DoExecute(Args &command, CommandReturnObject &result) override {
53 result.AppendError("need to enable statistics before disabling them");
54 return false;
55 }
56
59 return true;
60 }
61};
62
63#define LLDB_OPTIONS_statistics_dump
64#include "CommandOptions.inc"
65
67 class CommandOptions : public Options {
68 public:
70
71 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
72 ExecutionContext *execution_context) override {
74 const int short_option = m_getopt_table[option_idx].val;
75
76 switch (short_option) {
77 case 'a':
78 m_all_targets = true;
79 break;
80 default:
81 llvm_unreachable("Unimplemented option");
82 }
83 return error;
84 }
85
86 void OptionParsingStarting(ExecutionContext *execution_context) override {
87 m_all_targets = false;
88 }
89
90 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
91 return llvm::ArrayRef(g_statistics_dump_options);
92 }
93
94 bool m_all_targets = false;
95 };
96
97public:
100 interpreter, "statistics dump", "Dump metrics in JSON format",
101 "statistics dump [<options>]", eCommandRequiresTarget) {}
102
103 ~CommandObjectStatsDump() override = default;
104
105 Options *GetOptions() override { return &m_options; }
106
107protected:
108 bool DoExecute(Args &command, CommandReturnObject &result) override {
109 Target *target = nullptr;
111 target = m_exe_ctx.GetTargetPtr();
112
114 "{0:2}", DebuggerStats::ReportStatistics(GetDebugger(), target));
116 return true;
117 }
118
120};
121
123 : CommandObjectMultiword(interpreter, "statistics",
124 "Print statistics about a debugging session",
125 "statistics <subcommand> [<subcommand-options>]") {
126 LoadSubCommand("enable",
127 CommandObjectSP(new CommandObjectStatsEnable(interpreter)));
128 LoadSubCommand("disable",
129 CommandObjectSP(new CommandObjectStatsDisable(interpreter)));
130 LoadSubCommand("dump",
131 CommandObjectSP(new CommandObjectStatsDump(interpreter)));
132}
133
static llvm::raw_ostream & error(Stream &strm)
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectStatsDisable() override=default
CommandObjectStatsDisable(CommandInterpreter &interpreter)
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Options * GetOptions() override
~CommandObjectStatsDump() override=default
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectStatsDump(CommandInterpreter &interpreter)
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectStatsEnable(CommandInterpreter &interpreter)
~CommandObjectStatsEnable() override=default
A command line argument class.
Definition: Args.h:33
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectStats(CommandInterpreter &interpreter)
ExecutionContext m_exe_ctx
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void void AppendMessageWithFormatv(const char *format, Args &&... args)
static void SetCollectingStats(bool enable)
Definition: Statistics.h:161
static bool GetCollectingStats()
Definition: Statistics.h:162
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target)
Get metrics associated with one or all targets in a debugger in JSON format.
Definition: Statistics.cpp:186
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
A command line option parsing protocol class.
Definition: Options.h:57
std::vector< Option > m_getopt_table
Definition: Options.h:197
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
@ eReturnStatusSuccessFinishResult