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: 11.
24message TraceStats {
25  // From TraceBuffer::Stats.
26  //
27  // Next id: 20.
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  // Num. producers connected (whether they are involved in the current tracing
127  // session or not).
128  optional uint32 producers_connected = 2;
129
130  // Num. producers ever seen for all trace sessions since startup (it's a good
131  // proxy for inferring num. producers crashed / killed).
132  optional uint64 producers_seen = 3;
133
134  // Num. data sources registered for all trace sessions.
135  optional uint32 data_sources_registered = 4;
136
137  // Num. data sources ever seen for all trace sessions since startup.
138  optional uint64 data_sources_seen = 5;
139
140  // Num. concurrently active tracing sessions.
141  optional uint32 tracing_sessions = 6;
142
143  // Num. buffers for all tracing session (not just the current one). This will
144  // be >= buffer_stats.size(), because the latter is only about the current
145  // session.
146  optional uint32 total_buffers = 7;
147
148  // The fields below have been introduced in Android Q.
149
150  // Num. chunks that were discarded by the service before attempting to commit
151  // them to a buffer, e.g. because the producer specified an invalid buffer ID.
152  optional uint64 chunks_discarded = 8;
153
154  // Num. patches that were discarded by the service before attempting to apply
155  // them to a buffer, e.g. because the producer specified an invalid buffer ID.
156  optional uint64 patches_discarded = 9;
157
158  // Packets that failed validation of the TrustedPacket. If this is > 0, there
159  // is a bug in the producer.
160  optional uint64 invalid_packets = 10;
161
162  // This is set only when the TraceConfig specifies a TraceFilter.
163  message FilterStats {
164    optional uint64 input_packets = 1;
165    optional uint64 input_bytes = 2;
166    optional uint64 output_bytes = 3;
167    optional uint64 errors = 4;
168  }
169  optional FilterStats filter_stats = 11;
170}
171