LLDB mainline
|
#include <TraceCursorIntelPT.h>
Public Member Functions | |
TraceCursorIntelPT (lldb::ThreadSP thread_sp, DecodedThreadSP decoded_thread_sp, const std::optional< LinuxPerfZeroTscConversion > &tsc_conversion, std::optional< uint64_t > beginning_of_time_nanos) | |
bool | Seek (int64_t offset, lldb::TraceCursorSeekType origin) override |
Make the cursor point to an item in the trace based on an origin point and an offset. | |
void | Next () override |
Move the cursor to the next item (instruction or error). | |
bool | HasValue () const override |
llvm::StringRef | GetError () const override |
lldb::addr_t | GetLoadAddress () const override |
lldb::TraceEvent | GetEventType () const override |
lldb::cpu_id_t | GetCPU () const override |
Get the CPU associated with the current trace item. | |
std::optional< uint64_t > | GetHWClock () const override |
Get the last hardware clock value that was emitted before the current trace item. | |
lldb::TraceItemKind | GetItemKind () const override |
Trace item information (instructions, errors and events) | |
bool | GoToId (lldb::user_id_t id) override |
Instruction identifiers: | |
lldb::user_id_t | GetId () const override |
bool | HasId (lldb::user_id_t id) const override |
std::optional< double > | GetWallClockTime () const override |
Get the approximate wall clock time in nanoseconds at which the current trace item was executed. | |
std::optional< std::string > | GetSyncPointMetadata () const override |
Get some metadata associated with a synchronization point event. | |
Public Member Functions inherited from lldb_private::TraceCursor | |
TraceCursor (lldb::ThreadSP thread_sp) | |
Create a cursor that initially points to the end of the trace, i.e. | |
virtual | ~TraceCursor ()=default |
void | SetForwards (bool forwards) |
Set the direction to use in the TraceCursor::Next() method. | |
bool | IsForwards () const |
Check if the direction to use in the TraceCursor::Next() method is forwards. | |
virtual void | Next ()=0 |
Move the cursor to the next item (instruction or error). | |
virtual bool | HasValue () const =0 |
virtual bool | GoToId (lldb::user_id_t id)=0 |
Instruction identifiers: | |
virtual bool | HasId (lldb::user_id_t id) const =0 |
virtual lldb::user_id_t | GetId () const =0 |
virtual bool | Seek (int64_t offset, lldb::TraceCursorSeekType origin)=0 |
Make the cursor point to an item in the trace based on an origin point and an offset. | |
ExecutionContextRef & | GetExecutionContextRef () |
bool | IsError () const |
bool | IsEvent () const |
const char * | GetEventTypeAsString () const |
bool | IsInstruction () const |
Private Member Functions | |
void | ClearTimingRangesIfInvalid () |
Clear the current TSC and nanoseconds ranges if after moving they are not valid anymore. | |
const std::optional< DecodedThread::TSCRange > & | GetTSCRange () const |
Get or calculate the TSC range that includes the current trace item. | |
const std::optional< DecodedThread::NanosecondsRange > & | GetNanosecondsRange () const |
Get or calculate the TSC range that includes the current trace item. | |
Private Attributes | |
DecodedThreadSP | m_decoded_thread_sp |
Storage of the actual instructions. | |
int64_t | m_pos |
Internal instruction index currently pointing at. | |
std::optional< LinuxPerfZeroTscConversion > | m_tsc_conversion |
Timing information and cached values. | |
std::optional< uint64_t > | m_beginning_of_time_nanos |
Lowest nanoseconds timestamp seen in any thread trace, std::nullopt if not available at all. | |
std::optional< DecodedThread::TSCRange > | m_tsc_range |
Range of trace items with the same TSC that includes the current trace item, std::nullopt if not calculated or not available. | |
bool | m_tsc_range_calculated = false |
std::optional< DecodedThread::NanosecondsRange > | m_nanoseconds_range |
Range of trace items with the same non-interpolated timestamps in nanoseconds that includes the current trace item, std::nullopt if not calculated or not available. | |
bool | m_nanoseconds_range_calculated = false |
Additional Inherited Members | |
Static Public Member Functions inherited from lldb_private::TraceCursor | |
static const char * | EventKindToString (lldb::TraceEvent event_kind) |
Protected Attributes inherited from lldb_private::TraceCursor | |
ExecutionContextRef | m_exe_ctx_ref |
bool | m_forwards = false |
Definition at line 18 of file TraceCursorIntelPT.h.
TraceCursorIntelPT::TraceCursorIntelPT | ( | lldb::ThreadSP | thread_sp, |
DecodedThreadSP | decoded_thread_sp, | ||
const std::optional< LinuxPerfZeroTscConversion > & | tsc_conversion, | ||
std::optional< uint64_t > | beginning_of_time_nanos | ||
) |
Definition at line 20 of file TraceCursorIntelPT.cpp.
References lldb::eTraceCursorSeekTypeEnd, and Seek().
|
private |
Clear the current TSC and nanoseconds ranges if after moving they are not valid anymore.
Definition at line 35 of file TraceCursorIntelPT.cpp.
References m_nanoseconds_range, m_nanoseconds_range_calculated, m_pos, m_tsc_range, and m_tsc_range_calculated.
|
overridevirtual |
Get the CPU associated with the current trace item.
This call might not be O(1), so it's suggested to invoke this method whenever an eTraceEventCPUChanged event is fired.
Implements lldb_private::TraceCursor.
Definition at line 120 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
|
overridevirtual |
Implements lldb_private::TraceCursor.
Definition at line 98 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
|
overridevirtual |
Implements lldb_private::TraceCursor.
Definition at line 124 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
|
overridevirtual |
Get the last hardware clock value that was emitted before the current trace item.
This call might not be O(1), so it's suggested to invoke this method whenever an eTraceEventHWClockTick event is fired.
Implements lldb_private::TraceCursor.
Definition at line 106 of file TraceCursorIntelPT.cpp.
References GetTSCRange().
|
overridevirtual |
Implements lldb_private::TraceCursor.
Definition at line 140 of file TraceCursorIntelPT.cpp.
References m_pos.
|
overridevirtual |
Trace item information (instructions, errors and events)
Implements lldb_private::TraceCursor.
Definition at line 94 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
|
overridevirtual |
Implements lldb_private::TraceCursor.
Definition at line 102 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
|
private |
Get or calculate the TSC range that includes the current trace item.
Definition at line 62 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, m_nanoseconds_range, m_nanoseconds_range_calculated, and m_pos.
Referenced by GetWallClockTime().
|
overridevirtual |
Get some metadata associated with a synchronization point event.
As different trace technologies might have different values for this, we return a string for flexibility.
Implements lldb_private::TraceCursor.
Definition at line 142 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
|
private |
Get or calculate the TSC range that includes the current trace item.
Definition at line 53 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, m_pos, m_tsc_range, and m_tsc_range_calculated.
Referenced by GetHWClock().
|
overridevirtual |
Get the approximate wall clock time in nanoseconds at which the current trace item was executed.
Each trace plug-in has a different definition for what time 0 means.
Implements lldb_private::TraceCursor.
Definition at line 112 of file TraceCursorIntelPT.cpp.
References GetNanosecondsRange(), m_beginning_of_time_nanos, m_pos, and m_tsc_conversion.
|
overridevirtual |
Instruction identifiers:
When building complex higher level tools, fast random accesses in the trace might be needed, for which each instruction requires a unique identifier within its thread trace. For example, a tool might want to repeatedly inspect random consecutive portions of a trace. This means that it will need to first move quickly to the beginning of each section and then start its iteration. Given that the number of instructions can be in the order of hundreds of millions, fast random access is necessary.
An example of such a tool could be an inspector of the call graph of a trace, where each call is represented with its start and end instructions. Inspecting all the instructions of a call requires moving to its first instruction and then iterating until the last instruction, which following the pattern explained above.
Instead of using 0-based indices as identifiers, each Trace plug-in can decide the nature of these identifiers and thus no assumptions can be made regarding their ordering and sequentiality. The reason is that an instruction might be encoded by the plug-in in a way that hides its actual 0-based index in the trace, but it's still possible to efficiently find it.
Requirements:
id
.Implements lldb_private::TraceCursor.
Definition at line 128 of file TraceCursorIntelPT.cpp.
References ClearTimingRangesIfInvalid(), HasId(), and m_pos.
|
overridevirtual |
id
. Implements lldb_private::TraceCursor.
Definition at line 136 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp.
Referenced by GoToId().
|
overridevirtual |
Implements lldb_private::TraceCursor.
Definition at line 89 of file TraceCursorIntelPT.cpp.
References m_decoded_thread_sp, and m_pos.
Referenced by Seek().
|
overridevirtual |
Move the cursor to the next item (instruction or error).
Direction: The traversal is done following the current direction of the trace. If it is forwards, the instructions are visited forwards chronologically. Otherwise, the traversal is done in the opposite direction. By default, a cursor moves backwards unless changed with TraceCursor::SetForwards().
Implements lldb_private::TraceCursor.
Definition at line 30 of file TraceCursorIntelPT.cpp.
References ClearTimingRangesIfInvalid(), lldb_private::TraceCursor::IsForwards(), and m_pos.
|
overridevirtual |
Make the cursor point to an item in the trace based on an origin point and an offset.
The resulting position of the trace is origin + offset
If this resulting position would be out of bounds, the trace then points to an invalid item, i.e. calling HasValue() returns false.
[in] | offset | How many items to move forwards (if positive) or backwards (if negative) from the given origin point. For example, if origin is End, then a negative offset would move backward in the trace, but a positive offset would move past the trace to an invalid item. |
[in] | origin | The reference point to use when moving the cursor. |
Implements lldb_private::TraceCursor.
Definition at line 71 of file TraceCursorIntelPT.cpp.
References ClearTimingRangesIfInvalid(), lldb::eTraceCursorSeekTypeBeginning, lldb::eTraceCursorSeekTypeCurrent, lldb::eTraceCursorSeekTypeEnd, HasValue(), m_decoded_thread_sp, and m_pos.
Referenced by TraceCursorIntelPT().
|
private |
Lowest nanoseconds timestamp seen in any thread trace, std::nullopt if not available at all.
Definition at line 77 of file TraceCursorIntelPT.h.
Referenced by GetWallClockTime().
|
private |
Storage of the actual instructions.
Definition at line 66 of file TraceCursorIntelPT.h.
Referenced by GetCPU(), GetError(), GetEventType(), GetItemKind(), GetLoadAddress(), GetNanosecondsRange(), GetSyncPointMetadata(), GetTSCRange(), HasId(), HasValue(), and Seek().
|
mutableprivate |
Range of trace items with the same non-interpolated timestamps in nanoseconds that includes the current trace item, std::nullopt if not calculated or not available.
Definition at line 85 of file TraceCursorIntelPT.h.
Referenced by ClearTimingRangesIfInvalid(), and GetNanosecondsRange().
|
mutableprivate |
Definition at line 86 of file TraceCursorIntelPT.h.
Referenced by ClearTimingRangesIfInvalid(), and GetNanosecondsRange().
|
private |
Internal instruction index currently pointing at.
Definition at line 68 of file TraceCursorIntelPT.h.
Referenced by ClearTimingRangesIfInvalid(), GetCPU(), GetError(), GetEventType(), GetId(), GetItemKind(), GetLoadAddress(), GetNanosecondsRange(), GetSyncPointMetadata(), GetTSCRange(), GetWallClockTime(), GoToId(), HasValue(), Next(), and Seek().
|
private |
Timing information and cached values.
TSC -> nanos conversion utility. std::nullopt if not available at all.
Definition at line 74 of file TraceCursorIntelPT.h.
Referenced by GetWallClockTime().
|
mutableprivate |
Range of trace items with the same TSC that includes the current trace item, std::nullopt if not calculated or not available.
Definition at line 80 of file TraceCursorIntelPT.h.
Referenced by ClearTimingRangesIfInvalid(), and GetTSCRange().
|
mutableprivate |
Definition at line 81 of file TraceCursorIntelPT.h.
Referenced by ClearTimingRangesIfInvalid(), and GetTSCRange().