• 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
21// Next id: 12
22message PerfEvents {
23  // What event to sample on, and how often. Commented from the perspective of
24  // its use in |PerfEventConfig|.
25  message Timebase {
26    // How often the per-cpu sampling will occur. Not guaranteed to be honored
27    // as the kernel can throttle the sampling rate if it's too high.
28    // If unset, an implementation-defined default is used.
29    oneof interval {
30      // Per-cpu sampling frequency in Hz, as requested from the kernel. Not the
31      // same as 1/period.
32      // Details: the actual sampling will still be based on a period, but the
33      // kernel will dynamically adjust it based on the observed event rate, to
34      // approximate this frequency. Works best with steady-rate events like
35      // timers.
36      uint64 frequency = 2;
37
38      // Per-cpu sampling will occur every |period| counts of |event|.
39      // Prefer |frequency| by default, as it's easier to oversample with a
40      // fixed period.
41      uint64 period = 1;
42    }
43
44    // Counting event to use as a timebase for the sampling.
45    // If unset, implies the CPU timer (SW_CPU_CLOCK) as the event,
46    // which is what you usually want.
47    // See common/perf_events.proto for the definitions.
48    oneof event {
49      Counter counter = 4;
50      Tracepoint tracepoint = 3;
51      RawEvent raw_event = 5;
52    }
53
54    // If set, samples will be timestamped with the given clock.
55    // If unset, the clock is chosen by the implementation.
56    // For software events, prefer PERF_CLOCK_BOOTTIME. However it cannot be
57    // used for hardware events (due to interrupt safety), for which the
58    // recommendation is to use one of the monotonic clocks.
59    optional PerfClock timestamp_clock = 11;
60
61    // Optional arbitrary name for the event, to identify it in the parsed
62    // trace. Does *not* affect the profiling itself. If unset, the trace
63    // parser will choose a suitable name.
64    optional string name = 10;
65  }
66
67  // Builtin counter names from the uapi header. Commented with their perf tool
68  // aliases.
69  // TODO(rsavitski): consider generating enums for cache events (should be
70  // finite), and generally make this list as extensive as possible. Excluding
71  // things like dynamic PMUs since those don't fit into a static enum.
72  // Next id: 21
73  enum Counter {
74    UNKNOWN_COUNTER = 0;
75
76    // cpu-clock
77    SW_CPU_CLOCK = 1;
78    // page-faults, faults
79    SW_PAGE_FAULTS = 2;
80    // task-clock
81    SW_TASK_CLOCK = 3;
82    // context-switches, cs
83    SW_CONTEXT_SWITCHES = 4;
84    // cpu-migrations, migrations
85    SW_CPU_MIGRATIONS = 5;
86    // minor-faults
87    SW_PAGE_FAULTS_MIN = 6;
88    // major-faults
89    SW_PAGE_FAULTS_MAJ = 7;
90    // alignment-faults
91    SW_ALIGNMENT_FAULTS = 8;
92    // emulation-faults
93    SW_EMULATION_FAULTS = 9;
94    // dummy
95    SW_DUMMY = 20;
96
97    // cpu-cycles, cycles
98    HW_CPU_CYCLES = 10;
99    // instructions
100    HW_INSTRUCTIONS = 11;
101    // cache-references
102    HW_CACHE_REFERENCES = 12;
103    // cache-misses
104    HW_CACHE_MISSES = 13;
105    // branch-instructions, branches
106    HW_BRANCH_INSTRUCTIONS = 14;
107    // branch-misses
108    HW_BRANCH_MISSES = 15;
109    // bus-cycles
110    HW_BUS_CYCLES = 16;
111    // stalled-cycles-frontend, idle-cycles-frontend
112    HW_STALLED_CYCLES_FRONTEND = 17;
113    // stalled-cycles-backend, idle-cycles-backend
114    HW_STALLED_CYCLES_BACKEND = 18;
115    // ref-cycles
116    HW_REF_CPU_CYCLES = 19;
117  }
118
119  message Tracepoint {
120    // Group and name for the tracepoint, acceptable forms:
121    // * "sched/sched_switch"
122    // * "sched:sched_switch"
123    optional string name = 1;
124
125    // Optional field-level filter for the tracepoint. Only events matching this
126    // filter will be counted (and therefore contribute to the sampling period).
127    // Example: "prev_pid >= 42 && next_pid == 0".
128    // For full syntax, see kernel documentation on "Event filtering":
129    // https://www.kernel.org/doc/Documentation/trace/events.txt
130    optional string filter = 2;
131  }
132
133  // Syscall-level description of the event, propagated to the perf_event_attr
134  // struct. Primarily for local use-cases, since the event availability and
135  // encoding is hardware-specific.
136  message RawEvent {
137    optional uint32 type = 1;
138    optional uint64 config = 2;
139    optional uint64 config1 = 3;
140    optional uint64 config2 = 4;
141  }
142
143  // Subset of clocks that is supported by perf timestamping.
144  // CLOCK_TAI is excluded since it's not expected to be used in practice, but
145  // would require additions to the trace clock synchronisation logic.
146  enum PerfClock {
147    UNKNOWN_PERF_CLOCK = 0;
148    PERF_CLOCK_REALTIME = 1;
149    PERF_CLOCK_MONOTONIC = 2;
150    PERF_CLOCK_MONOTONIC_RAW = 3;
151    PERF_CLOCK_BOOTTIME = 4;
152  }
153}
154