LLDB mainline
IntelPTMultiCoreTrace.h
Go to the documentation of this file.
1//===-- IntelPTMultiCoreTrace.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_IntelPTMultiCoreTrace_H_
10#define liblldb_IntelPTMultiCoreTrace_H_
11
16#include "lldb/lldb-types.h"
17#include "llvm/Support/Error.h"
18
19#include <memory>
20#include <optional>
21
22namespace lldb_private {
23namespace process_linux {
24
27
28public:
29 /// Start tracing all CPU cores.
30 ///
31 /// \param[in] request
32 /// Intel PT configuration parameters.
33 ///
34 /// \param[in] process
35 /// The process being debugged.
36 ///
37 /// \param[in] cgroup_fd
38 /// A file descriptor in /sys/fs associated with the cgroup of the process to
39 /// trace. If not \a std::nullopt, then the trace sesion will use cgroup
40 /// filtering.
41 ///
42 /// \return
43 /// An \a IntelPTMultiCoreTrace instance if tracing was successful, or
44 /// an \a llvm::Error otherwise.
45 static llvm::Expected<std::unique_ptr<IntelPTMultiCoreTrace>>
47 NativeProcessProtocol &process,
48 std::optional<int> cgroup_fd = std::nullopt);
49
50 /// Execute the provided callback on each core that is being traced.
51 ///
52 /// \param[in] callback.cpu_id
53 /// The core id that is being traced.
54 ///
55 /// \param[in] callback.core_trace
56 /// The single-buffer trace instance for the given core.
57 void ForEachCore(std::function<void(lldb::cpu_id_t cpu_id,
58 IntelPTSingleBufferTrace &core_trace)>
59 callback);
60
61 /// Execute the provided callback on each core that is being traced.
62 ///
63 /// \param[in] callback.cpu_id
64 /// The core id that is being traced.
65 ///
66 /// \param[in] callback.intelpt_trace
67 /// The single-buffer intel pt trace instance for the given core.
68 ///
69 /// \param[in] callback.context_switch_trace
70 /// The perf event collecting context switches for the given core.
71 void ForEachCore(std::function<void(lldb::cpu_id_t cpu_id,
72 IntelPTSingleBufferTrace &intelpt_trace,
73 ContextSwitchTrace &context_switch_trace)>
74 callback);
75
76 void ProcessDidStop() override;
77
78 void ProcessWillResume() override;
79
81
82 bool TracesThread(lldb::tid_t tid) const override;
83
84 llvm::Error TraceStart(lldb::tid_t tid) override;
85
86 llvm::Error TraceStop(lldb::tid_t tid) override;
87
88 llvm::Expected<std::optional<std::vector<uint8_t>>>
89 TryGetBinaryData(const TraceGetBinaryDataRequest &request) override;
90
91private:
92 /// This assumes that all underlying perf_events for each core are part of the
93 /// same perf event group.
95 llvm::DenseMap<lldb::cpu_id_t,
96 std::pair<IntelPTSingleBufferTrace, ContextSwitchTrace>>
97 &&traces_per_core,
98 NativeProcessProtocol &process, bool using_cgroup_filtering)
99 : m_traces_per_core(std::move(traces_per_core)), m_process(process),
100 m_using_cgroup_filtering(using_cgroup_filtering) {}
101
102 llvm::DenseMap<lldb::cpu_id_t,
103 std::pair<IntelPTSingleBufferTrace, ContextSwitchTrace>>
105
106 /// The target process.
109};
110
111} // namespace process_linux
112} // namespace lldb_private
113
114#endif // liblldb_IntelPTMultiCoreTrace_H_
void ForEachCore(std::function< void(lldb::cpu_id_t cpu_id, IntelPTSingleBufferTrace &intelpt_trace, ContextSwitchTrace &context_switch_trace)> callback)
Execute the provided callback on each core that is being traced.
IntelPTMultiCoreTrace(llvm::DenseMap< lldb::cpu_id_t, std::pair< IntelPTSingleBufferTrace, ContextSwitchTrace > > &&traces_per_core, NativeProcessProtocol &process, bool using_cgroup_filtering)
This assumes that all underlying perf_events for each core are part of the same perf event group.
TraceIntelPTGetStateResponse GetState() override
Construct a minimal jLLDBTraceGetState response for this process trace.
void ForEachCore(std::function< void(lldb::cpu_id_t cpu_id, IntelPTSingleBufferTrace &core_trace)> callback)
Execute the provided callback on each core that is being traced.
static llvm::Expected< std::unique_ptr< IntelPTMultiCoreTrace > > StartOnAllCores(const TraceIntelPTStartRequest &request, NativeProcessProtocol &process, std::optional< int > cgroup_fd=std::nullopt)
Start tracing all CPU cores.
llvm::Error TraceStart(lldb::tid_t tid) override
Start tracing the thread given by its tid.
NativeProcessProtocol & m_process
The target process.
llvm::DenseMap< lldb::cpu_id_t, std::pair< IntelPTSingleBufferTrace, ContextSwitchTrace > > m_traces_per_core
llvm::Expected< std::optional< std::vector< uint8_t > > > TryGetBinaryData(const TraceGetBinaryDataRequest &request) override
llvm::Error TraceStop(lldb::tid_t tid) override
Stop tracing the thread given by its tid.
Interface to be implemented by each 'process trace' strategy (per cpu, per thread,...
This class wraps a single perf event collecting intel pt data in a single buffer.
Thin wrapper of the perf_event_open API.
Definition Perf.h:80
A class that represents a running process on the host machine.
uint32_t cpu_id_t
Definition lldb-types.h:93
uint64_t tid_t
Definition lldb-types.h:85
jLLDBTraceGetBinaryData gdb-remote packet