LLDB mainline
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
lldb_private::trace_intel_pt::DecodedThread Class Reference

Class holding the instructions and function call hierarchy obtained from decoding a trace, as well as a position cursor used when reverse debugging the trace. More...

#include <DecodedThread.h>

Inheritance diagram for lldb_private::trace_intel_pt::DecodedThread:
Inheritance graph
[legend]

Classes

struct  ErrorStats
 
struct  EventsStats
 
struct  NanosecondsRange
 A structure that represents a maximal range of trace items associated to the same non-interpolated timestamps in nanoseconds. More...
 
struct  TSCRange
 A structure that represents a maximal range of trace items associated to the same TSC value. More...
 

Public Types

using TSC = uint64_t
 

Public Member Functions

 DecodedThread (lldb::ThreadSP thread_sp, const std::optional< LinuxPerfZeroTscConversion > &tsc_conversion)
 
uint64_t GetItemsCount () const
 Get the total number of instruction, errors and events from the decoded trace.
 
llvm::StringRef GetErrorByIndex (uint64_t item_index) const
 
lldb::TraceItemKind GetItemKindByIndex (uint64_t item_index) const
 
lldb::TraceEvent GetEventByIndex (int item_index) const
 
lldb::cpu_id_t GetCPUByIndex (uint64_t item_index) const
 Get the most recent CPU id before or at the given trace item index.
 
lldb::addr_t GetSyncPointOffsetByIndex (uint64_t item_index) const
 
std::optional< DecodedThread::TSCRangeGetTSCRangeByIndex (uint64_t item_index) const
 Get a maximal range of trace items that include the given item_index that have the same TSC value.
 
std::optional< DecodedThread::NanosecondsRangeGetNanosecondsRangeByIndex (uint64_t item_index)
 Get a maximal range of trace items that include the given item_index that have the same nanoseconds timestamp without interpolation.
 
lldb::addr_t GetInstructionLoadAddress (uint64_t item_index) const
 
uint64_t GetTotalInstructionCount () const
 
const EventsStatsGetEventsStats () const
 Return an object with statistics of the trace events that happened.
 
const ErrorStatsGetErrorStats () const
 Return an object with statistics of the trace errors that happened.
 
size_t CalculateApproximateMemoryUsage () const
 The approximate size in bytes used by this instance, including all the already decoded instructions.
 
lldb::ThreadSP GetThread ()
 
void NotifyTsc (TSC tsc)
 Notify this object that a new tsc has been seen.
 
void NotifyCPU (lldb::cpu_id_t cpu_id)
 Notify this object that a CPU has been seen.
 
void NotifySyncPoint (lldb::addr_t psb_offset)
 Notify this object that a new PSB has been seen.
 
void AppendError (const IntelPTError &error)
 Append a decoding error.
 
void AppendCustomError (llvm::StringRef error, bool fatal=false)
 Append a custom decoding.
 
void AppendEvent (lldb::TraceEvent)
 Append an event.
 
void AppendInstruction (const pt_insn &insn)
 Append an instruction.
 

Private Types

using TraceItemStorage = std::variant< std::string, lldb::TraceEvent, lldb::addr_t >
 

Private Member Functions

template<typename Data >
DecodedThread::TraceItemStorageCreateNewTraceItem (lldb::TraceItemKind kind, Data &&data)
 Create a new trace item.
 

Private Attributes

lldb::ThreadSP m_thread_sp
 When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly.
 
std::deque< TraceItemStoragem_item_data
 Most of the trace data is stored here.
 
std::map< uint64_t, TSCRangem_tscs
 This map contains the TSCs of the decoded trace items.
 
std::optional< std::map< uint64_t, TSCRange >::iterator > m_last_tsc
 This is the chronologically last TSC that has been added.
 
std::map< uint64_t, NanosecondsRangem_nanoseconds
 This map contains the non-interpolated nanoseconds timestamps of the decoded trace items.
 
std::optional< std::map< uint64_t, NanosecondsRange >::iterator > m_last_nanoseconds = std::nullopt
 
std::map< uint64_t, lldb::cpu_id_tm_cpus
 
std::optional< uint64_t > m_last_cpu
 This is the chronologically last CPU ID.
 
llvm::DenseMap< uint64_t, lldb::addr_tm_psb_offsets
 
