LLDB  mainline
CommandObjectStats.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
9 #include "CommandObjectStats.h"
10 #include "lldb/Host/Host.h"
13 #include "lldb/Target/Target.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
19 public:
21  : CommandObjectParsed(interpreter, "enable",
22  "Enable statistics collection", nullptr,
23  eCommandProcessMustBePaused) {}
24 
25  ~CommandObjectStatsEnable() override = default;
26 
27 protected:
28  bool DoExecute(Args &command, CommandReturnObject &result) override {
29  Target *target = GetSelectedOrDummyTarget();
30 
31  if (target->GetCollectingStats()) {
32  result.AppendError("statistics already enabled");
34  return false;
35  }
36 
37  target->SetCollectingStats(true);
39  return true;
40  }
41 };
42 
44 public:
46  : CommandObjectParsed(interpreter, "disable",
47  "Disable statistics collection", nullptr,
48  eCommandProcessMustBePaused) {}
49 
50  ~CommandObjectStatsDisable() override = default;
51 
52 protected:
53  bool DoExecute(Args &command, CommandReturnObject &result) override {
54  Target *target = GetSelectedOrDummyTarget();
55 
56  if (!target->GetCollectingStats()) {
57  result.AppendError("need to enable statistics before disabling them");
59  return false;
60  }
61 
62  target->SetCollectingStats(false);
64  return true;
65  }
66 };
67 
69 public:
71  : CommandObjectParsed(interpreter, "dump", "Dump statistics results",
72  nullptr, eCommandProcessMustBePaused) {}
73 
74  ~CommandObjectStatsDump() override = default;
75 
76 protected:
77  bool DoExecute(Args &command, CommandReturnObject &result) override {
78  Target *target = GetSelectedOrDummyTarget();
79 
80  uint32_t i = 0;
81  for (auto &stat : target->GetStatistics()) {
83  "%s : %u\n",
84  lldb_private::GetStatDescription(static_cast<lldb_private::StatisticKind>(i))
85  .c_str(),
86  stat);
87  i += 1;
88  }
90  return true;
91  }
92 };
93 
94 CommandObjectStats::CommandObjectStats(CommandInterpreter &interpreter)
95  : CommandObjectMultiword(interpreter, "statistics",
96  "Print statistics about a debugging session",
97  "statistics <subcommand> [<subcommand-options>]") {
98  LoadSubCommand("enable",
99  CommandObjectSP(new CommandObjectStatsEnable(interpreter)));
100  LoadSubCommand("disable",
101  CommandObjectSP(new CommandObjectStatsDisable(interpreter)));
102  LoadSubCommand("dump",
103  CommandObjectSP(new CommandObjectStatsDump(interpreter)));
104 }
105 
A command line argument class.
Definition: Args.h:32
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
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:1319
CommandObjectStatsEnable(CommandInterpreter &interpreter)
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
std::vector< uint32_t > GetStatistics()
Definition: Target.h:1331
void void AppendError(llvm::StringRef in_string)
Definition: SBAddress.h:15
bool GetCollectingStats()
Definition: Target.h:1321
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectStatsDump(CommandInterpreter &interpreter)
void SetStatus(lldb::ReturnStatus status)