LLDB  mainline
TraceIntelPTGDBRemotePackets.h
Go to the documentation of this file.
1 //===-- TraceIntelPTGDBRemotePackets.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 LLDB_UTILITY_TRACEINTELPTGDBREMOTEPACKETS_H
10 #define LLDB_UTILITY_TRACEINTELPTGDBREMOTEPACKETS_H
11 
13 
14 #include "llvm/Support/JSON.h"
15 
16 #include <chrono>
17 
18 /// See docs/lldb-gdb-remote.txt for more information.
19 ///
20 /// Do not use system-dependent types, like size_t, because they might cause
21 /// issues when compiling on arm.
22 namespace lldb_private {
23 
24 // List of data kinds used by jLLDBGetState and jLLDBGetBinaryData.
26  static const char *kProcFsCpuInfo;
27  static const char *kIptTrace;
28  static const char *kPerfContextSwitchTrace;
29 };
30 
31 /// jLLDBTraceStart gdb-remote packet
32 /// \{
34  /// Size in bytes to use for each thread's trace buffer.
35  uint64_t ipt_trace_size;
36 
37  /// Whether to enable TSC
38  bool enable_tsc;
39 
40  /// PSB packet period
41  llvm::Optional<uint64_t> psb_period;
42 
43  /// Required when doing "process tracing".
44  ///
45  /// Limit in bytes on all the thread traces started by this "process trace"
46  /// instance. When a thread is about to be traced and the limit would be hit,
47  /// then a "tracing" stop event is triggered.
48  llvm::Optional<uint64_t> process_buffer_size_limit;
49 
50  /// Whether to have a trace buffer per thread or per cpu cpu.
51  llvm::Optional<bool> per_cpu_tracing;
52 
53  /// Disable the cgroup filtering that is automatically applied in per cpu
54  /// mode.
55  llvm::Optional<bool> disable_cgroup_filtering;
56 
57  bool IsPerCpuTracing() const;
58 };
59 
60 bool fromJSON(const llvm::json::Value &value, TraceIntelPTStartRequest &packet,
61  llvm::json::Path path);
62 
63 llvm::json::Value toJSON(const TraceIntelPTStartRequest &packet);
64 /// \}
65 
66 /// Helper structure to help parse long numbers that can't
67 /// be easily represented by a JSON number that is compatible with
68 /// Javascript (52 bits) or that can also be represented as hex.
69 ///
70 /// \{
71 struct JSONUINT64 {
72  uint64_t value;
73 };
74 
75 llvm::json::Value toJSON(const JSONUINT64 &uint64, bool hex);
76 
77 bool fromJSON(const llvm::json::Value &value, JSONUINT64 &uint64,
78  llvm::json::Path path);
79 /// \}
80 
81 /// jLLDBTraceGetState gdb-remote packet
82 /// \{
83 
84 /// TSC to wall time conversion values defined in the Linux perf_event_open API
85 /// when the capibilities cap_user_time and cap_user_time_zero are set. See the
86 /// See the documentation of `time_zero` in
87 /// https://man7.org/linux/man-pages/man2/perf_event_open.2.html for more
88 /// information.
90  /// Convert TSC value to nanosecond wall time. The beginning of time (0
91  /// nanoseconds) is defined by the kernel at boot time and has no particularly
92  /// useful meaning. On the other hand, this value is constant for an entire
93  /// trace session.
94  /// See 'time_zero' section of
95  /// https://man7.org/linux/man-pages/man2/perf_event_open.2.html
96  ///
97  /// \param[in] tsc
98  /// The TSC value to be converted.
99  ///
100  /// \return
101  /// Nanosecond wall time.
102  uint64_t ToNanos(uint64_t tsc) const;
103 
104  uint64_t ToTSC(uint64_t nanos) const;
105 
109 };
110 
112  /// The TSC to wall time conversion if it exists, otherwise \b nullptr.
113  llvm::Optional<LinuxPerfZeroTscConversion> tsc_perf_zero_conversion;
115 };
116 
117 bool fromJSON(const llvm::json::Value &value,
118  LinuxPerfZeroTscConversion &packet, llvm::json::Path path);
119 
120 llvm::json::Value toJSON(const LinuxPerfZeroTscConversion &packet);
121 
122 bool fromJSON(const llvm::json::Value &value,
123  TraceIntelPTGetStateResponse &packet, llvm::json::Path path);
124 
125 llvm::json::Value toJSON(const TraceIntelPTGetStateResponse &packet);
126 /// \}
127 
128 } // namespace lldb_private
129 
130 #endif // LLDB_UTILITY_TRACEINTELPTGDBREMOTEPACKETS_H
lldb_private::toJSON
llvm::json::Value toJSON(const TraceSupportedResponse &packet)
Definition: TraceGDBRemotePackets.cpp:24
lldb_private::LinuxPerfZeroTscConversion::ToTSC
uint64_t ToTSC(uint64_t nanos) const
Definition: TraceIntelPTGDBRemotePackets.cpp:82
lldb_private::TraceGetStateResponse
Definition: TraceGDBRemotePackets.h:132
lldb_private::TraceIntelPTStartRequest::IsPerCpuTracing
bool IsPerCpuTracing() const
Definition: TraceIntelPTGDBRemotePackets.cpp:21
lldb_private::TraceIntelPTGetStateResponse
Definition: TraceIntelPTGDBRemotePackets.h:111
lldb_private::TraceIntelPTGetStateResponse::using_cgroup_filtering
bool using_cgroup_filtering
Definition: TraceIntelPTGDBRemotePackets.h:114
lldb_private::LinuxPerfZeroTscConversion::time_zero
JSONUINT64 time_zero
Definition: TraceIntelPTGDBRemotePackets.h:108
lldb_private::LinuxPerfZeroTscConversion::time_mult
uint32_t time_mult
Definition: TraceIntelPTGDBRemotePackets.h:106
lldb_private::TraceIntelPTStartRequest::per_cpu_tracing
llvm::Optional< bool > per_cpu_tracing
Whether to have a trace buffer per thread or per cpu cpu.
Definition: TraceIntelPTGDBRemotePackets.h:51
lldb_private::TraceIntelPTStartRequest::psb_period
llvm::Optional< uint64_t > psb_period
PSB packet period.
Definition: TraceIntelPTGDBRemotePackets.h:41
lldb_private::TraceIntelPTStartRequest
jLLDBTraceStart gdb-remote packet
Definition: TraceIntelPTGDBRemotePackets.h:33
lldb_private::LinuxPerfZeroTscConversion::time_shift
uint16_t time_shift
Definition: TraceIntelPTGDBRemotePackets.h:107
lldb_private::TraceIntelPTStartRequest::ipt_trace_size
uint64_t ipt_trace_size
Size in bytes to use for each thread's trace buffer.
Definition: TraceIntelPTGDBRemotePackets.h:35
lldb_private::IntelPTDataKinds::kIptTrace
static const char * kIptTrace
Definition: TraceIntelPTGDBRemotePackets.h:27
lldb_private::fromJSON
bool fromJSON(const llvm::json::Value &value, TraceSupportedResponse &info, llvm::json::Path path)
lldb_private::IntelPTDataKinds::kPerfContextSwitchTrace
static const char * kPerfContextSwitchTrace
Definition: TraceIntelPTGDBRemotePackets.h:28
lldb_private::TraceStartRequest
jLLDBTraceStart gdb-remote packet
Definition: TraceGDBRemotePackets.h:43
lldb_private::JSONUINT64::value
uint64_t value
Definition: TraceIntelPTGDBRemotePackets.h:72
uint32_t
lldb_private::LinuxPerfZeroTscConversion
jLLDBTraceGetState gdb-remote packet
Definition: TraceIntelPTGDBRemotePackets.h:89
lldb_private::TraceIntelPTStartRequest::process_buffer_size_limit
llvm::Optional< uint64_t > process_buffer_size_limit
Required when doing "process tracing".
Definition: TraceIntelPTGDBRemotePackets.h:48
uint16_t
lldb_private::LinuxPerfZeroTscConversion::ToNanos
uint64_t ToNanos(uint64_t tsc) const
Convert TSC value to nanosecond wall time.
Definition: TraceIntelPTGDBRemotePackets.cpp:75
lldb_private::IntelPTDataKinds
Definition: TraceIntelPTGDBRemotePackets.h:25
lldb_private::TraceIntelPTStartRequest::enable_tsc
bool enable_tsc
Whether to enable TSC.
Definition: TraceIntelPTGDBRemotePackets.h:38
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::JSONUINT64
Helper structure to help parse long numbers that can't be easily represented by a JSON number that is...
Definition: TraceIntelPTGDBRemotePackets.h:71
lldb_private::TraceIntelPTGetStateResponse::tsc_perf_zero_conversion
llvm::Optional< LinuxPerfZeroTscConversion > tsc_perf_zero_conversion
The TSC to wall time conversion if it exists, otherwise nullptr.
Definition: TraceIntelPTGDBRemotePackets.h:113
TraceGDBRemotePackets.h
lldb_private::TraceIntelPTStartRequest::disable_cgroup_filtering
llvm::Optional< bool > disable_cgroup_filtering
Disable the cgroup filtering that is automatically applied in per cpu mode.
Definition: TraceIntelPTGDBRemotePackets.h:55
lldb_private::IntelPTDataKinds::kProcFsCpuInfo
static const char * kProcFsCpuInfo
Definition: TraceIntelPTGDBRemotePackets.h:26