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");
31  return false;
32  }
33 
34  target.SetCollectingStats(true);
36  return true;
37  }
38 };
39 
41 public:
43  : CommandObjectParsed(interpreter, "disable",
44  "Disable statistics collection", nullptr,
45  eCommandProcessMustBePaused) {}
46 
47  ~CommandObjectStatsDisable() override = default;
48 
49 protected:
50  bool DoExecute(Args &command, CommandReturnObject &result) override {
51  Target &target = GetSelectedOrDummyTarget();
52 
53  if (!target.GetCollectingStats()) {
54  result.AppendError("need to enable statistics before disabling them");
55  return false;
56  }
57 
58  target.SetCollectingStats(false);
60  return true;
61  }
62 };
63 
65 public:
67  : CommandObjectParsed(interpreter, "dump", "Dump statistics results",
68  nullptr, eCommandProcessMustBePaused) {}
69 
70  ~CommandObjectStatsDump() override = default;
71 
72 protected:
73  bool DoExecute(Args &command, CommandReturnObject &result) override {
74  Target &target = GetSelectedOrDummyTarget();
75 
76  uint32_t i = 0;
77  for (auto &stat : target.GetStatistics()) {
79  "%s : %u\n",
81  static_cast<lldb_private::StatisticKind>(i))
82  .c_str(),
83  stat);
84  i += 1;
85  }
87  return true;
88  }
89 };
90 
91 CommandObjectStats::CommandObjectStats(CommandInterpreter &interpreter)
92  : CommandObjectMultiword(interpreter, "statistics",
93  "Print statistics about a debugging session",
94  "statistics <subcommand> [<subcommand-options>]") {
95  LoadSubCommand("enable",
96  CommandObjectSP(new CommandObjectStatsEnable(interpreter)));
97  LoadSubCommand("disable",
98  CommandObjectSP(new CommandObjectStatsDisable(interpreter)));
99  LoadSubCommand("dump",
100  CommandObjectSP(new CommandObjectStatsDump(interpreter)));
101 }
102 
lldb_private::CommandObjectParsed
Definition: CommandObject.h:378
CommandObjectStatsEnable
Definition: CommandObjectStats.cpp:16
lldb_private::Target::GetCollectingStats
bool GetCollectingStats()
Definition: Target.h:1455
lldb_private::CommandObjectStats::~CommandObjectStats
~CommandObjectStats() override
CommandObjectStatsDisable::CommandObjectStatsDisable
CommandObjectStatsDisable(CommandInterpreter &interpreter)
Definition: CommandObjectStats.cpp:42
lldb_private::Args
Definition: Args.h:33
CommandObjectStatsDisable
Definition: CommandObjectStats.cpp:40
CommandReturnObject.h
lldb_private::Target
Definition: Target.h:445
Target.h
lldb_private::CommandObjectMultiword
Definition: CommandObjectMultiword.h:19
CommandObjectStatsDisable::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectStats.cpp:50
lldb_private::CommandObjectMultiword::LoadSubCommand
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
Definition: CommandObjectMultiword.cpp:68
lldb_private::CommandReturnObject::SetStatus
void SetStatus(lldb::ReturnStatus status)
Definition: CommandReturnObject.cpp:121
CommandObjectStatsDump::CommandObjectStatsDump
CommandObjectStatsDump(CommandInterpreter &interpreter)
Definition: CommandObjectStats.cpp:66
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::StatisticKind
StatisticKind
Definition: lldb-private-enumerations.h:211
lldb_private::GetStatDescription
std::string GetStatDescription(lldb_private::StatisticKind K)
Definition: lldb-private-enumerations.h:220
CommandObjectStatsEnable::CommandObjectStatsEnable
CommandObjectStatsEnable(CommandInterpreter &interpreter)
Definition: CommandObjectStats.cpp:18
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:25
uint32_t
lldb::eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishResult
Definition: lldb-enumerations.h:261
lldb_private::Target::GetStatistics
std::vector< uint32_t > GetStatistics()
Definition: Target.h:1465
lldb_private::CommandReturnObject::AppendMessageWithFormat
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:64
lldb_private::Target::SetCollectingStats
void SetCollectingStats(bool v)
Definition: Target.h:1453
CommandObjectStatsEnable::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectStats.cpp:26
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
CommandObjectStatsDump::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectStats.cpp:73
CommandObjectStats.h
lldb_private::CommandReturnObject::AppendError
void void AppendError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:100
lldb
Definition: SBAddress.h:15
CommandObjectStatsDump
Definition: CommandObjectStats.cpp:64