1 //===-- IntelPTThreadTraceCollection.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 liblldb_IntelPTPerThreadTraceCollection_H_ 10 #define liblldb_IntelPTPerThreadTraceCollection_H_ 11 12 #include "IntelPTSingleBufferTrace.h" 13 14 namespace lldb_private { 15 namespace process_linux { 16 17 /// Manages a list of thread traces. 18 class IntelPTThreadTraceCollection { 19 public: IntelPTThreadTraceCollection()20 IntelPTThreadTraceCollection() {} 21 22 /// Dispose of all traces 23 void Clear(); 24 25 /// \return 26 /// \b true if and only if this instance of tracing the provided \p tid. 27 bool TracesThread(lldb::tid_t tid) const; 28 29 /// \return 30 /// The total sum of the intel pt trace buffer sizes used by this 31 /// collection. 32 size_t GetTotalBufferSize() const; 33 34 /// Execute the provided callback on each thread that is being traced. 35 /// 36 /// \param[in] callback.tid 37 /// The id of the thread that is being traced. 38 /// 39 /// \param[in] callback.core_trace 40 /// The single-buffer trace instance for the given core. 41 void ForEachThread(std::function<void(lldb::tid_t tid, 42 IntelPTSingleBufferTrace &thread_trace)> 43 callback); 44 45 llvm::Expected<IntelPTSingleBufferTrace &> GetTracedThread(lldb::tid_t tid); 46 47 /// Start tracing the thread given by its \p tid. 48 /// 49 /// \return 50 /// An error if the operation failed. 51 llvm::Error TraceStart(lldb::tid_t tid, 52 const TraceIntelPTStartRequest &request); 53 54 /// Stop tracing the thread given by its \p tid. 55 /// 56 /// \return 57 /// An error if the given thread is not being traced or tracing couldn't be 58 /// stopped. 59 llvm::Error TraceStop(lldb::tid_t tid); 60 61 size_t GetTracedThreadsCount() const; 62 63 /// \copydoc IntelPTProcessTrace::TryGetBinaryData() 64 llvm::Expected<llvm::Optional<std::vector<uint8_t>>> 65 TryGetBinaryData(const TraceGetBinaryDataRequest &request); 66 67 private: 68 llvm::DenseMap<lldb::tid_t, IntelPTSingleBufferTrace> m_thread_traces; 69 /// Total actual thread buffer size in bytes 70 size_t m_total_buffer_size = 0; 71 }; 72 73 } // namespace process_linux 74 } // namespace lldb_private 75 76 #endif // liblldb_IntelPTPerThreadTraceCollection_H_ 77