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" 16bdd1243dSDimitry Andric #include <optional> 17e8d8bef9SDimitry Andric 18e8d8bef9SDimitry Andric namespace lldb_private { 19e8d8bef9SDimitry Andric namespace trace_intel_pt { 20e8d8bef9SDimitry Andric 21fe6060f1SDimitry Andric class CommandObjectThreadTraceStartIntelPT 22fe6060f1SDimitry Andric : public CommandObjectMultipleThreads { 23e8d8bef9SDimitry Andric public: 24e8d8bef9SDimitry Andric class CommandOptions : public Options { 25e8d8bef9SDimitry Andric public: CommandOptions()26e8d8bef9SDimitry Andric CommandOptions() : Options() { OptionParsingStarting(nullptr); } 27e8d8bef9SDimitry Andric 28e8d8bef9SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 29e8d8bef9SDimitry Andric ExecutionContext *execution_context) override; 30e8d8bef9SDimitry Andric 31e8d8bef9SDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override; 32e8d8bef9SDimitry Andric 33e8d8bef9SDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override; 34e8d8bef9SDimitry Andric 3581ad6265SDimitry Andric uint64_t m_ipt_trace_size; 36fe6060f1SDimitry Andric bool m_enable_tsc; 37bdd1243dSDimitry Andric std::optional<uint64_t> m_psb_period; 38e8d8bef9SDimitry Andric }; 39e8d8bef9SDimitry Andric CommandObjectThreadTraceStartIntelPT(TraceIntelPT & trace,CommandInterpreter & interpreter)40fe6060f1SDimitry Andric CommandObjectThreadTraceStartIntelPT(TraceIntelPT &trace, 41fe6060f1SDimitry Andric CommandInterpreter &interpreter) 42fe6060f1SDimitry Andric : CommandObjectMultipleThreads( 43e8d8bef9SDimitry Andric interpreter, "thread trace start", 44e8d8bef9SDimitry Andric "Start tracing one or more threads with intel-pt. " 45e8d8bef9SDimitry Andric "Defaults to the current thread. Thread indices can be " 46e8d8bef9SDimitry Andric "specified as arguments.\n Use the thread-index \"all\" to trace " 47fe6060f1SDimitry Andric "all threads including future threads.", 48e8d8bef9SDimitry Andric "thread trace start [<thread-index> <thread-index> ...] " 49e8d8bef9SDimitry Andric "[<intel-pt-options>]", 50e8d8bef9SDimitry Andric lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock | 51e8d8bef9SDimitry Andric lldb::eCommandProcessMustBeLaunched | 52e8d8bef9SDimitry Andric lldb::eCommandProcessMustBePaused), 53fe6060f1SDimitry Andric m_trace(trace), m_options() {} 54e8d8bef9SDimitry Andric GetOptions()55e8d8bef9SDimitry Andric Options *GetOptions() override { return &m_options; } 56e8d8bef9SDimitry Andric 57e8d8bef9SDimitry Andric protected: 58fe6060f1SDimitry Andric bool DoExecuteOnThreads(Args &command, CommandReturnObject &result, 59fe6060f1SDimitry Andric llvm::ArrayRef<lldb::tid_t> tids) override; 60e8d8bef9SDimitry Andric 61fe6060f1SDimitry Andric TraceIntelPT &m_trace; 62fe6060f1SDimitry Andric CommandOptions m_options; 63fe6060f1SDimitry Andric }; 64fe6060f1SDimitry Andric 65fe6060f1SDimitry Andric class CommandObjectProcessTraceStartIntelPT : public CommandObjectParsed { 66fe6060f1SDimitry Andric public: 67fe6060f1SDimitry Andric class CommandOptions : public Options { 68fe6060f1SDimitry Andric public: CommandOptions()69fe6060f1SDimitry Andric CommandOptions() : Options() { OptionParsingStarting(nullptr); } 70fe6060f1SDimitry Andric 71fe6060f1SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 72fe6060f1SDimitry Andric ExecutionContext *execution_context) override; 73fe6060f1SDimitry Andric 74fe6060f1SDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override; 75fe6060f1SDimitry Andric 76fe6060f1SDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override; 77fe6060f1SDimitry Andric 7881ad6265SDimitry Andric uint64_t m_ipt_trace_size; 7981ad6265SDimitry Andric uint64_t m_process_buffer_size_limit; 80fe6060f1SDimitry Andric bool m_enable_tsc; 81bdd1243dSDimitry Andric std::optional<uint64_t> m_psb_period; 8281ad6265SDimitry Andric bool m_per_cpu_tracing; 83753f127fSDimitry Andric bool m_disable_cgroup_filtering; 84fe6060f1SDimitry Andric }; 85fe6060f1SDimitry Andric CommandObjectProcessTraceStartIntelPT(TraceIntelPT & trace,CommandInterpreter & interpreter)86fe6060f1SDimitry Andric CommandObjectProcessTraceStartIntelPT(TraceIntelPT &trace, 87fe6060f1SDimitry Andric CommandInterpreter &interpreter) 88fe6060f1SDimitry Andric : CommandObjectParsed( 89fe6060f1SDimitry Andric interpreter, "process trace start", 90fe6060f1SDimitry Andric "Start tracing this process with intel-pt, including future " 9181ad6265SDimitry Andric "threads. If --per-cpu-tracing is not provided, this traces each " 9281ad6265SDimitry Andric "thread independently, thus using a trace buffer per thread. " 93fe6060f1SDimitry Andric "Threads traced with the \"thread trace start\" command are left " 9481ad6265SDimitry Andric "unaffected ant not retraced. This is the recommended option " 9581ad6265SDimitry Andric "unless the number of threads is huge. If --per-cpu-tracing is " 9681ad6265SDimitry Andric "passed, each cpu core is traced instead of each thread, which " 9781ad6265SDimitry Andric "uses a fixed number of trace buffers, but might result in less " 9881ad6265SDimitry Andric "data available for less frequent threads.", 99fe6060f1SDimitry Andric "process trace start [<intel-pt-options>]", 100fe6060f1SDimitry Andric lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock | 101fe6060f1SDimitry Andric lldb::eCommandProcessMustBeLaunched | 102fe6060f1SDimitry Andric lldb::eCommandProcessMustBePaused), 103fe6060f1SDimitry Andric m_trace(trace), m_options() {} 104fe6060f1SDimitry Andric GetOptions()105fe6060f1SDimitry Andric Options *GetOptions() override { return &m_options; } 106fe6060f1SDimitry Andric 107fe6060f1SDimitry Andric protected: 108*5f757f3fSDimitry Andric void DoExecute(Args &command, CommandReturnObject &result) override; 109fe6060f1SDimitry Andric 110fe6060f1SDimitry Andric TraceIntelPT &m_trace; 111e8d8bef9SDimitry Andric CommandOptions m_options; 112e8d8bef9SDimitry Andric }; 113e8d8bef9SDimitry Andric 114753f127fSDimitry Andric namespace ParsingUtils { 115753f127fSDimitry Andric /// Convert an integral size expression like 12KiB or 4MB into bytes. The units 116753f127fSDimitry Andric /// are taken loosely to help users input sizes into LLDB, e.g. KiB and KB are 117753f127fSDimitry Andric /// considered the same (2^20 bytes) for simplicity. 118753f127fSDimitry Andric /// 119753f127fSDimitry Andric /// \param[in] size_expression 120753f127fSDimitry Andric /// String expression which is an integral number plus a unit that can be 121753f127fSDimitry Andric /// lower or upper case. Supported units: K, KB and KiB for 2^10 bytes; M, 122753f127fSDimitry Andric /// MB and MiB for 2^20 bytes; and B for bytes. A single integral number is 123753f127fSDimitry Andric /// considered bytes. 124753f127fSDimitry Andric /// \return 125bdd1243dSDimitry Andric /// The converted number of bytes or \a std::nullopt if the expression is 126753f127fSDimitry Andric /// invalid. 127bdd1243dSDimitry Andric std::optional<uint64_t> 128753f127fSDimitry Andric ParseUserFriendlySizeExpression(llvm::StringRef size_expression); 129753f127fSDimitry Andric } // namespace ParsingUtils 130753f127fSDimitry Andric 131e8d8bef9SDimitry Andric } // namespace trace_intel_pt 132e8d8bef9SDimitry Andric } // namespace lldb_private 133e8d8bef9SDimitry Andric 134e8d8bef9SDimitry Andric #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H 135