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

#include <DecodedThread.h>

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

Classes

struct  EventsStats
 
struct  LibiptErrorsStats
 
struct  NanosecondsRange
 A structure that represents a maximal range of trace items associated to the same non-interpolated timestamps in nanoseconds. More...
 
union  TraceItemStorage
 We use a union to optimize the memory usage for the different kinds of trace items. 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 llvm::Optional< LinuxPerfZeroTscConversion > &tsc_conversion)
 
uint64_t GetItemsCount () const
 Get the total number of instruction, errors and events from the decoded trace. More...
 
const char * 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. More...
 
lldb::addr_t GetSyncPointOffsetByIndex (uint64_t item_index) const
 
llvm::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. More...
 
llvm::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. More...
 
lldb::addr_t GetInstructionLoadAddress (uint64_t item_index) const
 
const EventsStatsGetEventsStats () const
 Return an object with statistics of the trace events that happened. More...
 
size_t CalculateApproximateMemoryUsage () const
 The approximate size in bytes used by this instance, including all the already decoded instructions. More...
 
lldb::ThreadSP GetThread ()
 
void NotifyTsc (TSC tsc)
 Notify this object that a new tsc has been seen. More...
 
void NotifyCPU (lldb::cpu_id_t cpu_id)
 Notify this object that a CPU has been seen. More...
 
void NotifySyncPoint (lldb::addr_t psb_offset)
 Notify this object that a new PSB has been seen. More...
 
void AppendError (const IntelPTError &error)
 Append a decoding error. More...
 
void AppendCustomError (llvm::StringRef error)
 Append a custom decoding. More...
 
void AppendEvent (lldb::TraceEvent)
 Append an event. More...
 
void AppendInstruction (const pt_insn &insn)
 Append an instruction. More...
 

Private Member Functions

DecodedThread::TraceItemStorageCreateNewTraceItem (lldb::TraceItemKind kind)
 Create a new trace item. More...
 

Private Attributes

lldb::ThreadSP m_thread_sp
 When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly. More...
 
std::vector< TraceItemStoragem_item_data
 Most of the trace data is stored here. More...
 
std::vector< uint8_t > m_item_kinds
 The TraceItemKind for each trace item encoded as uint8_t. More...
 
std::map< uint64_t, TSCRangem_tscs
 This map contains the TSCs of the decoded trace items. More...
 
llvm::Optional< std::map< uint64_t, TSCRange >::iterator > m_last_tsc
 This is the chronologically last TSC that has been added. More...
 
std::map< uint64_t, NanosecondsRangem_nanoseconds
 This map contains the non-interpolated nanoseconds timestamps of the decoded trace items. More...
 
llvm::Optional< std::map< uint64_t, NanosecondsRange >::iterator > m_last_nanoseconds = llvm::None
 
std::map< uint64_t, lldb::cpu_id_tm_cpus
 
llvm::Optional< uint64_t > m_last_cpu = llvm::None
 This is the chronologically last CPU ID. More...
 
llvm::DenseMap< uint64_t, lldb::addr_tm_psb_offsets
 
llvm::Optional< LinuxPerfZeroTscConversionm_tsc_conversion
 TSC -> nanos conversion utility. More...
 
EventsStats m_events_stats
 Statistics of all tracing events. More...
 
std::chrono::milliseconds m_total_decoding_time {0}
 Total amount of time spent decoding. More...
 

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 60 of file DecodedThread.h.

Member Typedef Documentation

◆ TSC

Definition at line 62 of file DecodedThread.h.

Constructor & Destructor Documentation

◆ DecodedThread()

DecodedThread::DecodedThread ( lldb::ThreadSP  thread_sp,
const llvm::Optional< LinuxPerfZeroTscConversion > &  tsc_conversion 
)

Definition at line 219 of file DecodedThread.cpp.

Member Function Documentation

◆ AppendCustomError()

void DecodedThread::AppendCustomError ( llvm::StringRef  error)

