diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h')
-rw-r--r-- | contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h | 147 |
1 files changed, 96 insertions, 51 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h b/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h index a6ecf6f906b2..09ecbe7da61a 100644 --- a/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h +++ b/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h @@ -9,8 +9,11 @@ #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPT_H #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPT_H -#include "IntelPTDecoder.h" -#include "TraceIntelPTSessionFileParser.h" +#include "TaskTimer.h" +#include "ThreadDecoder.h" +#include "TraceIntelPTMultiCpuDecoder.h" +#include "TraceIntelPTBundleLoader.h" + #include "lldb/Utility/FileSpec.h" #include "lldb/lldb-types.h" #include "llvm/Support/raw_ostream.h" @@ -34,14 +37,13 @@ public: static void Terminate(); - /// Create an instance of this class. + /// Create an instance of this class from a trace bundle. /// - /// \param[in] trace_session_file - /// The contents of the trace session file. See \a Trace::FindPlugin. + /// \param[in] trace_bundle_description + /// The description of the trace bundle. See \a Trace::FindPlugin. /// - /// \param[in] session_file_dir - /// The path to the directory that contains the session file. It's used to - /// resolved relative paths in the session file. + /// \param[in] bundle_dir + /// The path to the directory that contains the trace bundle. /// /// \param[in] debugger /// The debugger instance where new Targets will be created as part of the @@ -50,8 +52,8 @@ public: /// \return /// A trace instance or an error in case of failures. static llvm::Expected<lldb::TraceSP> - CreateInstanceForSessionFile(const llvm::json::Value &trace_session_file, - llvm::StringRef session_file_dir, + CreateInstanceForTraceBundle(const llvm::json::Value &trace_bundle_description, + llvm::StringRef bundle_dir, Debugger &debugger); static llvm::Expected<lldb::TraceSP> @@ -68,14 +70,14 @@ public: llvm::StringRef GetSchema() override; - lldb::TraceCursorUP GetCursor(Thread &thread) override; + llvm::Expected<lldb::TraceCursorUP> CreateNewCursor(Thread &thread) override; void DumpTraceInfo(Thread &thread, Stream &s, bool verbose) override; - llvm::Optional<size_t> GetRawTraceSize(Thread &thread); + llvm::Expected<llvm::Optional<uint64_t>> GetRawTraceSize(Thread &thread); - void DoRefreshLiveProcessState( - llvm::Expected<TraceGetStateResponse> state) override; + llvm::Error DoRefreshLiveProcessState(TraceGetStateResponse state, + llvm::StringRef json_response) override; bool IsTraced(lldb::tid_t tid) override; @@ -83,27 +85,31 @@ public: /// Start tracing a live process. /// - /// \param[in] thread_buffer_size + /// More information on the parameters below can be found in the + /// jLLDBTraceStart section in lldb/docs/lldb-gdb-remote.txt. + /// + /// \param[in] ipt_trace_size /// Trace size per thread in bytes. /// /// \param[in] total_buffer_size_limit /// Maximum total trace size per process in bytes. - /// More information in TraceIntelPT::GetStartConfigurationHelp(). /// /// \param[in] enable_tsc /// Whether to use enable TSC timestamps or not. - /// More information in TraceIntelPT::GetStartConfigurationHelp(). /// /// \param[in] psb_period - /// /// This value defines the period in which PSB packets will be generated. - /// More information in TraceIntelPT::GetStartConfigurationHelp(); + /// + /// \param[in] per_cpu_tracing + /// This value defines whether to have an intel pt trace buffer per thread + /// or per cpu core. /// /// \return /// \a llvm::Error::success if the operation was successful, or /// \a llvm::Error otherwise. - llvm::Error Start(size_t thread_buffer_size, size_t total_buffer_size_limit, - bool enable_tsc, llvm::Optional<size_t> psb_period); + llvm::Error Start(uint64_t ipt_trace_size, uint64_t total_buffer_size_limit, + bool enable_tsc, llvm::Optional<uint64_t> psb_period, + bool m_per_cpu_tracing); /// \copydoc Trace::Start llvm::Error Start(StructuredData::ObjectSP configuration = @@ -111,59 +117,81 @@ public: /// Start tracing live threads. /// + /// More information on the parameters below can be found in the + /// jLLDBTraceStart section in lldb/docs/lldb-gdb-remote.txt. + /// /// \param[in] tids /// Threads to trace. /// - /// \param[in] thread_buffer_size - /// Trace size per thread in bytes. + /// \param[in] ipt_trace_size + /// Trace size per thread or per cpu core in bytes. /// /// \param[in] enable_tsc /// Whether to use enable TSC timestamps or not. - /// More information in TraceIntelPT::GetStartConfigurationHelp(). /// /// \param[in] psb_period - /// /// This value defines the period in which PSB packets will be generated. - /// More information in TraceIntelPT::GetStartConfigurationHelp(). /// /// \return /// \a llvm::Error::success if the operation was successful, or /// \a llvm::Error otherwise. - llvm::Error Start(llvm::ArrayRef<lldb::tid_t> tids, size_t thread_buffer_size, - bool enable_tsc, llvm::Optional<size_t> psb_period); + llvm::Error Start(llvm::ArrayRef<lldb::tid_t> tids, uint64_t ipt_trace_size, + bool enable_tsc, llvm::Optional<uint64_t> psb_period); /// \copydoc Trace::Start llvm::Error Start(llvm::ArrayRef<lldb::tid_t> tids, StructuredData::ObjectSP configuration = StructuredData::ObjectSP()) override; - /// Get the thread buffer content for a live thread - llvm::Expected<std::vector<uint8_t>> GetLiveThreadBuffer(lldb::tid_t tid); + /// See \a Trace::OnThreadBinaryDataRead(). + llvm::Error OnThreadBufferRead(lldb::tid_t tid, + OnBinaryDataReadCallback callback); + /// Get or fetch the cpu information from, for example, /proc/cpuinfo. llvm::Expected<pt_cpu> GetCPUInfo(); - /// Get the current traced live process. - /// + /// Get or fetch the values used to convert to and from TSCs and nanos. + llvm::Optional<LinuxPerfZeroTscConversion> GetPerfZeroTscConversion(); + /// \return - /// The current traced live process. If it's not a live process, - /// return \a nullptr. - Process *GetLiveProcess(); + /// The timer object for this trace. + TaskTimer &GetTimer(); + + TraceIntelPTSP GetSharedPtr(); private: - friend class TraceIntelPTSessionFileParser; + friend class TraceIntelPTBundleLoader; llvm::Expected<pt_cpu> GetCPUInfoForLiveProcess(); + /// Postmortem trace constructor + /// + /// \param[in] bundle_description + /// The definition file for the postmortem bundle. + /// + /// \param[in] traced_processes + /// The processes traced in the live session. + /// /// \param[in] trace_threads - /// ThreadTrace instances, which are not live-processes and whose trace - /// files are fixed. - TraceIntelPT( - const pt_cpu &cpu_info, - const std::vector<lldb::ThreadPostMortemTraceSP> &traced_threads); + /// The threads traced in the live session. They must belong to the + /// processes mentioned above. + /// + /// \return + /// A TraceIntelPT shared pointer instance. + /// \{ + static TraceIntelPTSP CreateInstanceForPostmortemTrace( + JSONTraceBundleDescription &bundle_description, + llvm::ArrayRef<lldb::ProcessSP> traced_processes, + llvm::ArrayRef<lldb::ThreadPostMortemTraceSP> traced_threads); + + /// This constructor is used by CreateInstanceForPostmortemTrace to get the + /// instance ready before using shared pointers, which is a limitation of C++. + TraceIntelPT(JSONTraceBundleDescription &bundle_description, + llvm::ArrayRef<lldb::ProcessSP> traced_processes); + /// \} /// Constructor for live processes - TraceIntelPT(Process &live_process) - : Trace(live_process), m_thread_decoders(){}; + TraceIntelPT(Process &live_process) : Trace(live_process){}; /// Decode the trace of the given thread that, i.e. recontruct the traced /// instructions. @@ -174,15 +202,32 @@ private: /// /// \return /// A \a DecodedThread shared pointer with the decoded instructions. Any - /// errors are embedded in the instruction list. - DecodedThreadSP Decode(Thread &thread); - - /// It is provided by either a session file or a live process' "cpuInfo" - /// binary data. + /// errors are embedded in the instruction list. An \a llvm::Error is + /// returned if the decoder couldn't be properly set up. + llvm::Expected<DecodedThreadSP> Decode(Thread &thread); + + /// We package all the data that can change upon process stops to make sure + /// this contract is very visible. + /// This variable should only be accessed directly by constructores or live + /// process data refreshers. + struct Storage { + llvm::Optional<TraceIntelPTMultiCpuDecoder> multicpu_decoder; + /// These decoders are used for the non-per-cpu case + llvm::DenseMap<lldb::tid_t, std::unique_ptr<ThreadDecoder>> thread_decoders; + /// Helper variable used to track long running operations for telemetry. + TaskTimer task_timer; + /// It is provided by either a trace bundle or a live process to convert TSC + /// counters to and from nanos. It might not be available on all hosts. + llvm::Optional<LinuxPerfZeroTscConversion> tsc_conversion; + } m_storage; + + /// It is provided by either a trace bundle or a live process' "cpuInfo" + /// binary data. We don't put it in the Storage because this variable doesn't + /// change. llvm::Optional<pt_cpu> m_cpu_info; - std::map<lldb::tid_t, std::unique_ptr<ThreadDecoder>> m_thread_decoders; - /// Error gotten after a failed live process update, if any. - llvm::Optional<std::string> m_live_refresh_error; + + /// Get the storage after refreshing the data in the case of a live process. + Storage &GetUpdatedStorage(); }; } // namespace trace_intel_pt |