1/* 2 * Copyright (C) 2017 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: 31 22message FtraceConfig { 23 // Ftrace events to record, example: "sched/sched_switch". 24 repeated string ftrace_events = 1; 25 26 message KprobeEvent { 27 enum KprobeType { 28 KPROBE_TYPE_UNKNOWN = 0; 29 KPROBE_TYPE_KPROBE = 1; 30 KPROBE_TYPE_KRETPROBE = 2; 31 KPROBE_TYPE_BOTH = 3; 32 } 33 // Kernel function name to attach to, for example "fuse_file_write_iter" 34 optional string probe = 1; 35 optional KprobeType type = 2; 36 } 37 38 // Ftrace events to record, specific for kprobes and kretprobes 39 repeated KprobeEvent kprobe_events = 30; 40 41 // Android-specific event categories: 42 repeated string atrace_categories = 2; 43 repeated string atrace_apps = 3; 44 // Some processes can emit data through atrace or through the perfetto SDK via 45 // the "track_event" data source. For these categories, the SDK will be 46 // preferred, if possible, for this config. 47 repeated string atrace_categories_prefer_sdk = 28; 48 49 // Size of each per-cpu kernel ftrace ring buffer. 50 // Not guaranteed if there are multiple concurrent tracing sessions, as the 51 // buffers cannot be resized without pausing recording in the kernel. 52 optional uint32 buffer_size_kb = 10; 53 54 // If set, specifies how often the tracing daemon reads from the kernel ring 55 // buffer. Not guaranteed if there are multiple concurrent tracing sessions. 56 // Leave unset unless you're fine-tuning a local config. 57 optional uint32 drain_period_ms = 11; 58 59 // If set, the tracing daemon will read kernel ring buffers as soon as 60 // they're filled past this percentage of occupancy. In other words, a value 61 // of 50 means that a read pass is triggered as soon as any per-cpu buffer is 62 // half-full. Not guaranteed if there are multiple concurrent tracing 63 // sessions. 64 // Currently does nothing on Linux kernels below v6.9. 65 // Introduced in: perfetto v48. 66 optional uint32 drain_buffer_percent = 29; 67 68 // Configuration for compact encoding of scheduler events. When enabled (and 69 // recording the relevant ftrace events), specific high-volume events are 70 // encoded in a denser format than normal. 71 message CompactSchedConfig { 72 // If true, and sched_switch or sched_waking ftrace events are enabled, 73 // record those events in the compact format. 74 // 75 // If the field is unset, the default is: 76 // * perfetto v42.0+: enabled 77 // * before: disabled 78 optional bool enabled = 1; 79 } 80 optional CompactSchedConfig compact_sched = 12; 81 82 // Optional filter for "ftrace/print" events. 83 // 84 // The filter consists of multiple rules. As soon as a rule matches (the rules 85 // are processed in order), its `allow` field will be used as the outcome: if 86 // `allow` is true, the event will be included in the trace, otherwise it will 87 // be discarded. If an event does not match any rule, it will be allowed by 88 // default (a rule with an empty prefix and allow=false, disallows everything 89 // by default). 90 message PrintFilter { 91 message Rule { 92 // Matches an atrace message of the form: 93 // <type>|pid|<prefix>... 94 message AtraceMessage { 95 optional string type = 1; 96 optional string prefix = 2; 97 } 98 oneof match { 99 // This rule matches if `prefix` matches exactly with the beginning of 100 // the "ftrace/print" "buf" field. 101 string prefix = 1; 102 // This rule matches if the "buf" field contains an atrace-style print 103 // message as specified in `atrace_msg`. 104 AtraceMessage atrace_msg = 3; 105 } 106 optional bool allow = 2; 107 } 108 repeated Rule rules = 1; 109 } 110 optional PrintFilter print_filter = 22; 111 112 // Enables symbol name resolution against /proc/kallsyms. 113 // It requires that either traced_probes is running as root or that 114 // kptr_restrict has been manually lowered. 115 // It does not disclose KASLR, symbol addresses are mangled. 116 optional bool symbolize_ksyms = 13; 117 118 // When symbolize_ksyms=true, determines whether the traced_probes daemon 119 // should keep the symbol map in memory (and reuse it for future tracing 120 // sessions) or clear it (saving memory) and re-create it on each tracing 121 // session (wasting cpu and wall time). 122 // The tradeoff is roughly: 123 // KSYMS_RETAIN: pay a fixed ~1.2 MB cost after the first trace. 124 // KSYMS_CLEANUP_ON_STOP: pay a ~300-500ms cost when starting each trace. 125 // Default behavior: KSYMS_CLEANUP_ON_STOP. 126 enum KsymsMemPolicy { 127 KSYMS_UNSPECIFIED = 0; 128 KSYMS_CLEANUP_ON_STOP = 1; 129 KSYMS_RETAIN = 2; 130 } 131 optional KsymsMemPolicy ksyms_mem_policy = 17; 132 133 // By default the kernel symbolizer is lazily initialized on a deferred task 134 // to reduce ftrace's time-to-start-recording. Unfortunately that makes 135 // ksyms integration tests hard. This flag forces the kernel symbolizer to be 136 // initialized synchronously on the data source start and hence avoiding 137 // timing races in tests. 138 // DEPRECATED in v28 / Android U. This is now the default behavior, setting it 139 // to true is a no-op. 140 optional bool initialize_ksyms_synchronously_for_testing = 14 141 [deprecated = true]; 142 143 // When this boolean is true AND the ftrace_events contains "kmem/rss_stat", 144 // this option causes traced_probes to enable the "kmem/rss_stat_throttled" 145 // event instead if present, and fall back to "kmem/rss_stat" if not present. 146 // The historical context for this is the following: 147 // - Up to Android S (12), the rss_stat was internally throttled in its 148 // kernel implementation. 149 // - A change introduced in the kernels after S has introduced a new 150 // "rss_stat_throttled" making the original "rss_stat" event unthrottled 151 // (hence very spammy). 152 // - Not all Android T/13 devices will receive a new kernel though, hence we 153 // need to deal with both cases. 154 // For more context: go/rss-stat-throttled. 155 optional bool throttle_rss_stat = 15; 156 157 // If true, avoid enabling events that aren't statically known by 158 // traced_probes. Otherwise, the default is to emit such events as 159 // GenericFtraceEvent protos. 160 // Prefer to keep this flag at its default. This was added for Android 161 // tracing, where atrace categories and/or atrace HAL requested events can 162 // expand to events that aren't of interest to the tracing user. 163 // Introduced in: Android T. 164 optional bool disable_generic_events = 16; 165 166 // The subset of syscalls to record. To record all syscalls, leave this unset 167 // and add "ftrace_events: raw_syscalls/sys_{enter,exit}" to the config. 168 // * before perfetto v43, requires the config to also enable 169 // raw_syscalls/sys_{enter,exit}. 170 // * perfetto v43+ does the right thing if you set only this field. 171 // Example: ["sys_read", "sys_open"]. 172 // Introduced in: Android U. 173 repeated string syscall_events = 18; 174 175 // If true, enable the "function_graph" kernel tracer that emits events 176 // whenever a kernel function is entered and exited 177 // (funcgraph_entry/funcgraph_exit). 178 // Notes on use: 179 // * Requires |symbolize_ksyms| for function name resolution. 180 // * Use |function_filters| or |function_graph_roots| to constrain the traced 181 // set of functions, otherwise the event bandwidth will be too high for 182 // practical use. 183 // * The data source might be rejected if there is already a concurrent 184 // ftrace data source that does not use function graph itself, as we do not 185 // support switching kernel tracers mid-trace. 186 // * Requires a kernel compiled with CONFIG_FUNCTION_GRAPH_TRACER. This is 187 // enabled if "cat /sys/kernel/tracing/available_tracers" includes 188 // "function_graph". 189 // Android: 190 // * Available only on debuggable builds. 191 // * Introduced in: Android U. 192 optional bool enable_function_graph = 19; 193 194 // Constrains the set of functions traced when |enable_function_graph| is 195 // true. Supports globs, e.g. "sched*". You can specify multiple filters, 196 // in which case all matching functions will be traced. See kernel 197 // documentation on ftrace "set_ftrace_filter" file for more details. 198 // Android: 199 // * Available only on debuggable builds. 200 // * Introduced in: Android U. 201 repeated string function_filters = 20; 202 203 // If |enable_function_graph| is true, trace this set of functions *and* all 204 // of its callees. Supports globs. Can be set together with 205 // |function_filters|, in which case only callees matching the filter will be 206 // traced. If setting both, you most likely want all roots to also be 207 // included in |function_filters|. 208 // Android: 209 // * Available only on debuggable builds. 210 // * Introduced in: Android U. 211 repeated string function_graph_roots = 21; 212 213 // If true, does not clear ftrace buffers before the start of the program. 214 // This makes sense only if this is the first ftrace data source instance 215 // created after the daemon has been started. Can be useful for gathering boot 216 // traces, if ftrace has been separately configured (e.g. via kernel 217 // commandline). 218 optional bool preserve_ftrace_buffer = 23; 219 220 // If true, overrides the default timestamp clock and uses a raw hardware 221 // based monotonic clock for getting timestamps. 222 // * Introduced in: Android U. 223 optional bool use_monotonic_raw_clock = 24; 224 225 // If |instance_name| is not empty, then attempt to use that tracefs instance 226 // for event recording. Normally, this means 227 // `/sys/kernel/tracing/instances/$instance_name`. 228 // 229 // The name "hyp" is reserved. 230 // 231 // The instance must already exist, the tracing daemon *will not* create it 232 // for you as it typically doesn't have such permissions. 233 // Only a subset of features is guaranteed to work with non-default instances, 234 // at the time of writing: 235 // * ftrace_events 236 // * buffer_size_kb 237 optional string instance_name = 25; 238 239 // If true, |buffer_size_kb| is interpreted as a lower bound, allowing the 240 // implementation to choose a bigger buffer size. 241 // 242 // Most configs for perfetto v43+ should simply leave both fields unset. 243 // 244 // If you need a config compatible with a range of perfetto builds and you 245 // used to set a non-default buffer_size_kb, consider setting both fields. 246 // Example: 247 // buffer_size_kb: 4096 248 // buffer_size_lower_bound: true 249 // On older builds, the per-cpu buffers will be exactly 4 MB. 250 // On v43+, buffers will be at least 4 MB. 251 // In both cases, neither is guaranteed if there are other concurrent 252 // perfetto ftrace sessions, as the buffers cannot be resized without pausing 253 // the recording in the kernel. 254 // Introduced in: perfetto v43. 255 optional bool buffer_size_lower_bound = 27; 256 257 // Previously drain_buffer_percent, perfetto v43-v47. 258 reserved 26; 259} 260