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