xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1e8d8bef9SDimitry Andric //===-- CommandObjectTraceStartIntelPT.h ----------------------*- C++ //-*-===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric 
9e8d8bef9SDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
10e8d8bef9SDimitry Andric #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
11e8d8bef9SDimitry Andric 
12fe6060f1SDimitry Andric #include "../../../../source/Commands/CommandObjectTrace.h"
13fe6060f1SDimitry Andric #include "TraceIntelPT.h"
14e8d8bef9SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
15e8d8bef9SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
16e8d8bef9SDimitry Andric 
17e8d8bef9SDimitry Andric namespace lldb_private {
18e8d8bef9SDimitry Andric namespace trace_intel_pt {
19e8d8bef9SDimitry Andric 
20fe6060f1SDimitry Andric class CommandObjectThreadTraceStartIntelPT
21fe6060f1SDimitry Andric     : public CommandObjectMultipleThreads {
22e8d8bef9SDimitry Andric public:
23e8d8bef9SDimitry Andric   class CommandOptions : public Options {
24e8d8bef9SDimitry Andric   public:
25e8d8bef9SDimitry Andric     CommandOptions() : Options() { OptionParsingStarting(nullptr); }
26e8d8bef9SDimitry Andric 
27e8d8bef9SDimitry Andric     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
28e8d8bef9SDimitry Andric                           ExecutionContext *execution_context) override;
29e8d8bef9SDimitry Andric 
30e8d8bef9SDimitry Andric     void OptionParsingStarting(ExecutionContext *execution_context) override;
31e8d8bef9SDimitry Andric 
32e8d8bef9SDimitry Andric     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
33e8d8bef9SDimitry Andric 
34*81ad6265SDimitry Andric     uint64_t m_ipt_trace_size;
35fe6060f1SDimitry Andric     bool m_enable_tsc;
36*81ad6265SDimitry Andric     llvm::Optional<uint64_t> m_psb_period;
37e8d8bef9SDimitry Andric   };
38e8d8bef9SDimitry Andric 
39fe6060f1SDimitry Andric   CommandObjectThreadTraceStartIntelPT(TraceIntelPT &trace,
40fe6060f1SDimitry Andric                                        CommandInterpreter &interpreter)
41fe6060f1SDimitry Andric       : CommandObjectMultipleThreads(
42e8d8bef9SDimitry Andric             interpreter, "thread trace start",
43e8d8bef9SDimitry Andric             "Start tracing one or more threads with intel-pt. "
44e8d8bef9SDimitry Andric             "Defaults to the current thread. Thread indices can be "
45e8d8bef9SDimitry Andric             "specified as arguments.\n Use the thread-index \"all\" to trace "
46fe6060f1SDimitry Andric             "all threads including future threads.",
47e8d8bef9SDimitry Andric             "thread trace start [<thread-index> <thread-index> ...] "
48e8d8bef9SDimitry Andric             "[<intel-pt-options>]",
49e8d8bef9SDimitry Andric             lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
50e8d8bef9SDimitry Andric                 lldb::eCommandProcessMustBeLaunched |
51e8d8bef9SDimitry Andric                 lldb::eCommandProcessMustBePaused),
52fe6060f1SDimitry Andric         m_trace(trace), m_options() {}
53e8d8bef9SDimitry Andric 
54e8d8bef9SDimitry Andric   Options *GetOptions() override { return &m_options; }
55e8d8bef9SDimitry Andric 
56e8d8bef9SDimitry Andric protected:
57fe6060f1SDimitry Andric   bool DoExecuteOnThreads(Args &command, CommandReturnObject &result,
58fe6060f1SDimitry Andric                           llvm::ArrayRef<lldb::tid_t> tids) override;
59e8d8bef9SDimitry Andric 
60fe6060f1SDimitry Andric   TraceIntelPT &m_trace;
61fe6060f1SDimitry Andric   CommandOptions m_options;
62fe6060f1SDimitry Andric };
63fe6060f1SDimitry Andric 
64fe6060f1SDimitry Andric class CommandObjectProcessTraceStartIntelPT : public CommandObjectParsed {
65fe6060f1SDimitry Andric public:
66fe6060f1SDimitry Andric   class CommandOptions : public Options {
67fe6060f1SDimitry Andric   public:
68fe6060f1SDimitry Andric     CommandOptions() : Options() { OptionParsingStarting(nullptr); }
69fe6060f1SDimitry Andric 
70fe6060f1SDimitry Andric     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
71fe6060f1SDimitry Andric                           ExecutionContext *execution_context) override;
72fe6060f1SDimitry Andric 
73fe6060f1SDimitry Andric     void OptionParsingStarting(ExecutionContext *execution_context) override;
74fe6060f1SDimitry Andric 
75fe6060f1SDimitry Andric     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
76fe6060f1SDimitry Andric 
77*81ad6265SDimitry Andric     uint64_t m_ipt_trace_size;
78*81ad6265SDimitry Andric     uint64_t m_process_buffer_size_limit;
79fe6060f1SDimitry Andric     bool m_enable_tsc;
80*81ad6265SDimitry Andric     llvm::Optional<uint64_t> m_psb_period;
81*81ad6265SDimitry Andric     bool m_per_cpu_tracing;
82fe6060f1SDimitry Andric   };
83fe6060f1SDimitry Andric 
84fe6060f1SDimitry Andric   CommandObjectProcessTraceStartIntelPT(TraceIntelPT &trace,
85fe6060f1SDimitry Andric                                         CommandInterpreter &interpreter)
86fe6060f1SDimitry Andric       : CommandObjectParsed(
87fe6060f1SDimitry Andric             interpreter, "process trace start",
88fe6060f1SDimitry Andric             "Start tracing this process with intel-pt, including future "
89*81ad6265SDimitry Andric             "threads. If --per-cpu-tracing is not provided, this traces each "
90*81ad6265SDimitry Andric             "thread independently, thus using a trace buffer per thread. "
91fe6060f1SDimitry Andric             "Threads traced with the \"thread trace start\" command are left "
92*81ad6265SDimitry Andric             "unaffected ant not retraced. This is the recommended option "
93*81ad6265SDimitry Andric             "unless the number of threads is huge. If --per-cpu-tracing is "
94*81ad6265SDimitry Andric             "passed, each cpu core is traced instead of each thread, which "
95*81ad6265SDimitry Andric             "uses a fixed number of trace buffers, but might result in less "
96*81ad6265SDimitry Andric             "data available for less frequent threads.",
97fe6060f1SDimitry Andric             "process trace start [<intel-pt-options>]",
98fe6060f1SDimitry Andric             lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
99fe6060f1SDimitry Andric                 lldb::eCommandProcessMustBeLaunched |
100fe6060f1SDimitry Andric                 lldb::eCommandProcessMustBePaused),
101fe6060f1SDimitry Andric         m_trace(trace), m_options() {}
102fe6060f1SDimitry Andric 
103fe6060f1SDimitry Andric   Options *GetOptions() override { return &m_options; }
104fe6060f1SDimitry Andric 
105fe6060f1SDimitry Andric protected:
106fe6060f1SDimitry Andric   bool DoExecute(Args &command, CommandReturnObject &result) override;
107fe6060f1SDimitry Andric 
108fe6060f1SDimitry Andric   TraceIntelPT &m_trace;
109e8d8bef9SDimitry Andric   CommandOptions m_options;
110e8d8bef9SDimitry Andric };
111e8d8bef9SDimitry Andric 
112e8d8bef9SDimitry Andric } // namespace trace_intel_pt
113e8d8bef9SDimitry Andric } // namespace lldb_private
114e8d8bef9SDimitry Andric 
115e8d8bef9SDimitry Andric #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
116