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 19import "protos/perfetto/trace/ftrace/ftrace_event.proto"; 20import "protos/perfetto/trace/ftrace/ftrace_stats.proto"; 21 22package perfetto.protos; 23 24// The result of tracing one or more ftrace data pages from a single per-cpu 25// kernel ring buffer. If collating multiple pages' worth of events, all of 26// them come from contiguous pages, with no kernel data loss in between. 27message FtraceEventBundle { 28 optional uint32 cpu = 1; 29 repeated FtraceEvent event = 2; 30 31 // Set to true if there was data loss between the last time we've read from 32 // the corresponding per-cpu kernel buffer, and the earliest event recorded 33 // in this bundle. 34 optional bool lost_events = 3; 35 36 // Optionally-enabled compact encoding of a batch of scheduling events. Only 37 // a subset of events & their fields is recorded. 38 // All fields (except comms) are stored in a structure-of-arrays form, one 39 // entry in each repeated field per event. 40 message CompactSched { 41 // Interned table of unique strings for this bundle. 42 repeated string intern_table = 5; 43 44 // Delta-encoded timestamps across all sched_switch events within this 45 // bundle. The first is absolute, each next one is relative to its 46 // predecessor. 47 repeated uint64 switch_timestamp = 1 [packed = true]; 48 repeated int64 switch_prev_state = 2 [packed = true]; 49 repeated int32 switch_next_pid = 3 [packed = true]; 50 repeated int32 switch_next_prio = 4 [packed = true]; 51 // One per event, index into |intern_table| corresponding to the 52 // next_comm field of the event. 53 repeated uint32 switch_next_comm_index = 6 [packed = true]; 54 55 // Delta-encoded timestamps across all sched_waking events within this 56 // bundle. The first is absolute, each next one is relative to its 57 // predecessor. 58 repeated uint64 waking_timestamp = 7 [packed = true]; 59 repeated int32 waking_pid = 8 [packed = true]; 60 repeated int32 waking_target_cpu = 9 [packed = true]; 61 repeated int32 waking_prio = 10 [packed = true]; 62 // One per event, index into |intern_table| corresponding to the 63 // comm field of the event. 64 repeated uint32 waking_comm_index = 11 [packed = true]; 65 repeated uint32 waking_common_flags = 12 [packed = true]; 66 } 67 optional CompactSched compact_sched = 4; 68 69 // traced_probes always sets the ftrace_clock to "boot". That is not available 70 // in older kernels (v3.x). In that case we fallback on "global" or "local". 71 // When we do that, we report the fallback clock in each bundle so we can do 72 // proper clock syncing at parsing time in TraceProcessor. We cannot use the 73 // TracePacket timestamp_clock_id because: (1) there is no per-packet 74 // timestamp for ftrace bundles; (2) "global" does not match CLOCK_MONOTONIC. 75 // Having a dedicated and explicit flag allows us to correct further misakes 76 // in future by looking at the kernel version. 77 // This field has been introduced in perfetto v19 / Android T (13). 78 // This field is omitted when the ftrace clock is just "boot", as that is the 79 // default assumption (and for consistency with the past). 80 optional FtraceClock ftrace_clock = 5; 81 82 // The timestamp according to the ftrace clock, taken at the same instant 83 // as |boot_timestamp|. This is used to sync ftrace events when a non-boot 84 // clock is used as the ftrace clock. We don't use the ClockSnapshot packet 85 // because the ftrace global/local clocks don't match any of the clock_gettime 86 // domains and can be only read by traced_probes. 87 // 88 // Only set when |ftrace_clock| != FTRACE_CLOCK_UNSPECIFIED. 89 // 90 // Implementation note: Populated by reading the 'now ts:' field in 91 // tracefs/per_cpu/cpuX/stat. 92 optional int64 ftrace_timestamp = 6; 93 94 // The timestamp according to CLOCK_BOOTTIME, taken at the same instant as 95 // |ftrace_timestamp|. See documentation of |ftrace_timestamp| for 96 // more info. 97 // 98 // Only set when |ftrace_clock| != FTRACE_CLOCK_UNSPECIFIED. 99 optional int64 boot_timestamp = 7; 100 101 // Errors encountered during parsing of the raw ftrace data. In case of ring 102 // buffer layout errors, the parser skips the rest of the offending kernel 103 // buffer page and continues from the next page. 104 // See also FtraceStats.ftrace_parse_errors, which collates all unique errors 105 // seen within the duration of the trace (even if the affected bundles get 106 // overwritten in ring buffer mode). 107 message FtraceError { 108 // Timestamp of the data that we're unable to parse, in the ftrace clock 109 // domain. Currently, we use the base timestamp of the tracing page 110 // containing the bad record rather than the time of the record itself. 111 optional uint64 timestamp = 1; 112 optional FtraceParseStatus status = 2; 113 } 114 repeated FtraceError error = 8; 115 116 // Superseded by |previous_bundle_end_timestamp| in perfetto v47+. The 117 // primary difference is that this field tracked the last timestamp read from 118 // the per-cpu buffer, while the newer field tracks events that get 119 // serialised into the trace. 120 // Added in: perfetto v44. 121 optional uint64 last_read_event_timestamp = 9; 122 123 // The timestamp (using ftrace clock) of the last event written into this 124 // data source on this cpu. In other words: the last event in the previous 125 // bundle. 126 // Lets the trace processing find an initial timestamp after which ftrace 127 // data is known to be valid across all cpus. Of particular importance when 128 // the perfetto trace buffer is a ring buffer as well, as the overwriting of 129 // oldest bundles can skew the first valid timestamp per cpu significantly. 130 // Added in: perfetto v47. 131 optional uint64 previous_bundle_end_timestamp = 10; 132} 133 134enum FtraceClock { 135 // There is no FTRACE_CLOCK_BOOT entry as that's the default assumption. When 136 // the ftrace clock is "boot", it's just omitted (so UNSPECIFIED == BOOT). 137 FTRACE_CLOCK_UNSPECIFIED = 0; 138 FTRACE_CLOCK_UNKNOWN = 1; 139 FTRACE_CLOCK_GLOBAL = 2; 140 FTRACE_CLOCK_LOCAL = 3; 141 FTRACE_CLOCK_MONO_RAW = 4; 142} 143