std::optional< LinuxPerfZeroTscConversionm_tsc_conversion
 TSC -> nanos conversion utility.
 
ErrorStats m_error_stats
 Statistics of all tracing errors.
 
EventsStats m_events_stats
 Statistics of all tracing events.
 
std::chrono::milliseconds m_total_decoding_time {0}
 Total amount of time spent decoding.
 
uint64_t m_insn_count = 0
 Total number of instructions in the trace.
 

Detailed Description

Class holding the instructions and function call hierarchy obtained from decoding a trace, as well as a position cursor used when reverse debugging the trace.

Each decoded thread contains a cursor to the current position the user is stopped at. See Trace::GetCursorPosition for more information.

Definition at line 62 of file DecodedThread.h.

Member Typedef Documentation

◆ TraceItemStorage

Definition at line 269 of file DecodedThread.h.

◆ TSC

Definition at line 64 of file DecodedThread.h.

Constructor & Destructor Documentation

◆ DecodedThread()

DecodedThread::DecodedThread ( lldb::ThreadSP  thread_sp,
const std::optional< LinuxPerfZeroTscConversion > &  tsc_conversion 
)

Definition at line 252 of file DecodedThread.cpp.

Member Function Documentation

◆ AppendCustomError()

void DecodedThread::AppendCustomError ( llvm::StringRef  error,
bool  fatal = false 
)

Append a custom decoding.

Parameters
[in]errorThe error message.
[in]fatalIf true, then the whole decoded thread should be discarded because a fatal anomaly has been found.

Definition at line 195 of file DecodedThread.cpp.

References CreateNewTraceItem(), lldb::eTraceItemKindError, m_error_stats, and lldb_private::trace_intel_pt::DecodedThread::ErrorStats::RecordError().

Referenced by PSBBlockDecoder::AppendInstructionAndDetectAnomalies(), and PSBBlockDecoder::ProcessPTEventTSC().

◆ AppendError()

void DecodedThread::AppendError ( const IntelPTError error)

◆ AppendEvent()

void DecodedThread::AppendEvent ( lldb::TraceEvent  event)

◆ AppendInstruction()

void DecodedThread::AppendInstruction ( const pt_insn &  insn)

◆ CalculateApproximateMemoryUsage()

size_t DecodedThread::CalculateApproximateMemoryUsage ( ) const

The approximate size in bytes used by this instance, including all the already decoded instructions.

Definition at line 257 of file DecodedThread.cpp.

References m_cpus, m_item_data, m_nanoseconds, and m_tscs.

◆ CreateNewTraceItem()

template<typename Data >
DecodedThread::TraceItemStorage & DecodedThread::CreateNewTraceItem ( lldb::TraceItemKind  kind,
Data &&  data 
)
private

Create a new trace item.

Returns
The index of the new item.

Definition at line 104 of file DecodedThread.cpp.

References m_item_data, m_last_nanoseconds, and m_last_tsc.

Referenced by AppendCustomError(), AppendError(), AppendEvent(), and AppendInstruction().

◆ GetCPUByIndex()

lldb::cpu_id_t DecodedThread::GetCPUByIndex ( uint64_t  item_index) const

Get the most recent CPU id before or at the given trace item index.

Parameters
[in]item_indexThe trace item index to compare with.
Returns
The requested cpu id, or LLDB_INVALID_CPU_ID if not available.

Definition at line 155 of file DecodedThread.cpp.

References LLDB_INVALID_CPU_ID, and m_cpus.

◆ GetErrorByIndex()

llvm::StringRef DecodedThread::GetErrorByIndex ( uint64_t  item_index) const
Returns
The error associated with a given trace item.

Definition at line 246 of file DecodedThread.cpp.

References m_item_data.

◆ GetErrorStats()

const DecodedThread::ErrorStats & DecodedThread::GetErrorStats ( ) const

Return an object with statistics of the trace errors that happened.

Returns
The stats object of all the events.

Definition at line 232 of file DecodedThread.cpp.

References m_error_stats.

◆ GetEventByIndex()

lldb::TraceEvent DecodedThread::GetEventByIndex ( int  item_index) const
Returns
The underlying event type for the given trace item index.

Definition at line 200 of file DecodedThread.cpp.

References m_item_data.

◆ GetEventsStats()

const DecodedThread::EventsStats & DecodedThread::GetEventsStats ( ) const

