1/* 2 * Copyright (C) 2019 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 19import "protos/perfetto/common/perf_events.proto"; 20 21package perfetto.protos; 22 23// Configuration for the traced_perf profiler. 24// 25// Example config for basic cpu profiling: 26// perf_event_config { 27// timebase { 28// frequency: 80 29// } 30// callstack_sampling { 31// scope { 32// target_cmdline: "surfaceflinger" 33// target_cmdline: "system_server" 34// } 35// kernel_frames: true 36// } 37// } 38// 39// Next id: 21 40message PerfEventConfig { 41 // What event to sample on, and how often. 42 // Defined in common/perf_events.proto. 43 optional PerfEvents.Timebase timebase = 15; 44 45 // Other events associated with the leader described in the timebase. 46 repeated FollowerEvent followers = 19; 47 48 // If set, the profiler will sample userspace processes' callstacks at the 49 // interval specified by the |timebase|. 50 // If unset, the profiler will record only the event counts. 51 optional CallstackSampling callstack_sampling = 16; 52 53 // List of cpu indices for counting. If empty, the default is all cpus. 54 // 55 // Note: this is not inside |callstack_sampling.scope| as it also applies to 56 // counter-only traces. A future change will likely reorganise the options, 57 // but this field will continue to be supported. 58 // 59 // Available since: perfetto v50. 60 repeated uint32 target_cpu = 20; 61 62 // 63 // Kernel <-> userspace ring buffer options: 64 // 65 66 // How often the per-cpu ring buffers are read by the producer. 67 // If unset, an implementation-defined default is used. 68 optional uint32 ring_buffer_read_period_ms = 8; 69 70 // Size (in 4k pages) of each per-cpu ring buffer that is filled by the 71 // kernel. If set, must be a power of two. 72 // If unset, an implementation-defined default is used. 73 optional uint32 ring_buffer_pages = 3; 74 75 // 76 // Daemon's resource usage limits: 77 // 78 79 // Drop samples if the heap memory held by the samples in the unwinder queue 80 // is above the given limit. This counts the memory across all concurrent data 81 // sources (not just this one's), and there is no fairness guarantee - the 82 // whole quota might be used up by a concurrent source. 83 optional uint64 max_enqueued_footprint_kb = 17; 84 85 // Stop the data source if traced_perf's combined {RssAnon + Swap} memory 86 // footprint exceeds this value. 87 optional uint32 max_daemon_memory_kb = 13; 88 89 // 90 // Uncommon options: 91 // 92 93 // Timeout for the remote /proc/<pid>/{maps,mem} file descriptors for a 94 // sampled process. This is primarily for Android, where this lookup is 95 // asynchronous. As long as the producer is waiting, the associated samples 96 // will be kept enqueued (putting pressure on the capacity of the shared 97 // unwinding queue). Once a lookup for a process expires, all associated 98 // samples are discarded. However, if the lookup still succeeds after the 99 // timeout, future samples will be handled normally. 100 // If unset, an implementation-defined default is used. 101 optional uint32 remote_descriptor_timeout_ms = 9; 102 103 // Optional period for clearing state cached by the unwinder. This is a heavy 104 // operation that is only necessary for traces that target a wide set of 105 // processes, and require the memory footprint to be reset periodically. 106 // If unset, the cached state will not be cleared. 107 optional uint32 unwind_state_clear_period_ms = 10; 108 109 // If set, only profile target if it was installed by a package with one of 110 // these names. Special values: 111 // * "@system": installed on the system partition 112 // * "@product": installed on the product partition 113 // * "@null": sideloaded 114 // Supported on Android 12+. 115 repeated string target_installed_by = 18; 116 117 // 118 // Deprecated (superseded by options above): 119 // 120 // Do not set *any* of these fields in new configs. 121 // 122 123 // Note: legacy configs had to set |all_cpus| to true to pass parsing. 124 // We rely on this to detect such configs. 125 optional bool all_cpus = 1; 126 optional uint32 sampling_frequency = 2; 127 optional bool kernel_frames = 12; 128 repeated int32 target_pid = 4; 129 repeated string target_cmdline = 5; 130 repeated int32 exclude_pid = 6; 131 repeated string exclude_cmdline = 7; 132 optional uint32 additional_cmdline_count = 11; 133 // previously |tracepoint| 134 reserved 14; 135 136 // 137 // Sub-messages (nested for generated code namespacing). 138 // 139 140 message CallstackSampling { 141 // Defines a set of processes for which samples are retained/skipped. If 142 // unset, all samples are kept, but beware that it will be very heavy on the 143 // stack unwinder, which might start dropping samples due to overload. 144 optional Scope scope = 1; 145 146 // If true, callstacks will include the kernel-space frames. Such frames can 147 // be identified by a magical "kernel" string as their mapping name. 148 // Requires traced_perf to be running as root, or kptr_restrict to have been 149 // manually unrestricted. On Android, the platform should do the right thing 150 // on debug builds. 151 // This does *not* disclose KASLR, as only the function names are emitted. 152 optional bool kernel_frames = 2; 153 154 // Whether to record and unwind userspace callstacks. If unset, defaults to 155 // including userspace (UNWIND_DWARF) both for backwards compatibility and 156 // as the most common default (this defaulting is only applicable if the 157 // outer CallstackSampling message is explicitly set). 158 optional UnwindMode user_frames = 3; 159 } 160 161 message Scope { 162 // Process ID (TGID) allowlist. If this list is not empty, only matching 163 // samples will be retained. If multiple allow/deny-lists are 164 // specified by the config, then all of them are evaluated for each sampled 165 // process. 166 repeated int32 target_pid = 1; 167 168 // Command line allowlist, matched against the /proc/<pid>/cmdline (not the 169 // comm string). The semantics of this field were changed since its original 170 // introduction. 171 // 172 // On Android T+ (13+), this field can specify a single wildcard (*), and 173 // the profiler will attempt to match it in two possible ways: 174 // * if the pattern starts with a '/', then it is matched against the first 175 // segment of the cmdline (i.e. argv0). For example "/bin/e*" would match 176 // "/bin/echo". 177 // * otherwise the pattern is matched against the part of argv0 178 // corresponding to the binary name (this is unrelated to /proc/pid/exe). 179 // For example "echo" would match "/bin/echo". 180 // 181 // On Android S (12) and below, both this pattern and /proc/pid/cmdline get 182 // normalized prior to an exact string comparison. Normalization is as 183 // follows: (1) trim everything beyond the first null or "@" byte; (2) if 184 // the string contains forward slashes, trim everything up to and including 185 // the last one. 186 // 187 // Implementation note: in either case, at most 511 characters of cmdline 188 // are considered. 189 repeated string target_cmdline = 2; 190 191 // List of excluded pids. 192 repeated int32 exclude_pid = 3; 193 194 // List of excluded cmdlines. See description of |target_cmdline| for how 195 // this is handled. 196 repeated string exclude_cmdline = 4; 197 198 // Niche features for systemwide callstacks: 199 200 // Number of additional command lines to sample. Only those which are 201 // neither explicitly included nor excluded will be considered. Processes 202 // are accepted on a first come, first served basis. 203 optional uint32 additional_cmdline_count = 5; 204 205 // If set to N, all encountered processes will be put into one of the N 206 // possible bins, and only one randomly-chosen bin will be selected for 207 // unwinding. The binning is simply "pid % N", under the assumption that 208 // low-order bits of pids are roughly uniformly distributed. Other explicit 209 // inclusions/exclusions in this |Scope| message are still respected. 210 // 211 // The profiler will report the chosen shard in PerfSampleDefaults, and the 212 // values will be queryable in trace processor under the "stats" table as 213 // "perf_process_shard_count" and "perf_chosen_process_shard". 214 // 215 // NB: all data sources in a config that set |process_shard_count| must set 216 // it to the same value. The profiler will choose one bin for all those data 217 // sources. 218 optional uint32 process_shard_count = 6; 219 } 220 221 // Userspace unwinding mode. A possible future addition is kernel-unwound 222 // callchains for frame pointer based systems. 223 enum UnwindMode { 224 UNWIND_UNKNOWN = 0; 225 // Do not unwind userspace: 226 UNWIND_SKIP = 1; 227 // Use libunwindstack (default): 228 UNWIND_DWARF = 2; 229 // Use userspace frame pointer unwinder: 230 UNWIND_FRAME_POINTER = 3; 231 } 232} 233