1 //===-- CommandObjectStats.cpp ----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "CommandObjectStats.h"
10 #include "lldb/Interpreter/CommandReturnObject.h"
11 #include "lldb/Target/Target.h"
14 using namespace lldb_private
;
16 class CommandObjectStatsEnable
: public CommandObjectParsed
{
18 CommandObjectStatsEnable(CommandInterpreter
&interpreter
)
19 : CommandObjectParsed(interpreter
, "enable",
20 "Enable statistics collection", nullptr,
21 eCommandProcessMustBePaused
) {}
23 ~CommandObjectStatsEnable() override
= default;
26 bool DoExecute(Args
&command
, CommandReturnObject
&result
) override
{
27 Target
&target
= GetSelectedOrDummyTarget();
29 if (target
.GetCollectingStats()) {
30 result
.AppendError("statistics already enabled");
31 result
.SetStatus(eReturnStatusFailed
);
35 target
.SetCollectingStats(true);
36 result
.SetStatus(eReturnStatusSuccessFinishResult
);
41 class CommandObjectStatsDisable
: public CommandObjectParsed
{
43 CommandObjectStatsDisable(CommandInterpreter
&interpreter
)
44 : CommandObjectParsed(interpreter
, "disable",
45 "Disable statistics collection", nullptr,
46 eCommandProcessMustBePaused
) {}
48 ~CommandObjectStatsDisable() override
= default;
51 bool DoExecute(Args
&command
, CommandReturnObject
&result
) override
{
52 Target
&target
= GetSelectedOrDummyTarget();
54 if (!target
.GetCollectingStats()) {
55 result
.AppendError("need to enable statistics before disabling them");
56 result
.SetStatus(eReturnStatusFailed
);
60 target
.SetCollectingStats(false);
61 result
.SetStatus(eReturnStatusSuccessFinishResult
);
66 class CommandObjectStatsDump
: public CommandObjectParsed
{
68 CommandObjectStatsDump(CommandInterpreter
&interpreter
)
69 : CommandObjectParsed(interpreter
, "dump", "Dump statistics results",
70 nullptr, eCommandProcessMustBePaused
) {}
72 ~CommandObjectStatsDump() override
= default;
75 bool DoExecute(Args
&command
, CommandReturnObject
&result
) override
{
76 Target
&target
= GetSelectedOrDummyTarget();
79 for (auto &stat
: target
.GetStatistics()) {
80 result
.AppendMessageWithFormat(
82 lldb_private::GetStatDescription(
83 static_cast<lldb_private::StatisticKind
>(i
))
88 result
.SetStatus(eReturnStatusSuccessFinishResult
);
93 CommandObjectStats::CommandObjectStats(CommandInterpreter
&interpreter
)
94 : CommandObjectMultiword(interpreter
, "statistics",
95 "Print statistics about a debugging session",
96 "statistics <subcommand> [<subcommand-options>]") {
97 LoadSubCommand("enable",
98 CommandObjectSP(new CommandObjectStatsEnable(interpreter
)));
99 LoadSubCommand("disable",
100 CommandObjectSP(new CommandObjectStatsDisable(interpreter
)));
101 LoadSubCommand("dump",
102 CommandObjectSP(new CommandObjectStatsDump(interpreter
)));
105 CommandObjectStats::~CommandObjectStats() = default;