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