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: 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 trace buffer sizes used by this collection. 31 size_t GetTotalBufferSize() const; 32 33 /// Execute the provided callback on each thread that is being traced. 34 /// 35 /// \param[in] callback.tid 36 /// The id of the thread that is being traced. 37 /// 38 /// \param[in] callback.core_trace 39 /// The single-buffer trace instance for the given core. 40 void ForEachThread(std::function<void(lldb::tid_t tid, 41 IntelPTSingleBufferTrace &thread_trace)> 42 callback); 43 44 llvm::Expected<IntelPTSingleBufferTrace &> GetTracedThread(lldb::tid_t tid); 45 46 /// Start tracing the thread given by its \p tid. 47 /// 48 /// \return 49 /// An error if the operation failed. 50 llvm::Error TraceStart(lldb::tid_t tid, 51 const TraceIntelPTStartRequest &request); 52 53 /// Stop tracing the thread given by its \p tid. 54 /// 55 /// \return 56 /// An error if the given thread is not being traced or tracing couldn't be 57 /// stopped. 58 llvm::Error TraceStop(lldb::tid_t tid); 59 60 size_t GetTracedThreadsCount() const; 61 62 private: 63 llvm::DenseMap<lldb::tid_t, IntelPTSingleBufferTraceUP> m_thread_traces; 64 /// Total actual thread buffer size in bytes 65 size_t m_total_buffer_size = 0; 66 }; 67 68 } // namespace process_linux 69 } // namespace lldb_private 70 71 #endif // liblldb_IntelPTPerThreadTraceCollection_H_ 72