xref: /llvm-project/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h (revision 4bae706682d5b621884ff2f7014ba4eb8cb636aa)
1b0aa7076SWalter Erquinigo //===-- TraceCursorIntelPT.h ------------------------------------*- C++ -*-===//
2b0aa7076SWalter Erquinigo //
3b0aa7076SWalter Erquinigo // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4b0aa7076SWalter Erquinigo // See https://llvm.org/LICENSE.txt for license information.
5b0aa7076SWalter Erquinigo // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b0aa7076SWalter Erquinigo //
7b0aa7076SWalter Erquinigo //===----------------------------------------------------------------------===//
8b0aa7076SWalter Erquinigo 
9b0aa7076SWalter Erquinigo #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACECURSORINTELPT_H
10b0aa7076SWalter Erquinigo #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACECURSORINTELPT_H
11b0aa7076SWalter Erquinigo 
126423b502SWalter Erquinigo #include "ThreadDecoder.h"
13f190ce62SKazu Hirata #include <optional>
14b0aa7076SWalter Erquinigo 
15b0aa7076SWalter Erquinigo namespace lldb_private {
16b0aa7076SWalter Erquinigo namespace trace_intel_pt {
17b0aa7076SWalter Erquinigo 
18b0aa7076SWalter Erquinigo class TraceCursorIntelPT : public TraceCursor {
19b0aa7076SWalter Erquinigo public:
204f676c25SWalter Erquinigo   TraceCursorIntelPT(
214f676c25SWalter Erquinigo       lldb::ThreadSP thread_sp, DecodedThreadSP decoded_thread_sp,
222fe83274SKazu Hirata       const std::optional<LinuxPerfZeroTscConversion> &tsc_conversion,
232fe83274SKazu Hirata       std::optional<uint64_t> beginning_of_time_nanos);
24b0aa7076SWalter Erquinigo 
25f9b4ea0cSJakob Johnson   bool Seek(int64_t offset, lldb::TraceCursorSeekType origin) override;
26b0aa7076SWalter Erquinigo 
27f91d8281SWalter Erquinigo   void Next() override;
28f91d8281SWalter Erquinigo 
29f91d8281SWalter Erquinigo   bool HasValue() const override;
30b0aa7076SWalter Erquinigo 
31*4bae7066SAlex Langford   llvm::StringRef GetError() const override;
32b0aa7076SWalter Erquinigo 
33a7d6c3efSWalter Erquinigo   lldb::addr_t GetLoadAddress() const override;
34b0aa7076SWalter Erquinigo 
35a7d6c3efSWalter Erquinigo   lldb::TraceEvent GetEventType() const override;
36059f39d2SWalter Erquinigo 
37f9b4ea0cSJakob Johnson   lldb::cpu_id_t GetCPU() const override;
384a843d92SWalter Erquinigo 
392fe83274SKazu Hirata   std::optional<uint64_t> GetHWClock() const override;
404f676c25SWalter Erquinigo 
41a7d6c3efSWalter Erquinigo   lldb::TraceItemKind GetItemKind() const override;
42b0aa7076SWalter Erquinigo 
4305b4bf25SWalter Erquinigo   bool GoToId(lldb::user_id_t id) override;
4405b4bf25SWalter Erquinigo 
4505b4bf25SWalter Erquinigo   lldb::user_id_t GetId() const override;
4605b4bf25SWalter Erquinigo 
47efbfde0dSWalter Erquinigo   bool HasId(lldb::user_id_t id) const override;
48efbfde0dSWalter Erquinigo 
492fe83274SKazu Hirata   std::optional<double> GetWallClockTime() const override;
504f676c25SWalter Erquinigo 
512fe83274SKazu Hirata   std::optional<std::string> GetSyncPointMetadata() const override;
52e17cae07SWalter Erquinigo 
53b0aa7076SWalter Erquinigo private:
544f676c25SWalter Erquinigo   /// Clear the current TSC and nanoseconds ranges if after moving they are not
554f676c25SWalter Erquinigo   /// valid anymore.
564f676c25SWalter Erquinigo   void ClearTimingRangesIfInvalid();
574f676c25SWalter Erquinigo 
584f676c25SWalter Erquinigo   /// Get or calculate the TSC range that includes the current trace item.
592fe83274SKazu Hirata   const std::optional<DecodedThread::TSCRange> &GetTSCRange() const;
604f676c25SWalter Erquinigo 
614f676c25SWalter Erquinigo   /// Get or calculate the TSC range that includes the current trace item.
622fe83274SKazu Hirata   const std::optional<DecodedThread::NanosecondsRange> &
634f676c25SWalter Erquinigo   GetNanosecondsRange() const;
64b0aa7076SWalter Erquinigo 
65b0aa7076SWalter Erquinigo   /// Storage of the actual instructions
66b0aa7076SWalter Erquinigo   DecodedThreadSP m_decoded_thread_sp;
67b0aa7076SWalter Erquinigo   /// Internal instruction index currently pointing at.
68f91d8281SWalter Erquinigo   int64_t m_pos;
694f676c25SWalter Erquinigo 
704f676c25SWalter Erquinigo   /// Timing information and cached values.
714f676c25SWalter Erquinigo   /// \{
724f676c25SWalter Erquinigo 
738b5c302eSKazu Hirata   /// TSC -> nanos conversion utility. \a std::nullopt if not available at all.
742fe83274SKazu Hirata   std::optional<LinuxPerfZeroTscConversion> m_tsc_conversion;
758b5c302eSKazu Hirata   /// Lowest nanoseconds timestamp seen in any thread trace, \a std::nullopt if
768b5c302eSKazu Hirata   /// not available at all.
772fe83274SKazu Hirata   std::optional<uint64_t> m_beginning_of_time_nanos;
784f676c25SWalter Erquinigo   /// Range of trace items with the same TSC that includes the current trace
798b5c302eSKazu Hirata   /// item, \a std::nullopt if not calculated or not available.
802fe83274SKazu Hirata   std::optional<DecodedThread::TSCRange> mutable m_tsc_range;
814f676c25SWalter Erquinigo   bool mutable m_tsc_range_calculated = false;
824f676c25SWalter Erquinigo   /// Range of trace items with the same non-interpolated timestamps in
838b5c302eSKazu Hirata   /// nanoseconds that includes the current trace item, \a std::nullopt if not
844f676c25SWalter Erquinigo   /// calculated or not available.
852fe83274SKazu Hirata   std::optional<DecodedThread::NanosecondsRange> mutable m_nanoseconds_range;
864f676c25SWalter Erquinigo   bool mutable m_nanoseconds_range_calculated = false;
874f676c25SWalter Erquinigo   /// \}
88b0aa7076SWalter Erquinigo };
89b0aa7076SWalter Erquinigo 
90b0aa7076SWalter Erquinigo } // namespace trace_intel_pt
91b0aa7076SWalter Erquinigo } // namespace lldb_private
92b0aa7076SWalter Erquinigo 
93b0aa7076SWalter Erquinigo #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_TRACECURSORINTELPT_H
94