[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / Commands / CommandObjectStats.cpp
blobeeec4a8d3e77e5ee80fc6b5940a3313ebda8c700
1 //===-- CommandObjectStats.cpp ----------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "CommandObjectStats.h"
10 #include "lldb/Interpreter/CommandReturnObject.h"
11 #include "lldb/Target/Target.h"
13 using namespace lldb;
14 using namespace lldb_private;
16 class CommandObjectStatsEnable : public CommandObjectParsed {
17 public:
18 CommandObjectStatsEnable(CommandInterpreter &interpreter)
19 : CommandObjectParsed(interpreter, "enable",
20 "Enable statistics collection", nullptr,
21 eCommandProcessMustBePaused) {}
23 ~CommandObjectStatsEnable() override = default;
25 protected:
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);
32 return false;
35 target.SetCollectingStats(true);
36 result.SetStatus(eReturnStatusSuccessFinishResult);
37 return true;
41 class CommandObjectStatsDisable : public CommandObjectParsed {
42 public:
43 CommandObjectStatsDisable(CommandInterpreter &interpreter)
44 : CommandObjectParsed(interpreter, "disable",
45 "Disable statistics collection", nullptr,
46 eCommandProcessMustBePaused) {}
48 ~CommandObjectStatsDisable() override = default;
50 protected:
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);
57 return false;
60 target.SetCollectingStats(false);
61 result.SetStatus(eReturnStatusSuccessFinishResult);
62 return true;
66 class CommandObjectStatsDump : public CommandObjectParsed {
67 public:
68 CommandObjectStatsDump(CommandInterpreter &interpreter)
69 : CommandObjectParsed(interpreter, "dump", "Dump statistics results",
70 nullptr, eCommandProcessMustBePaused) {}
72 ~CommandObjectStatsDump() override = default;
74 protected:
75 bool DoExecute(Args &command, CommandReturnObject &result) override {
76 Target &target = GetSelectedOrDummyTarget();
78 uint32_t i = 0;
79 for (auto &stat : target.GetStatistics()) {
80 result.AppendMessageWithFormat(
81 "%s : %u\n",
82 lldb_private::GetStatDescription(
83 static_cast<lldb_private::StatisticKind>(i))
84 .c_str(),
85 stat);
86 i += 1;
88 result.SetStatus(eReturnStatusSuccessFinishResult);
89 return true;
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;