LLDB mainline
IntelPTSingleBufferTrace.h
Go to the documentation of this file.
1//===-- IntelPTSingleBufferTrace.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_IntelPTSingleBufferTrace_H_
10#define liblldb_IntelPTSingleBufferTrace_H_
11
14#include "lldb/lldb-types.h"
15#include "llvm/Support/Error.h"
16
17#include <cstddef>
18#include <cstdint>
19#include <memory>
20#include <vector>
21
22namespace lldb_private {
23namespace process_linux {
24
25llvm::Expected<uint32_t> GetIntelPTOSEventType();
26
27/// This class wraps a single perf event collecting intel pt data in a single
28/// buffer.
30public:
31 /// Start tracing using a single Intel PT trace buffer.
32 ///
33 /// \param[in] request
34 /// Intel PT configuration parameters.
35 ///
36 /// \param[in] tid
37 /// The tid of the thread to be traced. If \b None, then this traces all
38 /// threads of all processes.
39 ///
40 /// \param[in] cpu_id
41 /// The CPU core id where to trace. If \b None, then this traces all CPUs.
42 ///
43 /// \param[in] disabled
44 /// If \b true, then no data is collected until \a Resume is invoked.
45 /// Similarly, if \b false, data is collected right away until \a Pause is
46 /// invoked.
47 ///
48 /// \param[in] cgroup_fd
49 /// A file descriptor in /sys/fs associated with the cgroup of the process
50 /// to trace. If not \a std::nullopt, then the trace sesion will use cgroup
51 /// filtering.
52 ///
53 /// \return
54 /// A \a IntelPTSingleBufferTrace instance if tracing was successful, or
55 /// an \a llvm::Error otherwise.
56 static llvm::Expected<IntelPTSingleBufferTrace>
57 Start(const TraceIntelPTStartRequest &request, std::optional<lldb::tid_t> tid,
58 std::optional<lldb::cpu_id_t> cpu_id = std::nullopt,
59 bool disabled = false, std::optional<int> cgroup_fd = std::nullopt);
60
61 /// \return
62 /// The bytes requested by a jLLDBTraceGetBinaryData packet that was routed
63 /// to this trace instace.
64 llvm::Expected<std::vector<uint8_t>>
66
67 /// Read the intel pt trace buffer managed by this trace instance. To ensure
68 /// that the data is up-to-date and is not corrupted by read-write race
69 /// conditions, the underlying perf_event is paused during read, and later
70 /// it's returned to its initial state.
71 ///
72 /// \return
73 /// A vector with the requested binary data.
74 llvm::Expected<std::vector<uint8_t>> GetIptTrace();
75
76 /// \return
77 /// The total the size in bytes used by the intel pt trace buffer managed
78 /// by this trace instance.
79 size_t GetIptTraceSize() const;
80
81 /// Resume the collection of this trace.
82 ///
83 /// \return
84 /// An error if the trace couldn't be resumed. If the trace is already
85 /// running, this returns \a Error::success().
86 llvm::Error Resume();
87
88 /// Pause the collection of this trace.
89 ///
90 /// \return
91 /// An error if the trace couldn't be paused. If the trace is already
92 /// paused, this returns \a Error::success().
93 llvm::Error Pause();
94
95 /// \return
96 /// The underlying PerfEvent for this trace.
97 const PerfEvent &GetPerfEvent() const;
98
99private:
100 /// Construct new \a IntelPTSingleBufferThreadTrace. Users are supposed to
101 /// create instances of this class via the \a Start() method and not invoke
102 /// this one directly.
103 ///
104 /// \param[in] perf_event
105 /// perf event configured for IntelPT.
106 ///
107 /// \param[in] collection_state
108 /// The initial collection state for the provided perf_event.
110 : m_perf_event(std::move(perf_event)) {}
111
112 /// perf event configured for IntelPT.
114};
115
116} // namespace process_linux
117} // namespace lldb_private
118
119#endif // liblldb_IntelPTSingleBufferTrace_H_
This file contains a thin wrapper of the perf_event_open API and classes to handle the destruction of...
static llvm::Expected< IntelPTSingleBufferTrace > Start(const TraceIntelPTStartRequest &request, std::optional< lldb::tid_t > tid, std::optional< lldb::cpu_id_t > cpu_id=std::nullopt, bool disabled=false, std::optional< int > cgroup_fd=std::nullopt)
Start tracing using a single Intel PT trace buffer.
PerfEvent m_perf_event
perf event configured for IntelPT.
llvm::Error Resume()
Resume the collection of this trace.
IntelPTSingleBufferTrace(PerfEvent &&perf_event)
Construct new IntelPTSingleBufferThreadTrace.
llvm::Error Pause()
Pause the collection of this trace.
llvm::Expected< std::vector< uint8_t > > GetBinaryData(const TraceGetBinaryDataRequest &request) const
llvm::Expected< std::vector< uint8_t > > GetIptTrace()
Read the intel pt trace buffer managed by this trace instance.
Thin wrapper of the perf_event_open API.
Definition Perf.h:80
llvm::Expected< uint32_t > GetIntelPTOSEventType()
Return the Linux perf event type for Intel PT.
A class that represents a running process on the host machine.
jLLDBTraceGetBinaryData gdb-remote packet