Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:59

0001 //===-- TraceIntelPTGDBRemotePackets.h --------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_TRACEINTELPTGDBREMOTEPACKETS_H
0010 #define LLDB_UTILITY_TRACEINTELPTGDBREMOTEPACKETS_H
0011 
0012 #include "lldb/Utility/TraceGDBRemotePackets.h"
0013 
0014 #include "llvm/Support/JSON.h"
0015 
0016 #include <chrono>
0017 #include <optional>
0018 
0019 /// See docs/lldb-gdb-remote.txt for more information.
0020 ///
0021 /// Do not use system-dependent types, like size_t, because they might cause
0022 /// issues when compiling on arm.
0023 namespace lldb_private {
0024 
0025 // List of data kinds used by jLLDBGetState and jLLDBGetBinaryData.
0026 struct IntelPTDataKinds {
0027   static const char *kProcFsCpuInfo;
0028   static const char *kIptTrace;
0029   static const char *kPerfContextSwitchTrace;
0030 };
0031 
0032 /// jLLDBTraceStart gdb-remote packet
0033 /// \{
0034 struct TraceIntelPTStartRequest : TraceStartRequest {
0035   /// Size in bytes to use for each thread's trace buffer.
0036   uint64_t ipt_trace_size;
0037 
0038   /// Whether to enable TSC
0039   bool enable_tsc;
0040 
0041   /// PSB packet period
0042   std::optional<uint64_t> psb_period;
0043 
0044   /// Required when doing "process tracing".
0045   ///
0046   /// Limit in bytes on all the thread traces started by this "process trace"
0047   /// instance. When a thread is about to be traced and the limit would be hit,
0048   /// then a "tracing" stop event is triggered.
0049   std::optional<uint64_t> process_buffer_size_limit;
0050 
0051   /// Whether to have a trace buffer per thread or per cpu cpu.
0052   std::optional<bool> per_cpu_tracing;
0053 
0054   /// Disable the cgroup filtering that is automatically applied in per cpu
0055   /// mode.
0056   std::optional<bool> disable_cgroup_filtering;
0057 
0058   bool IsPerCpuTracing() const;
0059 };
0060 
0061 bool fromJSON(const llvm::json::Value &value, TraceIntelPTStartRequest &packet,
0062               llvm::json::Path path);
0063 
0064 llvm::json::Value toJSON(const TraceIntelPTStartRequest &packet);
0065 /// \}
0066 
0067 /// Helper structure to help parse long numbers that can't
0068 /// be easily represented by a JSON number that is compatible with
0069 /// Javascript (52 bits) or that can also be represented as hex.
0070 ///
0071 /// \{
0072 struct JSONUINT64 {
0073   uint64_t value;
0074 };
0075 
0076 llvm::json::Value toJSON(const JSONUINT64 &uint64, bool hex);
0077 
0078 bool fromJSON(const llvm::json::Value &value, JSONUINT64 &uint64,
0079               llvm::json::Path path);
0080 /// \}
0081 
0082 /// jLLDBTraceGetState gdb-remote packet
0083 /// \{
0084 
0085 /// TSC to wall time conversion values defined in the Linux perf_event_open API
0086 /// when the capibilities cap_user_time and cap_user_time_zero are set. See the
0087 /// See the documentation of `time_zero` in
0088 /// https://man7.org/linux/man-pages/man2/perf_event_open.2.html for more
0089 /// information.
0090 struct LinuxPerfZeroTscConversion {
0091   /// Convert TSC value to nanosecond wall time. The beginning of time (0
0092   /// nanoseconds) is defined by the kernel at boot time and has no particularly
0093   /// useful meaning. On the other hand, this value is constant for an entire
0094   /// trace session.
0095   /// See 'time_zero' section of
0096   /// https://man7.org/linux/man-pages/man2/perf_event_open.2.html
0097   ///
0098   /// \param[in] tsc
0099   ///   The TSC value to be converted.
0100   ///
0101   /// \return
0102   ///   Nanosecond wall time.
0103   uint64_t ToNanos(uint64_t tsc) const;
0104 
0105   uint64_t ToTSC(uint64_t nanos) const;
0106 
0107   uint32_t time_mult;
0108   uint16_t time_shift;
0109   JSONUINT64 time_zero;
0110 };
0111 
0112 struct TraceIntelPTGetStateResponse : TraceGetStateResponse {
0113   /// The TSC to wall time conversion if it exists, otherwise \b nullptr.
0114   std::optional<LinuxPerfZeroTscConversion> tsc_perf_zero_conversion;
0115   bool using_cgroup_filtering = false;
0116 };
0117 
0118 bool fromJSON(const llvm::json::Value &value,
0119               LinuxPerfZeroTscConversion &packet, llvm::json::Path path);
0120 
0121 llvm::json::Value toJSON(const LinuxPerfZeroTscConversion &packet);
0122 
0123 bool fromJSON(const llvm::json::Value &value,
0124               TraceIntelPTGetStateResponse &packet, llvm::json::Path path);
0125 
0126 llvm::json::Value toJSON(const TraceIntelPTGetStateResponse &packet);
0127 /// \}
0128 
0129 } // namespace lldb_private
0130 
0131 #endif // LLDB_UTILITY_TRACEINTELPTGDBREMOTEPACKETS_H