Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.h
39645 views
//===-- CommandObjectTraceStartIntelPT.h ----------------------*- C++ //-*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H9#define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H1011#include "../../../../source/Commands/CommandObjectTrace.h"12#include "TraceIntelPT.h"13#include "lldb/Interpreter/CommandInterpreter.h"14#include "lldb/Interpreter/CommandReturnObject.h"15#include <optional>1617namespace lldb_private {18namespace trace_intel_pt {1920class CommandObjectThreadTraceStartIntelPT21: public CommandObjectMultipleThreads {22public:23class CommandOptions : public Options {24public:25CommandOptions() : Options() { OptionParsingStarting(nullptr); }2627Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,28ExecutionContext *execution_context) override;2930void OptionParsingStarting(ExecutionContext *execution_context) override;3132llvm::ArrayRef<OptionDefinition> GetDefinitions() override;3334uint64_t m_ipt_trace_size;35bool m_enable_tsc;36std::optional<uint64_t> m_psb_period;37};3839CommandObjectThreadTraceStartIntelPT(TraceIntelPT &trace,40CommandInterpreter &interpreter)41: CommandObjectMultipleThreads(42interpreter, "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>]",49lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |50lldb::eCommandProcessMustBeLaunched |51lldb::eCommandProcessMustBePaused),52m_trace(trace), m_options() {}5354Options *GetOptions() override { return &m_options; }5556protected:57bool DoExecuteOnThreads(Args &command, CommandReturnObject &result,58llvm::ArrayRef<lldb::tid_t> tids) override;5960TraceIntelPT &m_trace;61CommandOptions m_options;62};6364class CommandObjectProcessTraceStartIntelPT : public CommandObjectParsed {65public:66class CommandOptions : public Options {67public:68CommandOptions() : Options() { OptionParsingStarting(nullptr); }6970Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,71ExecutionContext *execution_context) override;7273void OptionParsingStarting(ExecutionContext *execution_context) override;7475llvm::ArrayRef<OptionDefinition> GetDefinitions() override;7677uint64_t m_ipt_trace_size;78uint64_t m_process_buffer_size_limit;79bool m_enable_tsc;80std::optional<uint64_t> m_psb_period;81bool m_per_cpu_tracing;82bool m_disable_cgroup_filtering;83};8485CommandObjectProcessTraceStartIntelPT(TraceIntelPT &trace,86CommandInterpreter &interpreter)87: CommandObjectParsed(88interpreter, "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>]",99lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |100lldb::eCommandProcessMustBeLaunched |101lldb::eCommandProcessMustBePaused),102m_trace(trace), m_options() {}103104Options *GetOptions() override { return &m_options; }105106protected:107void DoExecute(Args &command, CommandReturnObject &result) override;108109TraceIntelPT &m_trace;110CommandOptions m_options;111};112113namespace ParsingUtils {114/// Convert an integral size expression like 12KiB or 4MB into bytes. The units115/// are taken loosely to help users input sizes into LLDB, e.g. KiB and KB are116/// considered the same (2^20 bytes) for simplicity.117///118/// \param[in] size_expression119/// String expression which is an integral number plus a unit that can be120/// 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 is122/// considered bytes.123/// \return124/// The converted number of bytes or \a std::nullopt if the expression is125/// invalid.126std::optional<uint64_t>127ParseUserFriendlySizeExpression(llvm::StringRef size_expression);128} // namespace ParsingUtils129130} // namespace trace_intel_pt131} // namespace lldb_private132133#endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H134135136