Go to the documentation of this file.
23 return libipt_status < 0;
27 return libipt_status == -pte_eos;
31 return libipt_status == -pte_no_time;
36 IntelPTError::IntelPTError(
int libipt_error_code,
lldb::addr_t address)
37 : m_libipt_error_code(libipt_error_code), m_address(address) {
38 assert(libipt_error_code < 0);
79 Optional<lldb::cpu_id_t>
82 auto it =
m_cpus.upper_bound(insn_index);
85 return prev(it)->second;
133 events_counts[event]++;
139 const Optional<DecodedThread::TscRange> &hint_range)
const {
144 Optional<TscRange> candidate_range;
145 if (insn_index < hint_range->GetStartInstructionIndex())
146 candidate_range = hint_range->Prev();
147 else if (insn_index > hint_range->GetEndInstructionIndex())
148 candidate_range = hint_range->Next();
150 candidate_range = hint_range;
152 if (candidate_range && candidate_range->InRange(insn_index))
153 return candidate_range;
174 return std::make_unique<TraceCursorIntelPT>(
m_thread_sp, shared_from_this());
180 (
sizeof(size_t) +
sizeof(uint64_t)) *
m_timestamps.size() +
186 : m_it(it), m_decoded_thread(&decoded_thread) {
190 ? std::numeric_limits<uint64_t>::max()
191 : next_it->first - 1;
205 return GetStartInstructionIndex() <= insn_index &&
206 insn_index <= GetEndInstructionIndex();
212 if (next_it == m_decoded_thread->m_timestamps.end())
214 return TscRange(next_it, *m_decoded_thread);
218 if (m_it == m_decoded_thread->m_timestamps.begin())
222 return TscRange(prev_it, *m_decoded_thread);
TscRange(std::map< size_t, uint64_t >::const_iterator it, const DecodedThread &decoded_thread)
DecodedThread(lldb::ThreadSP thread_sp)
lldb::TraceCursorUP CreateNewCursor()
Get a new cursor for the decoded thread.
@ eTraceItemKindInstruction
const char * GetErrorByIndex(size_t item_index) const
DecodedThread::TraceItemStorage & CreateNewTraceItem(lldb::TraceItemKind kind)
Create a new trace item.
llvm::Optional< TscRange > Next() const
Get the next range chronologically.
void AppendEvent(lldb::TraceEvent)
Append an event.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
std::map< size_t, uint64_t >::const_iterator m_it
The iterator pointing to the beginning of the range.
int64_t GetItemsCount() const
Get the total number of instruction, errors and events from the decoded trace.
We use a union to optimize the memory usage for the different kinds of trace items.
size_t GetEndInstructionIndex() const
Get the largest instruction index that has this TSC.
lldb::TraceItemKind GetItemKindByIndex(size_t item_index) const
llvm::Optional< TscRange > CalculateTscRange(size_t insn_index, const llvm::Optional< DecodedThread::TscRange > &hint_range) const
Construct the TSC range that covers the given instruction index.
llvm::Optional< uint64_t > m_last_tsc
This is the chronologically last TSC that has been added.
static llvm::raw_ostream & error(Stream &strm)
TraceEvent
Events that might happen during a trace session.
std::vector< TraceItemStorage > m_item_data
Most of the trace data is stored here.
void AppendError(const IntelPTError &error)
Append a decoding error.
llvm::Optional< TscRange > Prev() const
Get the previous range chronologically.
const char * error
The string message of this item if it's an error.
const EventsStats & GetEventsStats() const
Return an object with statistics of the trace events that happened.
void AppendInstruction(const pt_insn &insn)
Append an instruction.
const DecodedThread * m_decoded_thread
size_t GetStartInstructionIndex() const
Get the smallest instruction index that has this TSC.
void NotifyTsc(uint64_t tsc)
Notify this object that a new tsc has been seen.
void RecordTscError(int libipt_error_code)
Record an error decoding a TSC timestamp.
Class for representing a libipt decoding error.
void log(llvm::raw_ostream &OS) const override
lldb::ThreadSP m_thread_sp
When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordin...
lldb::TraceEvent event
The event kind of this item if it's an event.
void RecordEvent(lldb::TraceEvent event)
@ eTraceEventCPUChanged
Event due to CPU change for a thread.
const LibiptErrorsStats & GetTscErrorsStats() const
Return an object with statistics of the TSC decoding errors that happened.
bool InRange(size_t insn_index) const
Check if this TSC range includes the given instruction index.
size_t CalculateApproximateMemoryUsage() const
The approximate size in bytes used by this instance, including all the already decoded instructions.
llvm::Optional< 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::ThreadSP GetThread()
#define LLDB_INVALID_ADDRESS
void NotifyCPU(lldb::cpu_id_t cpu_id)
Notify this object that a CPU has been seen.
size_t m_end_index
The largest instruction index that has this TSC.
std::map< uint64_t, lldb::cpu_id_t > m_cpus
LibiptErrorsStats m_tsc_errors_stats
Statistics of libipt errors when decoding TSCs.
bool IsLibiptError(int libipt_status)
libipt status utils
A class that represents a running process on the host machine.
size_t GetTsc() const
Get the TSC value.
bool IsEndOfStream(int libipt_status)
bool IsTscUnavailable(int libipt_status)
std::vector< uint8_t > m_item_kinds
The TraceItemKind for each trace item encoded as uint8_t.
lldb::addr_t GetInstructionLoadAddress(size_t item_index) const
std::map< uint64_t, uint64_t > m_timestamps
This map contains the TSCs of the decoded instructions.
void AppendCustomError(llvm::StringRef error)
Append a custom decoding.
uint64_t load_address
The load addresses of this item if it's an instruction.
llvm::Optional< uint64_t > m_last_cpu
This is the chronologically last CPU ID.
EventsStats m_events_stats
Statistics of all tracing events.
lldb::TraceEvent GetEventByIndex(int item_index) const