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"
15#include "lldb/Target/Target.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
21public:
23 : CommandObjectParsed(interpreter, "enable",
24 "Enable statistics collection", nullptr,
25 eCommandProcessMustBePaused) {}
26
27 ~CommandObjectStatsEnable() override = default;
28
29protected:
30 void DoExecute(Args &command, CommandReturnObject &result) override {
32 result.AppendError("statistics already enabled");
33 return;
34 }
35
38 }
39};
40
42public:
44 : CommandObjectParsed(interpreter, "disable",
45 "Disable statistics collection", nullptr,
46 eCommandProcessMustBePaused) {}
47
48 ~CommandObjectStatsDisable() override = default;
49
50protected:
51 void DoExecute(Args &command, CommandReturnObject &result) override {
53 result.AppendError("need to enable statistics before disabling them");
54 return;
55 }
56
59 }
60};
61
62#define LLDB_OPTIONS_statistics_dump
63#include "CommandOptions.inc"
64
66 class CommandOptions : public Options {
67 public:
69
70 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
71 ExecutionContext *execution_context) override {
73 const int short_option = m_getopt_table[option_idx].val;
74
75 switch (short_option) {
76 case 'a':
77 m_all_targets = true;
78 break;
79 case 's':
81 break;
82 case 'f':
84 break;
85 case 'r':
86 if (llvm::Expected<bool> bool_or_error =
87 OptionArgParser::ToBoolean("--targets", option_arg))
88 m_stats_options.SetIncludeTargets(*bool_or_error);
89 else
90 error = bool_or_error.takeError();
91 break;
92 case 'm':
93 if (llvm::Expected<bool> bool_or_error =
94 OptionArgParser::ToBoolean("--modules", option_arg))
95 m_stats_options.SetIncludeModules(*bool_or_error);
96 else
97 error = bool_or_error.takeError();
98 break;
99 case 't':
100 if (llvm::Expected<bool> bool_or_error =
101 OptionArgParser::ToBoolean("--transcript", option_arg))
103 else
104 error = bool_or_error.takeError();
105 break;
106 default:
107 llvm_unreachable("Unimplemented option");
108 }
109 return error;
110 }
111
112 void OptionParsingStarting(ExecutionContext *execution_context) override {
113 m_all_targets = false;
115 }
116
117 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
118 return llvm::ArrayRef(g_statistics_dump_options);
119 }
120
122
123 bool m_all_targets = false;
125 };
126
127public:
130 interpreter, "statistics dump", "Dump metrics in JSON format",
131 "statistics dump [<options>]", eCommandRequiresTarget) {}
132
133 ~CommandObjectStatsDump() override = default;
134
135 Options *GetOptions() override { return &m_options; }
136
137protected:
138 void DoExecute(Args &command, CommandReturnObject &result) override {
139 Target *target = nullptr;
141 target = m_exe_ctx.GetTargetPtr();
142
147 }
148
150};
151
153 : CommandObjectMultiword(interpreter, "statistics",
154 "Print statistics about a debugging session",
155 "statistics <subcommand> [<subcommand-options>]") {
156 LoadSubCommand("enable",
157 CommandObjectSP(new CommandObjectStatsEnable(interpreter)));
158 LoadSubCommand("disable",
160 LoadSubCommand("dump",
161 CommandObjectSP(new CommandObjectStatsDump(interpreter)));
162}
163
static llvm::raw_ostream & error(Stream &strm)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectStatsDisable() override=default
CommandObjectStatsDisable(CommandInterpreter &interpreter)
void OptionParsingStarting(ExecutionContext *execution_context) override
const StatisticsOptions & GetStatisticsOptions()
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
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectStatsDump(CommandInterpreter &interpreter)
CommandObjectStatsEnable(CommandInterpreter &interpreter)
~CommandObjectStatsEnable() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
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:206
static bool GetCollectingStats()
Definition: Statistics.h:207
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target, const lldb_private::StatisticsOptions &options)
Get metrics associated with one or all targets in a debugger in JSON format.
Definition: Statistics.cpp:225
"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:58
std::vector< Option > m_getopt_table
Definition: Options.h:198
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:330
@ eReturnStatusSuccessFinishResult
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)
void SetIncludeTranscript(bool value)
Definition: Statistics.h:160
void SetSummaryOnly(bool value)
Definition: Statistics.h:135
void SetIncludeModules(bool value)
Definition: Statistics.h:151
void SetLoadAllDebugInfo(bool value)
Definition: Statistics.h:138
void SetIncludeTargets(bool value)
Definition: Statistics.h:143