LLDB  mainline
CommandObjectTraceStartIntelPT.h
Go to the documentation of this file.
1 //===-- CommandObjectTraceStartIntelPT.h ----------------------*- 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 #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
10 #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
11 
12 #include "../../../../source/Commands/CommandObjectTrace.h"
13 #include "TraceIntelPT.h"
16 
17 namespace lldb_private {
18 namespace trace_intel_pt {
19 
22 public:
23  class CommandOptions : public Options {
24  public:
26 
27  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
28  ExecutionContext *execution_context) override;
29 
30  void OptionParsingStarting(ExecutionContext *execution_context) override;
31 
32  llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
33 
34  uint64_t m_ipt_trace_size;
36  llvm::Optional<uint64_t> m_psb_period;
37  };
38 
40  CommandInterpreter &interpreter)
42  interpreter, "thread trace start",
43  "Start tracing one or more threads with intel-pt. "
44  "Defaults to the current thread. Thread indices can be "
45  "specified as arguments.\n Use the thread-index \"all\" to trace "
46  "all threads including future threads.",
47  "thread trace start [<thread-index> <thread-index> ...] "
48  "[<intel-pt-options>]",
49  lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
50  lldb::eCommandProcessMustBeLaunched |
51  lldb::eCommandProcessMustBePaused),
52  m_trace(trace), m_options() {}
53 
54  Options *GetOptions() override { return &m_options; }
55 
56 protected:
57  bool DoExecuteOnThreads(Args &command, CommandReturnObject &result,
58  llvm::ArrayRef<lldb::tid_t> tids) override;
59 
62 };
63 
65 public:
66  class CommandOptions : public Options {
67  public:
69 
70  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
71  ExecutionContext *execution_context) override;
72 
73  void OptionParsingStarting(ExecutionContext *execution_context) override;
74 
75  llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
76 
77  uint64_t m_ipt_trace_size;
80  llvm::Optional<uint64_t> m_psb_period;
83  };
84 
86  CommandInterpreter &interpreter)
88  interpreter, "process trace start",
89  "Start tracing this process with intel-pt, including future "
90  "threads. If --per-cpu-tracing is not provided, this traces each "
91  "thread independently, thus using a trace buffer per thread. "
92  "Threads traced with the \"thread trace start\" command are left "
93  "unaffected ant not retraced. This is the recommended option "
94  "unless the number of threads is huge. If --per-cpu-tracing is "
95  "passed, each cpu core is traced instead of each thread, which "
96  "uses a fixed number of trace buffers, but might result in less "
97  "data available for less frequent threads.",
98  "process trace start [<intel-pt-options>]",
99  lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
100  lldb::eCommandProcessMustBeLaunched |
101  lldb::eCommandProcessMustBePaused),
102  m_trace(trace), m_options() {}
103 
104  Options *GetOptions() override { return &m_options; }
105 
106 protected:
107  bool DoExecute(Args &command, CommandReturnObject &result) override;
108 
111 };
112 
113 namespace ParsingUtils {
114 /// Convert an integral size expression like 12KiB or 4MB into bytes. The units
115 /// are taken loosely to help users input sizes into LLDB, e.g. KiB and KB are
116 /// considered the same (2^20 bytes) for simplicity.
117 ///
118 /// \param[in] size_expression
119 /// String expression which is an integral number plus a unit that can be
120 /// lower or upper case. Supported units: K, KB and KiB for 2^10 bytes; M,
121 /// MB and MiB for 2^20 bytes; and B for bytes. A single integral number is
122 /// considered bytes.
123 /// \return
124 /// The converted number of bytes or \a std::nullopt if the expression is
125 /// invalid.
126 llvm::Optional<uint64_t>
127 ParseUserFriendlySizeExpression(llvm::StringRef size_expression);
128 } // namespace ParsingUtils
129 
130 } // namespace trace_intel_pt
131 } // namespace lldb_private
132 
133 #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::m_enable_tsc
bool m_enable_tsc
Definition: CommandObjectTraceStartIntelPT.h:79
lldb_private::CommandObjectParsed
Definition: CommandObject.h:390
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::DoExecuteOnThreads
bool DoExecuteOnThreads(Args &command, CommandReturnObject &result, llvm::ArrayRef< lldb::tid_t > tids) override
Method that handles the command after the main arguments have been parsed.
Definition: CommandObjectTraceStartIntelPT.cpp:75
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectTraceStartIntelPT.cpp:146
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandObjectProcessTraceStartIntelPT
CommandObjectProcessTraceStartIntelPT(TraceIntelPT &trace, CommandInterpreter &interpreter)
Definition: CommandObjectTraceStartIntelPT.h:85
lldb_private::trace_intel_pt::ParsingUtils::ParseUserFriendlySizeExpression
llvm::Optional< uint64_t > ParseUserFriendlySizeExpression(llvm::StringRef size_expression)
Convert an integral size expression like 12KiB or 4MB into bytes.
Definition: CommandObjectTraceStartIntelPT.cpp:174
lldb_private::trace_intel_pt::TraceIntelPT
Definition: TraceIntelPT.h:23
lldb_private::Args
Definition: Args.h:33
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectTraceStartIntelPT.cpp:71
CommandReturnObject.h
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::m_psb_period
llvm::Optional< uint64_t > m_psb_period
Definition: CommandObjectTraceStartIntelPT.h:80
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectTraceStartIntelPT.h:68
lldb_private::Options
Definition: Options.h:57
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::GetOptions
Options * GetOptions() override
Definition: CommandObjectTraceStartIntelPT.h:54
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT
Definition: CommandObjectTraceStartIntelPT.h:20
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions
Definition: CommandObjectTraceStartIntelPT.h:66
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::CommandOptions
CommandOptions()
Definition: CommandObjectTraceStartIntelPT.h:25
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectTraceStartIntelPT.cpp:160
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::m_disable_cgroup_filtering
bool m_disable_cgroup_filtering
Definition: CommandObjectTraceStartIntelPT.h:82
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions
Definition: CommandObjectTraceStartIntelPT.h:23
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::CommandObjectMultipleThreads
Class similar to CommandObjectIterateOverThreads, but which performs an action on multiple threads at...
Definition: CommandObjectThreadUtil.h:81
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: CommandObjectTraceStartIntelPT.cpp:64
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::m_enable_tsc
bool m_enable_tsc
Definition: CommandObjectTraceStartIntelPT.h:35
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::GetOptions
Options * GetOptions() override
Definition: CommandObjectTraceStartIntelPT.h:104
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandObjectThreadTraceStartIntelPT
CommandObjectThreadTraceStartIntelPT(TraceIntelPT &trace, CommandInterpreter &interpreter)
Definition: CommandObjectTraceStartIntelPT.h:39
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::m_trace
TraceIntelPT & m_trace
Definition: CommandObjectTraceStartIntelPT.h:109
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::m_ipt_trace_size
uint64_t m_ipt_trace_size
Definition: CommandObjectTraceStartIntelPT.h:34
lldb_private::Status
Definition: Status.h:44
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::m_process_buffer_size_limit
uint64_t m_process_buffer_size_limit
Definition: CommandObjectTraceStartIntelPT.h:78
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:26
uint32_t
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::m_psb_period
llvm::Optional< uint64_t > m_psb_period
Definition: CommandObjectTraceStartIntelPT.h:36
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::m_options
CommandOptions m_options
Definition: CommandObjectTraceStartIntelPT.h:110
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::m_per_cpu_tracing
bool m_per_cpu_tracing
Definition: CommandObjectTraceStartIntelPT.h:81
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectTraceStartIntelPT.cpp:27
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: CommandObjectTraceStartIntelPT.cpp:156
CommandInterpreter.h
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::SetOptionValue
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Definition: CommandObjectTraceStartIntelPT.cpp:92
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT::CommandOptions::m_ipt_trace_size
uint64_t m_ipt_trace_size
Definition: CommandObjectTraceStartIntelPT.h:77
lldb
Definition: SBAddress.h:15
TraceIntelPT.h
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::m_trace
TraceIntelPT & m_trace
Definition: CommandObjectTraceStartIntelPT.h:60
lldb_private::trace_intel_pt::CommandObjectProcessTraceStartIntelPT
Definition: CommandObjectTraceStartIntelPT.h:64
lldb_private::trace_intel_pt::CommandObjectThreadTraceStartIntelPT::m_options
CommandOptions m_options
Definition: CommandObjectTraceStartIntelPT.h:61