◆ 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 224 of file DecodedThread.cpp.

References m_cpus, m_item_data, m_item_kinds, m_nanoseconds, and m_tscs.

◆ CreateNewTraceItem()

DecodedThread::TraceItemStorage & DecodedThread::CreateNewTraceItem ( lldb::TraceItemKind  kind)
private

Create a new trace item.

Returns
The index of the new item.

Definition at line 102 of file DecodedThread.cpp.

References m_item_data, m_item_kinds, 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 152 of file DecodedThread.cpp.

References LLDB_INVALID_CPU_ID, and m_cpus.

◆ GetErrorByIndex()

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

Definition at line 215 of file DecodedThread.cpp.

References m_item_data.

◆ GetEventByIndex()

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

Definition at line 192 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 201 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 90 of file DecodedThread.cpp.

References m_item_data.

◆ GetItemKindByIndex()

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

Definition at line 211 of file DecodedThread.cpp.

References m_item_kinds.

◆ GetItemsCount()

uint64_t DecodedThread::GetItemsCount ( ) const

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

Definition at line 87 of file DecodedThread.cpp.

References m_item_kinds.

Referenced by NotifyCPU(), NotifySyncPoint(), and NotifyTsc().

◆ GetNanosecondsRangeByIndex()

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 llvm::None if not available.

Definition at line 166 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 95 of file DecodedThread.cpp.

References m_psb_offsets.

◆ GetThread()

ThreadSP DecodedThread::GetThread ( )

Definition at line 99 of file DecodedThread.cpp.

References m_thread_sp.

◆ GetTSCRangeByIndex()

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 llvm::None if not available.

Definition at line 158 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 144 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 112 of file DecodedThread.cpp.

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

◆ 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 117 of file DecodedThread.cpp.

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

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 282 of file DecodedThread.h.

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

◆ m_events_stats

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

Statistics of all tracing events.

Definition at line 293 of file DecodedThread.h.

Referenced by AppendEvent(), and GetEventsStats().

◆ m_item_data

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

Most of the trace data is stored here.

Definition at line 257 of file DecodedThread.h.

Referenced by CalculateApproximateMemoryUsage(), CreateNewTraceItem(), GetErrorByIndex(), GetEventByIndex(), and GetInstructionLoadAddress().

◆ m_item_kinds

std::vector<uint8_t> lldb_private::trace_intel_pt::DecodedThread::m_item_kinds
private

The TraceItemKind for each trace item encoded as uint8_t.

We don't include it in TraceItemStorage to avoid padding.

Definition at line 260 of file DecodedThread.h.

Referenced by CalculateApproximateMemoryUsage(), CreateNewTraceItem(), GetItemKindByIndex(), and GetItemsCount().

◆ m_last_cpu

llvm::Optional<uint64_t> lldb_private::trace_intel_pt::DecodedThread::m_last_cpu = llvm::None
private

This is the chronologically last CPU ID.

Definition at line 284 of file DecodedThread.h.

Referenced by NotifyCPU().

◆ m_last_nanoseconds

llvm::Optional<std::map<uint64_t, NanosecondsRange>::iterator> lldb_private::trace_intel_pt::DecodedThread::m_last_nanoseconds = llvm::None
private

Definition at line 277 of file DecodedThread.h.

Referenced by CreateNewTraceItem(), and NotifyTsc().

◆ m_last_tsc

llvm::Optional<std::map<uint64_t, TSCRange>::iterator> lldb_private::trace_intel_pt::DecodedThread::m_last_tsc
private
Initial value:
=
llvm::None

This is the chronologically last TSC that has been added.

Definition at line 268 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 275 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 287 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 235 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 295 of file DecodedThread.h.

◆ m_tsc_conversion

llvm::Optional<LinuxPerfZeroTscConversion> lldb_private::trace_intel_pt::DecodedThread::m_tsc_conversion
private

TSC -> nanos conversion utility.

Definition at line 290 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 266 of file DecodedThread.h.

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


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