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