• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17syntax = "proto2";
18
19package perfetto.protos;
20
21message PerfEvents {
22  // The primary event to count. If recording multiple events, this
23  // counter is the "group leader".
24  // Commented from the perspective of its use in |PerfEventConfig|.
25  // Next id: 12
26  message Timebase {
27    // How often to snapshot the counter, along with any follower events and
28    // any additional sampled data such as callstacks.
29    //
30    // This choice also controls how the readings are taken:
31    // * With |frequency| or |period|, samples are taken by the kernel
32    //   into a ring buffer. Analogous to `perf record`.
33    // * With |poll_period_ms|, the userspace periodically snapshots
34    //   the counters using the read syscall. Analogous to `perf stat -I`.
35    // Prefer the sampling options unless you're recording PMUs whose
36    // perf drivers only support the reading mode.
37    //
38    // If unset, an implementation-defined sampling default is used.
39    oneof interval {
40      // Per-cpu sampling frequency in Hz, as requested from the kernel. Not the
41      // same as 1/period.
42      // Details: the actual sampling will still be based on a period, but the
43      // kernel will dynamically adjust it based on the observed event rate, to
44      // approximate this frequency. Works best with steady-rate events like
45      // timers.
46      // Not guaranteed to be honored as the kernel can throttle the sampling
47      // rate if it's too high.
48      uint64 frequency = 2;
49
50      // Per-cpu sampling will occur every |period| counts of |event|.
51      // Prefer |frequency| by default, as it's easier to oversample with a
52      // fixed period.
53      // Not guaranteed to be honored as the kernel can throttle the sampling
54      // rate if it's too high.
55      uint64 period = 1;
56
57      // Per-cpu values are read by the userspace every interval. If using this
58      // mode, only follower events are supported. Options such as
59      // |PerfEventConfig.CallstackSampling| are incompatible.
60      // The period can't be guaranteed to be exact since the readings are taken
61      // by userspace.
62      uint32 poll_period_ms = 6;
63    }
64
65    // Counting event to use as the timebase.
66    // If unset, implies the CPU timer (SW_CPU_CLOCK) as the event,
67    // which is what you usually want.
68    oneof event {
69      Counter counter = 4;
70      Tracepoint tracepoint = 3;
71      RawEvent raw_event = 5;
72    }
73
74    // If set, samples will be timestamped with the given clock.
75    // If unset, the clock is chosen by the implementation.
76    // For software events, prefer PERF_CLOCK_BOOTTIME. However it cannot be
77    // used for hardware events (due to interrupt safety), for which the
78    // recommendation is to use one of the monotonic clocks.
79    optional PerfClock timestamp_clock = 11;
80
81    // Optional arbitrary name for the event, to identify it in the parsed
82    // trace. Does *not* affect the profiling itself. If unset, the trace
83    // parser will choose a suitable name.
84    optional string name = 10;
85  }
86
87  // Builtin counter names from the uapi header. Commented with their perf tool
88  // aliases.
89  // TODO(rsavitski): consider generating enums for cache events (should be
90  // finite), and generally make this list as extensive as possible. Excluding
91  // things like dynamic PMUs since those don't fit into a static enum.
92  // Next id: 21
93  enum Counter {
94    UNKNOWN_COUNTER = 0;
95
96    // cpu-clock
97    SW_CPU_CLOCK = 1;
98    // page-faults, faults
99    SW_PAGE_FAULTS = 2;
100    // task-clock
101    SW_TASK_CLOCK = 3;
102    // context-switches, cs
103    SW_CONTEXT_SWITCHES = 4;
104    // cpu-migrations, migrations
105    SW_CPU_MIGRATIONS = 5;
106    // minor-faults
107    SW_PAGE_FAULTS_MIN = 6;
108    // major-faults
109    SW_PAGE_FAULTS_MAJ = 7;
110    // alignment-faults
111    SW_ALIGNMENT_FAULTS = 8;
112    // emulation-faults
113    SW_EMULATION_FAULTS = 9;
114    // dummy
115    SW_DUMMY = 20;
116
117    // cpu-cycles, cycles
118    HW_CPU_CYCLES = 10;
119    // instructions
120    HW_INSTRUCTIONS = 11;
121    // cache-references
122    HW_CACHE_REFERENCES = 12;
123    // cache-misses
124    HW_CACHE_MISSES = 13;
125    // branch-instructions, branches
126    HW_BRANCH_INSTRUCTIONS = 14;
127    // branch-misses
128    HW_BRANCH_MISSES = 15;
129    // bus-cycles
130    HW_BUS_CYCLES = 16;
131    // stalled-cycles-frontend, idle-cycles-frontend
132    HW_STALLED_CYCLES_FRONTEND = 17;
133    // stalled-cycles-backend, idle-cycles-backend
134    HW_STALLED_CYCLES_BACKEND = 18;
135    // ref-cycles
136    HW_REF_CPU_CYCLES = 19;
137  }
138
139  message Tracepoint {
140    // Group and name for the tracepoint, acceptable forms:
141    // * "sched/sched_switch"
142    // * "sched:sched_switch"
143    optional string name = 1;
144
145    // Optional field-level filter for the tracepoint. Only events matching this
146    // filter will be counted (and therefore contribute to the sampling period).
147    // Example: "prev_pid >= 42 && next_pid == 0".
148    // For full syntax, see kernel documentation on "Event filtering":
149    // https://www.kernel.org/doc/Documentation/trace/events.txt
150    optional string filter = 2;
151  }
152
153  // Syscall-level description of the event, propagated to the perf_event_attr
154  // struct. Primarily for local use-cases, since the event availability and
155  // encoding is hardware-specific.
156  message RawEvent {
157    optional uint32 type = 1;
158    optional uint64 config = 2;
159    optional uint64 config1 = 3;
160    optional uint64 config2 = 4;
161  }
162
163  // Subset of clocks that is supported by perf timestamping.
164  // CLOCK_TAI is excluded since it's not expected to be used in practice, but
165  // would require additions to the trace clock synchronisation logic.
166  enum PerfClock {
167    UNKNOWN_PERF_CLOCK = 0;
168    PERF_CLOCK_REALTIME = 1;
169    PERF_CLOCK_MONOTONIC = 2;
170    PERF_CLOCK_MONOTONIC_RAW = 3;
171    PERF_CLOCK_BOOTTIME = 4;
172  }
173}
174
175// Additional events associated with a leader.
176// Configuration is similar to Timebase event. Because data acquisition is
177// driven by the leader there is no option to configure the clock or the
178// frequency.
179message FollowerEvent {
180  oneof event {
181    PerfEvents.Counter counter = 1;
182    PerfEvents.Tracepoint tracepoint = 2;
183    PerfEvents.RawEvent raw_event = 3;
184  }
185  optional string name = 4;
186}
187