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" 14 #include "lldb/Interpreter/CommandInterpreter.h" 15 #include "lldb/Interpreter/CommandReturnObject.h" 16 17 namespace lldb_private { 18 namespace trace_intel_pt { 19 20 class CommandObjectThreadTraceStartIntelPT 21 : public CommandObjectMultipleThreads { 22 public: 23 class CommandOptions : public Options { 24 public: 25 CommandOptions() : Options() { OptionParsingStarting(nullptr); } 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 size_t m_trace_buffer_size; 35 bool m_enable_tsc; 36 llvm::Optional<size_t> m_psb_period; 37 }; 38 39 CommandObjectThreadTraceStartIntelPT(TraceIntelPT &trace, 40 CommandInterpreter &interpreter) 41 : CommandObjectMultipleThreads( 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 60 TraceIntelPT &m_trace; 61 CommandOptions m_options; 62 }; 63 64 class CommandObjectProcessTraceStartIntelPT : public CommandObjectParsed { 65 public: 66 class CommandOptions : public Options { 67 public: 68 CommandOptions() : Options() { OptionParsingStarting(nullptr); } 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 size_t m_trace_buffer_size; 78 size_t m_process_buffer_size_limit; 79 bool m_enable_tsc; 80 llvm::Optional<size_t> m_psb_period; 81 bool m_per_core_tracing; 82 }; 83 84 CommandObjectProcessTraceStartIntelPT(TraceIntelPT &trace, 85 CommandInterpreter &interpreter) 86 : CommandObjectParsed( 87 interpreter, "process trace start", 88 "Start tracing this process with intel-pt, including future " 89 "threads. If --per-core-tracing is not provided, this traces each " 90 "thread independently, thus using a trace buffer per thread. " 91 "Threads traced with the \"thread trace start\" command are left " 92 "unaffected ant not retraced. This is the recommended option " 93 "unless the number of threads is huge. If --per-core-tracing is " 94 "passed, each cpu core is traced instead of each thread, which " 95 "uses a fixed number of trace buffers, but might result in less " 96 "data available for less frequent threads.", 97 "process trace start [<intel-pt-options>]", 98 lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock | 99 lldb::eCommandProcessMustBeLaunched | 100 lldb::eCommandProcessMustBePaused), 101 m_trace(trace), m_options() {} 102 103 Options *GetOptions() override { return &m_options; } 104 105 protected: 106 bool DoExecute(Args &command, CommandReturnObject &result) override; 107 108 TraceIntelPT &m_trace; 109 CommandOptions m_options; 110 }; 111 112 } // namespace trace_intel_pt 113 } // namespace lldb_private 114 115 #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H 116