LLDB mainline
|
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>
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::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. | |
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 timestamp without interpolation. | |
lldb::addr_t | GetInstructionLoadAddress (uint64_t item_index) const |
uint64_t | GetTotalInstructionCount () const |
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. | |
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::TraceItemStorage & | CreateNewTraceItem (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< TraceItemStorage > | m_item_data |
Most of the trace data is stored here. | |
std::map< uint64_t, TSCRange > | m_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, NanosecondsRange > | m_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_t > | m_cpus |
std::optional< uint64_t > | m_last_cpu |
This is the chronologically last CPU ID. | |
llvm::DenseMap< uint64_t, lldb::addr_t > | m_psb_offsets |
std::optional< LinuxPerfZeroTscConversion > | m_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. | |
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.
|
private |
Definition at line 269 of file DecodedThread.h.
using lldb_private::trace_intel_pt::DecodedThread::TSC = uint64_t |
Definition at line 64 of file DecodedThread.h.
DecodedThread::DecodedThread | ( | lldb::ThreadSP | thread_sp, |
const std::optional< LinuxPerfZeroTscConversion > & | tsc_conversion | ||
) |
Definition at line 252 of file DecodedThread.cpp.
void DecodedThread::AppendCustomError | ( | llvm::StringRef | error, |
bool | fatal = false |
||
) |
Append a custom decoding.
[in] | error | The error message. |
[in] | fatal | If 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().
void DecodedThread::AppendError | ( | const IntelPTError & | error | ) |
Append a decoding error.
Definition at line 190 of file DecodedThread.cpp.
References CreateNewTraceItem(), error(), lldb::eTraceItemKindError, m_error_stats, and lldb_private::trace_intel_pt::DecodedThread::ErrorStats::RecordError().
Referenced by PSBBlockDecoder::DecodeInstructionsAndEvents(), and PSBBlockDecoder::ProcessPTEvents().
void DecodedThread::AppendEvent | ( | lldb::TraceEvent | event | ) |
Append an event.
Definition at line 180 of file DecodedThread.cpp.
References CreateNewTraceItem(), lldb::eTraceItemKindEvent, m_events_stats, and lldb_private::trace_intel_pt::DecodedThread::EventsStats::RecordEvent().
Referenced by NotifyCPU(), NotifySyncPoint(), NotifyTsc(), and PSBBlockDecoder::ProcessPTEvents().
void DecodedThread::AppendInstruction | ( | const pt_insn & | insn | ) |
Append an instruction.
Definition at line 185 of file DecodedThread.cpp.
References CreateNewTraceItem(), lldb::eTraceItemKindInstruction, and m_insn_count.
Referenced by PSBBlockDecoder::AppendInstructionAndDetectAnomalies().
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.
|
private |
Create a new trace 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().
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.
[in] | item_index | The trace item index to compare with. |
Definition at line 155 of file DecodedThread.cpp.
References LLDB_INVALID_CPU_ID, and m_cpus.
llvm::StringRef DecodedThread::GetErrorByIndex | ( | uint64_t | item_index | ) | const |
Definition at line 246 of file DecodedThread.cpp.
References m_item_data.
const DecodedThread::ErrorStats & DecodedThread::GetErrorStats | ( | ) | const |
Return an object with statistics of the trace errors that happened.
Definition at line 232 of file DecodedThread.cpp.
References m_error_stats.
lldb::TraceEvent DecodedThread::GetEventByIndex | ( | int | item_index | ) | const |
Definition at line 200 of file DecodedThread.cpp.
References m_item_data.
const DecodedThread::EventsStats & DecodedThread::GetEventsStats | ( | ) | const |
Return an object with statistics of the trace events that happened.
Definition at line 204 of file DecodedThread.cpp.
References m_events_stats.
lldb::addr_t DecodedThread::GetInstructionLoadAddress | ( | uint64_t | item_index | ) | const |
Definition at line 91 of file DecodedThread.cpp.
References m_item_data.
Referenced by PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().
lldb::TraceItemKind DecodedThread::GetItemKindByIndex | ( | uint64_t | item_index | ) | const |
Definition at line 237 of file DecodedThread.cpp.
References lldb::eTraceItemKindError, lldb::eTraceItemKindEvent, lldb::eTraceItemKindInstruction, and m_item_data.
Referenced by PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().
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().
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.
[in] | item_index | The trace item index to compare with. |
Definition at line 169 of file DecodedThread.cpp.
References m_nanoseconds.
lldb::addr_t DecodedThread::GetSyncPointOffsetByIndex | ( | uint64_t | item_index | ) | const |
Definition at line 96 of file DecodedThread.cpp.
References m_psb_offsets.
ThreadSP DecodedThread::GetThread | ( | ) |
Definition at line 100 of file DecodedThread.cpp.
References m_thread_sp.
uint64_t DecodedThread::GetTotalInstructionCount | ( | ) | const |
Definition at line 176 of file DecodedThread.cpp.
References m_insn_count.
Referenced by PSBBlockAnomalyDetector::DetectAnomaly(), and PSBBlockAnomalyDetector::RefreshPacketOffset().
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.
[in] | item_index | The trace item index to compare with. |
Definition at line 161 of file DecodedThread.cpp.
References m_tscs.
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.
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().
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().
|
private |
Definition at line 303 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), GetCPUByIndex(), and NotifyCPU().
|
private |
Statistics of all tracing errors.
Definition at line 314 of file DecodedThread.h.
Referenced by AppendCustomError(), AppendError(), and GetErrorStats().
|
private |
Statistics of all tracing events.
Definition at line 317 of file DecodedThread.h.
Referenced by AppendEvent(), and GetEventsStats().
|
private |
Total number of instructions in the trace.
Definition at line 322 of file DecodedThread.h.
Referenced by AppendInstruction(), and GetTotalInstructionCount().
|
private |
Most of the trace data is stored here.
Definition at line 281 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), CreateNewTraceItem(), GetErrorByIndex(), GetEventByIndex(), GetInstructionLoadAddress(), GetItemKindByIndex(), and GetItemsCount().
|
private |
This is the chronologically last CPU ID.
Definition at line 305 of file DecodedThread.h.
Referenced by NotifyCPU().
|
private |
Definition at line 298 of file DecodedThread.h.
Referenced by CreateNewTraceItem(), and NotifyTsc().
|
private |
This is the chronologically last TSC that has been added.
Definition at line 289 of file DecodedThread.h.
Referenced by CreateNewTraceItem(), and NotifyTsc().
|
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().
|
private |
Definition at line 308 of file DecodedThread.h.
Referenced by GetSyncPointOffsetByIndex(), and NotifySyncPoint().
|
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().
|
private |
Total amount of time spent decoding.
Definition at line 319 of file DecodedThread.h.
|
private |
TSC -> nanos conversion utility.
Definition at line 311 of file DecodedThread.h.
Referenced by NotifyTsc().
|
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().