1/* 2 * Copyright (C) 2018 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// Statistics for the internals of the tracing service. 22// 23// Next id: 19. 24message TraceStats { 25 // From TraceBuffer::Stats. 26 // 27 // Next id: 21. 28 message BufferStats { 29 // Size of the circular buffer in bytes. 30 optional uint64 buffer_size = 12; 31 32 // Num. bytes written into the circular buffer, including chunk headers. 33 optional uint64 bytes_written = 1; 34 35 // Num. bytes overwritten before they have been read (i.e. loss of data). 36 optional uint64 bytes_overwritten = 13; 37 38 // Total size of chunks that were fully read from the circular buffer by the 39 // consumer. This may not be equal to |bytes_written| either in the middle 40 // of tracing, or if |chunks_overwritten| is non-zero. Note that this is the 41 // size of the chunks read from the buffer, including chunk headers, which 42 // will be different from the total size of packets returned to the 43 // consumer. 44 // 45 // The current utilization of the trace buffer (mid-tracing) can be obtained 46 // by subtracting |bytes_read| and |bytes_overwritten| from |bytes_written|, 47 // adding the difference of |padding_bytes_written| and 48 // |padding_bytes_cleared|, and comparing this sum to the |buffer_size|. 49 // Note that this represents the total size of buffered data in the buffer, 50 // yet this data may be spread non-contiguously through the buffer and may 51 // be overridden before the utilization reaches 100%. 52 optional uint64 bytes_read = 14; 53 54 // Num. bytes that were allocated as padding between chunks in the circular 55 // buffer. 56 optional uint64 padding_bytes_written = 15; 57 58 // Num. of padding bytes that were removed from the circular buffer when 59 // they were overwritten. 60 // 61 // The difference between |padding_bytes_written| and 62 // |padding_bytes_cleared| denotes the total size of padding currently 63 // present in the buffer. 64 optional uint64 padding_bytes_cleared = 16; 65 66 // Num. chunks (!= packets) written into the buffer. 67 optional uint64 chunks_written = 2; 68 69 // Num. chunks (!= packets) rewritten into the buffer. This means we rewrote 70 // the same chunk with additional packets appended to the end. 71 optional uint64 chunks_rewritten = 10; 72 73 // Num. chunks overwritten before they have been read (i.e. loss of data). 74 optional uint64 chunks_overwritten = 3; 75 76 // Num. chunks discarded (i.e. loss of data). Can be > 0 only when a buffer 77 // is configured with FillPolicy == DISCARD. 78 optional uint64 chunks_discarded = 18; 79 80 // Num. chunks (!= packets) that were fully read from the circular buffer by 81 // the consumer. This may not be equal to |chunks_written| either in the 82 // middle of tracing, or if |chunks_overwritten| is non-zero. 83 optional uint64 chunks_read = 17; 84 85 // Num. chunks that were committed out of order. 86 optional uint64 chunks_committed_out_of_order = 11; 87 88 // Num. times the ring buffer wrapped around. 89 optional uint64 write_wrap_count = 4; 90 91 // Num. out-of-band (OOB) patches that succeeded. 92 optional uint64 patches_succeeded = 5; 93 94 // Num. OOB patches that failed (e.g., the chunk to patch was gone). 95 optional uint64 patches_failed = 6; 96 97 // Num. readaheads (for large multi-chunk packet reads) that ended up in a 98 // successful packet read. 99 optional uint64 readaheads_succeeded = 7; 100 101 // Num. readaheads aborted because of missing chunks in the sequence stream. 102 // Note that a small number > 0 is totally expected: occasionally, when 103 // issuing a read, the very last packet in a sequence might be incomplete 104 // (because the producer is still writing it while we read). The read will 105 // stop at that point, for that sequence, increasing this counter. 106 optional uint64 readaheads_failed = 8; 107 108 // Num. of violations of the SharedMemoryABI found while writing or reading 109 // the buffer. This is an indication of either a bug in the producer(s) or 110 // malicious producer(s). 111 optional uint64 abi_violations = 9; 112 113 // The fields below have been introduced in Android R. 114 115 // Num. of times the service detected packet loss on a trace writer 116 // sequence. This is usually caused by exhaustion of available chunks in the 117 // writer process's SMB. Note that this relies on the client's TraceWriter 118 // indicating this loss to the service -- packets lost for other reasons are 119 // not reflected in this stat. 120 optional uint64 trace_writer_packet_loss = 19; 121 } 122 123 // Stats for the TraceBuffer(s) of the current trace session. 124 repeated BufferStats buffer_stats = 1; 125 126 // Per TraceWriter stat. Each {producer, trace writer} tuple is publicly 127 // visible as a unique sequence ID in the trace. 128 message WriterStats { 129 // This matches the TracePacket.trusted_packet_sequence_id and is used to 130 // correlate the stats with the actual packet types. 131 optional uint64 sequence_id = 1; 132 133 // The buffer index (0..N, as defined in the TraceConfig). 134 optional uint32 buffer = 4; 135 136 // These two arrays have the same cardinality and match the cardinality of 137 // chunk_payload_histogram_def + 1 (for the overflow bucket, see below). 138 // `sum` contains the SUM(entries) and `counts` contains the COUNT(entries) 139 // for each bucket. 140 repeated uint64 chunk_payload_histogram_counts = 2 [packed = true]; 141 repeated int64 chunk_payload_histogram_sum = 3 [packed = true]; 142 } 143 144 // The thresholds of each the `writer_stats` histogram buckets. This is 145 // emitted only once as all WriterStats share the same bucket layout. 146 // This field has the same cardinality of the 147 // `writer_stats.chunk_payload_histogram_{counts,sum}` - 1. 148 // (The -1 is because the last overflow bucket is not reported in the _def). 149 // An array of values [10, 100, 1000] in the _def array means that there are 150 // four buckets (3 + the implicit overflow bucket): 151 // [0]: x <= 10; [1]: 100 < x <= 1000; [2]: 1000 < x <= 1000; [3]: x > 1000. 152 repeated int64 chunk_payload_histogram_def = 17; 153 repeated WriterStats writer_stats = 18; 154 155 // Num. producers connected (whether they are involved in the current tracing 156 // session or not). 157 optional uint32 producers_connected = 2; 158 159 // Num. producers ever seen for all trace sessions since startup (it's a good 160 // proxy for inferring num. producers crashed / killed). 161 optional uint64 producers_seen = 3; 162 163 // Num. data sources registered for all trace sessions. 164 optional uint32 data_sources_registered = 4; 165 166 // Num. data sources ever seen for all trace sessions since startup. 167 optional uint64 data_sources_seen = 5; 168 169 // Num. concurrently active tracing sessions. 170 optional uint32 tracing_sessions = 6; 171 172 // Num. buffers for all tracing session (not just the current one). This will 173 // be >= buffer_stats.size(), because the latter is only about the current 174 // session. 175 optional uint32 total_buffers = 7; 176 177 // The fields below have been introduced in Android Q. 178 179 // Num. chunks that were discarded by the service before attempting to commit 180 // them to a buffer, e.g. because the producer specified an invalid buffer ID. 181 optional uint64 chunks_discarded = 8; 182 183 // Num. patches that were discarded by the service before attempting to apply 184 // them to a buffer, e.g. because the producer specified an invalid buffer ID. 185 optional uint64 patches_discarded = 9; 186 187 // Packets that failed validation of the TrustedPacket. If this is > 0, there 188 // is a bug in the producer. 189 optional uint64 invalid_packets = 10; 190 191 // This is set only when the TraceConfig specifies a TraceFilter. 192 message FilterStats { 193 optional uint64 input_packets = 1; 194 optional uint64 input_bytes = 2; 195 optional uint64 output_bytes = 3; 196 optional uint64 errors = 4; 197 optional uint64 time_taken_ns = 5; 198 199 // The number of bytes discarded by the filter (i.e. output - input). 200 // The array has one entry for each buffer defined in the config (unless no 201 // packets for that buffer were seen and hence filtered). 202 // Note: the SUM(bytes_discarded_per_buffer) will be <= but not == the total 203 // (output_bytes - input_bytes) because the filter might also discard 204 // server-generated synthetic packets, that have no buffer index. 205 repeated uint64 bytes_discarded_per_buffer = 20; 206 } 207 optional FilterStats filter_stats = 11; 208 209 // Count of Flush() requests (either from the Consumer, or self-induced 210 // periodic flushes). The final Flush() is also included in the count. 211 optional uint64 flushes_requested = 12; 212 213 // The count of the Flush() requests that were completed successfully. 214 // In a well behaving trace this should always be == `flush_requests`. 215 optional uint64 flushes_succeeded = 13; 216 217 // The count of the Flush() requests that failed (in most timed out). 218 // In a well behaving trace this should always be == 0. 219 optional uint64 flushes_failed = 14; 220 221 enum FinalFlushOutcome { 222 FINAL_FLUSH_UNSPECIFIED = 0; 223 FINAL_FLUSH_SUCCEEDED = 1; 224 FINAL_FLUSH_FAILED = 2; 225 } 226 optional FinalFlushOutcome final_flush_outcome = 15; 227} 228