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 
9 #include "CommandObjectStats.h"
11 #include "lldb/Target/Target.h"
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 
17 public:
19  : CommandObjectParsed(interpreter, "enable",
20  "Enable statistics collection", nullptr,
21  eCommandProcessMustBePaused) {}
22 
23  ~CommandObjectStatsEnable() override = default;
24 
25 protected:
26  bool DoExecute(Args &command, CommandReturnObject &result) override {
27  Target &target = GetSelectedOrDummyTarget();
28 
29  if (target.GetCollectingStats()) {
30  result.AppendError("statistics already enabled");
32  return false;
33  }
34 
35  target.SetCollectingStats(true);
37  return true;
38  }
39 };
40 
42 public:
44  : CommandObjectParsed(interpreter, "disable",
45  "Disable statistics collection", nullptr,
46  eCommandProcessMustBePaused) {}
47 
48  ~CommandObjectStatsDisable() override = default;
49 
50 protected:
51  bool DoExecute(Args &command, CommandReturnObject &result) override {
52  Target &target = GetSelectedOrDummyTarget();
53 
54  if (!target.GetCollectingStats()) {
55  result.AppendError("need to enable statistics before disabling them");
57  return false;
58  }
59 
60  target.SetCollectingStats(false);
62  return true;
63  }
64 };
65 
67 public:
69  : CommandObjectParsed(interpreter, "dump", "Dump statistics results",
70  nullptr, eCommandProcessMustBePaused) {}
71 
72  ~CommandObjectStatsDump() override = default;
73 
74 protected:
75  bool DoExecute(Args &command, CommandReturnObject &result) override {
76  Target &target = GetSelectedOrDummyTarget();
77 
78  uint32_t i = 0;
79  for (auto &stat : target.GetStatistics()) {
81  "%s : %u\n",
83  static_cast<lldb_private::StatisticKind>(i))
84  .c_str(),
85  stat);
86  i += 1;
87  }
89  return true;
90  }
91 };
92 
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)));
103 }
104 
A command line argument class.
Definition: Args.h:33
A class that represents a running process on the host machine.
bool DoExecute(Args &command, CommandReturnObject &result) override
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectStatsDisable(CommandInterpreter &interpreter)
std::string GetStatDescription(lldb_private::StatisticKind K)
void SetCollectingStats(bool v)
Definition: Target.h:1338
CommandObjectStatsEnable(CommandInterpreter &interpreter)
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
std::vector< uint32_t > GetStatistics()
Definition: Target.h:1350
void void AppendError(llvm::StringRef in_string)
Definition: SBAddress.h:15
bool GetCollectingStats()
Definition: Target.h:1340
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectStatsDump(CommandInterpreter &interpreter)
void SetStatus(lldb::ReturnStatus status)