16423b502SWalter Erquinigo //===-- ThreadDecoder.h --======---------------------------------*- C++ -*-===// 26423b502SWalter Erquinigo // 36423b502SWalter Erquinigo // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 46423b502SWalter Erquinigo // See https://llvm.org/LICENSE.txt for license information. 56423b502SWalter Erquinigo // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 66423b502SWalter Erquinigo // 76423b502SWalter Erquinigo //===----------------------------------------------------------------------===// 86423b502SWalter Erquinigo 96423b502SWalter Erquinigo #ifndef LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H 106423b502SWalter Erquinigo #define LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H 116423b502SWalter Erquinigo 126423b502SWalter Erquinigo #include "DecodedThread.h" 136423b502SWalter Erquinigo #include "forward-declarations.h" 14c4fb631cSWalter Erquinigo #include "intel-pt.h" 156423b502SWalter Erquinigo #include "lldb/Target/Process.h" 166423b502SWalter Erquinigo #include "lldb/Utility/FileSpec.h" 17f190ce62SKazu Hirata #include <optional> 186423b502SWalter Erquinigo 196423b502SWalter Erquinigo namespace lldb_private { 206423b502SWalter Erquinigo namespace trace_intel_pt { 216423b502SWalter Erquinigo 22e0cfe20aSWalter Erquinigo /// Class that handles the decoding of a thread and caches the result. 236423b502SWalter Erquinigo class ThreadDecoder { 246423b502SWalter Erquinigo public: 25e0cfe20aSWalter Erquinigo /// \param[in] thread_sp 266a5355e8SWalter Erquinigo /// The thread whose intel pt trace buffer will be decoded. 27e0cfe20aSWalter Erquinigo /// 28e0cfe20aSWalter Erquinigo /// \param[in] trace 29e0cfe20aSWalter Erquinigo /// The main Trace object who owns this decoder and its data. 30e0cfe20aSWalter Erquinigo ThreadDecoder(const lldb::ThreadSP &thread_sp, TraceIntelPT &trace); 316423b502SWalter Erquinigo 326423b502SWalter Erquinigo /// Decode the thread and store the result internally, to avoid 336423b502SWalter Erquinigo /// recomputations. 346423b502SWalter Erquinigo /// 356423b502SWalter Erquinigo /// \return 366423b502SWalter Erquinigo /// A \a DecodedThread instance. 37a7d6c3efSWalter Erquinigo llvm::Expected<DecodedThreadSP> Decode(); 386423b502SWalter Erquinigo 394f676c25SWalter Erquinigo /// \return 40768cae4aSKazu Hirata /// The lowest TSC value in this trace if available, \a std::nullopt if 41768cae4aSKazu Hirata /// the trace is empty or the trace contains no timing information, or an 42768cae4aSKazu Hirata /// \a llvm::Error if it was not possible to set up the decoder. 43*2fe83274SKazu Hirata llvm::Expected<std::optional<uint64_t>> FindLowestTSC(); 444f676c25SWalter Erquinigo 456423b502SWalter Erquinigo ThreadDecoder(const ThreadDecoder &other) = delete; 466423b502SWalter Erquinigo ThreadDecoder &operator=(const ThreadDecoder &other) = delete; 476423b502SWalter Erquinigo 486423b502SWalter Erquinigo private: 49a7d6c3efSWalter Erquinigo llvm::Expected<DecodedThreadSP> DoDecode(); 506423b502SWalter Erquinigo 516423b502SWalter Erquinigo lldb::ThreadSP m_thread_sp; 526423b502SWalter Erquinigo TraceIntelPT &m_trace; 53*2fe83274SKazu Hirata std::optional<DecodedThreadSP> m_decoded_thread; 546423b502SWalter Erquinigo }; 556423b502SWalter Erquinigo 566423b502SWalter Erquinigo } // namespace trace_intel_pt 576423b502SWalter Erquinigo } // namespace lldb_private 586423b502SWalter Erquinigo 596423b502SWalter Erquinigo #endif // LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H 60