Return an object with statistics of the trace events that happened.

Returns
The stats object of all the events.

Definition at line 204 of file DecodedThread.cpp.

References m_events_stats.

◆ GetInstructionLoadAddress()

lldb::addr_t DecodedThread::GetInstructionLoadAddress ( uint64_t  item_index) const
Returns
The load address of the instruction at the given index.

Definition at line 91 of file DecodedThread.cpp.

References m_item_data.

Referenced by PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().

◆ GetItemKindByIndex()

lldb::TraceItemKind DecodedThread::GetItemKindByIndex ( uint64_t  item_index) const
Returns
The trace item kind given an item index.

Definition at line 237 of file DecodedThread.cpp.

References lldb::eTraceItemKindError, lldb::eTraceItemKindEvent, lldb::eTraceItemKindInstruction, and m_item_data.

Referenced by PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().

◆ GetItemsCount()

uint64_t DecodedThread::GetItemsCount ( ) const

Get the total number of instruction, errors and events from the decoded trace.

Definition at line 88 of file DecodedThread.cpp.

References m_item_data.

Referenced by NotifyCPU(), NotifySyncPoint(), NotifyTsc(), and PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().

◆ GetNanosecondsRangeByIndex()

std::optional< DecodedThread::NanosecondsRange > DecodedThread::GetNanosecondsRangeByIndex ( uint64_t  item_index)

Get a maximal range of trace items that include the given item_index that have the same nanoseconds timestamp without interpolation.

Parameters
[in]item_indexThe trace item index to compare with.
Returns
The requested nanoseconds range, or std::nullopt if not available.

Definition at line 169 of file DecodedThread.cpp.

References m_nanoseconds.

◆ GetSyncPointOffsetByIndex()

lldb::addr_t DecodedThread::GetSyncPointOffsetByIndex ( uint64_t  item_index) const
Returns
The PSB offset associated with the given item index.

Definition at line 96 of file DecodedThread.cpp.

References m_psb_offsets.

◆ GetThread()

ThreadSP DecodedThread::GetThread ( )

Definition at line 100 of file DecodedThread.cpp.

References m_thread_sp.

◆ GetTotalInstructionCount()

uint64_t DecodedThread::GetTotalInstructionCount ( ) const
Returns
The number of instructions in this trace (not trace items).

Definition at line 176 of file DecodedThread.cpp.

References m_insn_count.

Referenced by PSBBlockAnomalyDetector::DetectAnomaly(), and PSBBlockAnomalyDetector::RefreshPacketOffset().

◆ GetTSCRangeByIndex()

std::optional< DecodedThread::TSCRange > DecodedThread::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.

Parameters
[in]item_indexThe trace item index to compare with.
Returns
The requested TSC range, or std::nullopt if not available.

Definition at line 161 of file DecodedThread.cpp.

References m_tscs.

◆ NotifyCPU()

void DecodedThread::NotifyCPU ( lldb::cpu_id_t  cpu_id)

Notify this object that a CPU has been seen.

If this a new CPU, an event will be created.

Definition at line 147 of file DecodedThread.cpp.

References AppendEvent(), lldb::eTraceEventCPUChanged, GetItemsCount(), m_cpus, and m_last_cpu.

◆ NotifySyncPoint()

void DecodedThread::NotifySyncPoint ( lldb::addr_t  psb_offset)

Notify this object that a new PSB has been seen.

Definition at line 115 of file DecodedThread.cpp.

References AppendEvent(), lldb::eTraceEventSyncPoint, GetItemsCount(), and m_psb_offsets.

Referenced by PSBBlockDecoder::DecodePSBBlock().

◆ NotifyTsc()

void DecodedThread::NotifyTsc ( TSC  tsc)

Notify this object that a new tsc has been seen.

If this a new TSC, an event will be created.

Definition at line 120 of file DecodedThread.cpp.

References AppendEvent(), lldb::eTraceEventHWClockTick, GetItemsCount(), m_last_nanoseconds, m_last_tsc, m_nanoseconds, m_tsc_conversion, and m_tscs.

Referenced by PSBBlockDecoder::DecodePSBBlock(), and PSBBlockDecoder::ProcessPTEventTSC().

Member Data Documentation

◆ m_cpus

