9#ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_DECODEDTHREAD_H
10#define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_DECODEDTHREAD_H
15#include "llvm/Support/Errc.h"
16#include "llvm/Support/Error.h"
23namespace trace_intel_pt {
43 return llvm::errc::not_supported;
48 void log(llvm::raw_ostream &
OS)
const override;
62class DecodedThread :
public std::enable_shared_from_this<DecodedThread> {
78 bool InRange(uint64_t item_index)
const;
118 bool InRange(uint64_t item_index)
const;
155 const std::optional<LinuxPerfZeroTscConversion> &tsc_conversion);
194 std::optional<DecodedThread::TSCRange>
205 std::optional<DecodedThread::NanosecondsRange>
270 std::variant<std::string, lldb::TraceEvent, lldb::addr_t>;
276 template <
typename Data>
289 std::optional<std::map<uint64_t, TSCRange>::iterator>
m_last_tsc =
297 std::optional<std::map<uint64_t, NanosecondsRange>::iterator>
303 std::map<uint64_t, lldb::cpu_id_t>
m_cpus;
static llvm::raw_ostream & error(Stream &strm)
Class holding the instructions and function call hierarchy obtained from decoding a trace,...
uint64_t m_insn_count
Total number of instructions in the trace.
const EventsStats & GetEventsStats() const
Return an object with statistics of the trace events that happened.
const ErrorStats & GetErrorStats() const
Return an object with statistics of the trace errors that happened.
std::optional< uint64_t > m_last_cpu
This is the chronologically last CPU ID.
std::optional< std::map< uint64_t, TSCRange >::iterator > m_last_tsc
This is the chronologically last TSC that has been added.
lldb::TraceItemKind GetItemKindByIndex(uint64_t item_index) const
std::chrono::milliseconds m_total_decoding_time
Total amount of time spent decoding.
void AppendEvent(lldb::TraceEvent)
Append an event.
std::map< uint64_t, NanosecondsRange > m_nanoseconds
This map contains the non-interpolated nanoseconds timestamps of the decoded trace items.
llvm::StringRef GetErrorByIndex(uint64_t item_index) const
lldb::ThreadSP GetThread()
std::deque< TraceItemStorage > m_item_data
Most of the trace data is stored here.
EventsStats m_events_stats
Statistics of all tracing events.
lldb::addr_t GetInstructionLoadAddress(uint64_t item_index) const
llvm::DenseMap< uint64_t, lldb::addr_t > m_psb_offsets
std::optional< DecodedThread::NanosecondsRange > GetNanosecondsRangeByIndex(uint64_t item_index)
Get a maximal range of trace items that include the given item_index that have the same nanoseconds t...
void AppendError(const IntelPTError &error)
Append a decoding error.
lldb::TraceEvent GetEventByIndex(int item_index) const
void NotifyCPU(lldb::cpu_id_t cpu_id)
Notify this object that a CPU has been seen.
size_t CalculateApproximateMemoryUsage() const
The approximate size in bytes used by this instance, including all the already decoded instructions.
std::optional< LinuxPerfZeroTscConversion > m_tsc_conversion
TSC -> nanos conversion utility.
uint64_t GetTotalInstructionCount() const
ErrorStats m_error_stats
Statistics of all tracing errors.
std::map< uint64_t, lldb::cpu_id_t > m_cpus
std::variant< std::string, lldb::TraceEvent, lldb::addr_t > TraceItemStorage
void NotifySyncPoint(lldb::addr_t psb_offset)
Notify this object that a new PSB has been seen.
std::optional< DecodedThread::TSCRange > GetTSCRangeByIndex(uint64_t item_index) const
Get a maximal range of trace items that include the given item_index that have the same TSC value.
DecodedThread::TraceItemStorage & CreateNewTraceItem(lldb::TraceItemKind kind, Data &&data)
Create a new trace item.
void AppendCustomError(llvm::StringRef error, bool fatal=false)
Append a custom decoding.
lldb::cpu_id_t GetCPUByIndex(uint64_t item_index) const
Get the most recent CPU id before or at the given trace item index.
void NotifyTsc(TSC tsc)
Notify this object that a new tsc has been seen.
lldb::addr_t GetSyncPointOffsetByIndex(uint64_t item_index) const
std::map< uint64_t, TSCRange > m_tscs
This map contains the TSCs of the decoded trace items.
uint64_t GetItemsCount() const
Get the total number of instruction, errors and events from the decoded trace.
lldb::ThreadSP m_thread_sp
When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordin...
std::optional< std::map< uint64_t, NanosecondsRange >::iterator > m_last_nanoseconds
void AppendInstruction(const pt_insn &insn)
Append an instruction.
Class for representing a libipt decoding error.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
int GetLibiptErrorCode() const
#define LLDB_INVALID_ADDRESS
std::shared_ptr< DecodedThread > DecodedThreadSP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Thread > ThreadSP
TraceEvent
Events that might happen during a trace session.
jLLDBTraceGetState gdb-remote packet
void RecordError(int libipt_error_code)
llvm::DenseMap< const char *, uint64_t > libipt_errors
uint64_t other_errors
The following counters are mutually exclusive.
uint64_t GetTotalCount() const
std::unordered_map< lldb::TraceEvent, uint64_t > events_counts
A count for each individual event kind.
void RecordEvent(lldb::TraceEvent event)
A structure that represents a maximal range of trace items associated to the same non-interpolated ti...
NanosecondsRange * next_range
A nullable pointer to the next range.
uint64_t first_item_index
Index of the first trace item in this range.
double GetInterpolatedTime(uint64_t item_index, uint64_t beginning_of_time_nanos, const LinuxPerfZeroTscConversion &tsc_conversion) const
Calculate an interpolated timestamp in nanoseconds for the given item index.
TSC tsc
The corresponding TSC value for this range.
bool InRange(uint64_t item_index) const
uint64_t items_count
Number of trace items in this range.
uint64_t nanos
The nanoseconds value for this range.
A structure that represents a maximal range of trace items associated to the same TSC value.
uint64_t items_count
Number of trace items in this range.
uint64_t first_item_index
Index of the first trace item in this range.
bool InRange(uint64_t item_index) const