LLDB mainline
TraceCursorIntelPT.h
Go to the documentation of this file.
1//===-- TraceCursorIntelPT.h ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACECURSORINTELPT_H
10#define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACECURSORINTELPT_H
11
12#include "ThreadDecoder.h"
13#include <optional>
14
15namespace lldb_private {
16namespace trace_intel_pt {
17
19public:
21 lldb::ThreadSP thread_sp, DecodedThreadSP decoded_thread_sp,
22 const std::optional<LinuxPerfZeroTscConversion> &tsc_conversion,
23 std::optional<uint64_t> beginning_of_time_nanos);
24
25 bool Seek(int64_t offset, lldb::TraceCursorSeekType origin) override;
26
27 void Next() override;
28
29 bool HasValue() const override;
30
31 llvm::StringRef GetError() const override;
32
33 lldb::addr_t GetLoadAddress() const override;
34
35 lldb::TraceEvent GetEventType() const override;
36
37 lldb::cpu_id_t GetCPU() const override;
38
39 std::optional<uint64_t> GetHWClock() const override;
40
41 lldb::TraceItemKind GetItemKind() const override;
42
43 bool GoToId(lldb::user_id_t id) override;
44
45 lldb::user_id_t GetId() const override;
46
47 bool HasId(lldb::user_id_t id) const override;
48
49 std::optional<double> GetWallClockTime() const override;
50
51 std::optional<std::string> GetSyncPointMetadata() const override;
52
53private:
54 /// Clear the current TSC and nanoseconds ranges if after moving they are not
55 /// valid anymore.
57
58 /// Get or calculate the TSC range that includes the current trace item.
59 const std::optional<DecodedThread::TSCRange> &GetTSCRange() const;
60
61 /// Get or calculate the TSC range that includes the current trace item.
62 const std::optional<DecodedThread::NanosecondsRange> &
63 GetNanosecondsRange() const;
64
65 /// Storage of the actual instructions
67 /// Internal instruction index currently pointing at.
68 int64_t m_pos;
69
70 /// Timing information and cached values.
71 /// \{
72
73 /// TSC -> nanos conversion utility. \a std::nullopt if not available at all.
74 std::optional<LinuxPerfZeroTscConversion> m_tsc_conversion;
75 /// Lowest nanoseconds timestamp seen in any thread trace, \a std::nullopt if
76 /// not available at all.
77 std::optional<uint64_t> m_beginning_of_time_nanos;
78 /// Range of trace items with the same TSC that includes the current trace
79 /// item, \a std::nullopt if not calculated or not available.
80 std::optional<DecodedThread::TSCRange> mutable m_tsc_range;
81 bool mutable m_tsc_range_calculated = false;
82 /// Range of trace items with the same non-interpolated timestamps in
83 /// nanoseconds that includes the current trace item, \a std::nullopt if not
84 /// calculated or not available.
85 std::optional<DecodedThread::NanosecondsRange> mutable m_nanoseconds_range;
86 bool mutable m_nanoseconds_range_calculated = false;
87 /// \}
88};
89
90} // namespace trace_intel_pt
91} // namespace lldb_private
92
93#endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACECURSORINTELPT_H
Class used for iterating over the instructions of a thread's trace, among other kinds of information.
Definition: TraceCursor.h:94
void ClearTimingRangesIfInvalid()
Clear the current TSC and nanoseconds ranges if after moving they are not valid anymore.
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)
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 calc...
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.
const std::optional< DecodedThread::NanosecondsRange > & GetNanosecondsRange() const
Get or calculate the TSC range that includes the current trace item.
lldb::cpu_id_t GetCPU() const override
Get the CPU associated with the current trace item.
void Next() override
Move the cursor to the next item (instruction or error).
std::optional< LinuxPerfZeroTscConversion > m_tsc_conversion
Timing information and cached values.
DecodedThreadSP m_decoded_thread_sp
Storage of the actual instructions.
int64_t m_pos
Internal instruction index currently pointing at.
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::NanosecondsRange > m_nanoseconds_range
Range of trace items with the same non-interpolated timestamps in nanoseconds that includes the curre...
bool GoToId(lldb::user_id_t id) override
Instruction identifiers:
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.
const std::optional< DecodedThread::TSCRange > & GetTSCRange() const
Get or calculate the TSC range that includes the current trace item.
bool HasId(lldb::user_id_t id) const override
std::shared_ptr< DecodedThread > DecodedThreadSP
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:438
TraceEvent
Events that might happen during a trace session.
uint32_t cpu_id_t
Definition: lldb-types.h:89
TraceCursorSeekType
Enum to indicate the reference point when invoking TraceCursor::Seek().
uint64_t user_id_t
Definition: lldb-types.h:80
uint64_t addr_t
Definition: lldb-types.h:79