std::map<uint64_t, lldb::cpu_id_t> lldb_private::trace_intel_pt::DecodedThread::m_cpus
private

Definition at line 303 of file DecodedThread.h.

Referenced by CalculateApproximateMemoryUsage(), GetCPUByIndex(), and NotifyCPU().

◆ m_error_stats

ErrorStats lldb_private::trace_intel_pt::DecodedThread::m_error_stats
private

Statistics of all tracing errors.

Definition at line 314 of file DecodedThread.h.

Referenced by AppendCustomError(), AppendError(), and GetErrorStats().

◆ m_events_stats

EventsStats lldb_private::trace_intel_pt::DecodedThread::m_events_stats
private

Statistics of all tracing events.

Definition at line 317 of file DecodedThread.h.

Referenced by AppendEvent(), and GetEventsStats().

◆ m_insn_count

uint64_t lldb_private::trace_intel_pt::DecodedThread::m_insn_count = 0
private

Total number of instructions in the trace.

Definition at line 322 of file DecodedThread.h.

Referenced by AppendInstruction(), and GetTotalInstructionCount().

◆ m_item_data

std::deque<TraceItemStorage> lldb_private::trace_intel_pt::DecodedThread::m_item_data
private

◆ m_last_cpu

std::optional<uint64_t> lldb_private::trace_intel_pt::DecodedThread::m_last_cpu
private

This is the chronologically last CPU ID.

Definition at line 305 of file DecodedThread.h.

Referenced by NotifyCPU().

◆ m_last_nanoseconds

std::optional<std::map<uint64_t, NanosecondsRange>::iterator> lldb_private::trace_intel_pt::DecodedThread::m_last_nanoseconds = std::nullopt
private

Definition at line 298 of file DecodedThread.h.

Referenced by CreateNewTraceItem(), and NotifyTsc().

◆ m_last_tsc

std::optional<std::map<uint64_t, TSCRange>::iterator> lldb_private::trace_intel_pt::DecodedThread::m_last_tsc
private
Initial value:
=
std::nullopt

This is the chronologically last TSC that has been added.

Definition at line 289 of file DecodedThread.h.

Referenced by CreateNewTraceItem(), and NotifyTsc().

◆ m_nanoseconds

std::map<uint64_t, NanosecondsRange> lldb_private::trace_intel_pt::DecodedThread::m_nanoseconds
private

This map contains the non-interpolated nanoseconds timestamps of the decoded trace items.

It maps item index -> nanoseconds, where item index is the first index at which the mapped nanoseconds first appears. We use this representation because timestamps are sporadic and we think of them as ranges.

Definition at line 296 of file DecodedThread.h.

Referenced by CalculateApproximateMemoryUsage(), GetNanosecondsRangeByIndex(), and NotifyTsc().

◆ m_psb_offsets

llvm::DenseMap<uint64_t, lldb::addr_t> lldb_private::trace_intel_pt::DecodedThread::m_psb_offsets
private

Definition at line 308 of file DecodedThread.h.

Referenced by GetSyncPointOffsetByIndex(), and NotifySyncPoint().

◆ m_thread_sp

lldb::ThreadSP lldb_private::trace_intel_pt::DecodedThread::m_thread_sp
private

When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly.

Definition at line 267 of file DecodedThread.h.

Referenced by GetThread().

◆ m_total_decoding_time

std::chrono::milliseconds lldb_private::trace_intel_pt::DecodedThread::m_total_decoding_time {0}
private

Total amount of time spent decoding.

Definition at line 319 of file DecodedThread.h.

◆ m_tsc_conversion

std::optional<LinuxPerfZeroTscConversion> lldb_private::trace_intel_pt::DecodedThread::m_tsc_conversion
private

TSC -> nanos conversion utility.

Definition at line 311 of file DecodedThread.h.

Referenced by NotifyTsc().

◆ m_tscs

std::map<uint64_t, TSCRange> lldb_private::trace_intel_pt::DecodedThread::m_tscs
private

This map contains the TSCs of the decoded trace items.

It maps item index -> TSC, where item index is the first index at which the mapped TSC first appears. We use this representation because TSCs are sporadic and we can think of them as ranges.

Definition at line 287 of file DecodedThread.h.

Referenced by CalculateApproximateMemoryUsage(), GetTSCRangeByIndex(), and NotifyTsc().


The documentation for this class was generated from the following files: