Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.h
39645 views
//===-- TraceIntelPTMultiCpuDecoder.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_TRACEINTELPTMULTICPUDECODER_H9#define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTMULTICPUDECODER_H1011#include "LibiptDecoder.h"12#include "PerfContextSwitchDecoder.h"13#include "ThreadDecoder.h"14#include "forward-declarations.h"15#include <optional>1617namespace lldb_private {18namespace trace_intel_pt {1920/// Class used to decode a multi-cpu Intel PT trace. It assumes that each21/// thread could have potentially been executed on different cpu cores. It uses22/// a context switch trace per CPU with timestamps to identify which thread owns23/// each Intel PT decoded instruction and in which order. It also assumes that24/// the Intel PT data and context switches might have gaps in their traces due25/// to contention or race conditions. Finally, it assumes that a tid is not26/// repeated twice for two different threads because of the shortness of the27/// intel pt trace.28///29/// This object should be recreated after every stop in the case of live30/// processes.31class TraceIntelPTMultiCpuDecoder {32public:33/// \param[in] TraceIntelPT34/// The trace object to be decoded35TraceIntelPTMultiCpuDecoder(TraceIntelPTSP trace_sp);3637/// \return38/// A \a DecodedThread for the \p thread by decoding its instructions on all39/// CPUs, sorted by TSCs. An \a llvm::Error is returned if the decoder40/// couldn't be properly set up.41llvm::Expected<DecodedThreadSP> Decode(Thread &thread);4243/// \return44/// \b true if the given \p tid is managed by this decoder, regardless of45/// whether there's tracing data associated to it or not.46bool TracesThread(lldb::tid_t tid) const;4748/// \return49/// The number of continuous executions found for the given \p tid.50size_t GetNumContinuousExecutionsForThread(lldb::tid_t tid) const;5152/// \return53/// The number of PSB blocks for a given thread in all cores.54size_t GePSBBlocksCountForThread(lldb::tid_t tid) const;5556/// \return57/// The total number of continuous executions found across CPUs.58size_t GetTotalContinuousExecutionsCount() const;5960/// \return61/// The number of psb blocks in all cores that couldn't be matched with a62/// thread execution coming from context switch traces.63size_t GetUnattributedPSBBlocksCount() const;6465/// \return66/// The total number of PSB blocks in all cores.67size_t GetTotalPSBBlocksCount() const;6869/// \return70/// The lowest TSC value in this trace if available, \a std::nullopt if71/// the trace is empty or the trace contains no timing information, or an72/// \a llvm::Error if it was not possible to set up the decoder.73llvm::Expected<std::optional<uint64_t>> FindLowestTSC();7475private:76/// Traverse the context switch traces and the basic intel pt continuous77/// subtraces and produce a list of continuous executions for each process and78/// thread.79///80/// See \a DoCorrelateContextSwitchesAndIntelPtTraces.81///82/// Any errors are stored in \a m_setup_error.83llvm::Error CorrelateContextSwitchesAndIntelPtTraces();8485/// Produce a mapping from thread ids to the list of continuos executions with86/// their associated intel pt subtraces.87llvm::Expected<88llvm::DenseMap<lldb::tid_t, std::vector<IntelPTThreadContinousExecution>>>89DoCorrelateContextSwitchesAndIntelPtTraces();9091TraceIntelPTSP GetTrace();9293std::weak_ptr<TraceIntelPT> m_trace_wp;94std::set<lldb::tid_t> m_tids;95std::optional<96llvm::DenseMap<lldb::tid_t, std::vector<IntelPTThreadContinousExecution>>>97m_continuous_executions_per_thread;98llvm::DenseMap<lldb::tid_t, DecodedThreadSP> m_decoded_threads;99/// This variable will not be std::nullopt if a severe error happened during100/// the setup of the decoder and we don't want decoding to be reattempted.101std::optional<std::string> m_setup_error;102uint64_t m_unattributed_psb_blocks = 0;103uint64_t m_total_psb_blocks = 0;104};105106} // namespace trace_intel_pt107} // namespace lldb_private108109#endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACEINTELPTMULTICPUDECODER_H110111112