xref: /aosp_15_r20/external/perfetto/protos/perfetto/trace_processor/trace_processor.proto (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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
21import "protos/perfetto/common/descriptor.proto";
22import "protos/perfetto/trace_processor/metatrace_categories.proto";
23
24// This file defines the schema for {,un}marshalling arguments and return values
25// when interfacing to the trace processor binary interface.
26
27// The Trace Processor can be used in three modes:
28// 1. Fully native from C++ or directly using trace_processor_shell.
29//    In this case, this file isn't really relevant because no binary
30//    marshalling is involved. Look at include/trace_processor/trace_processor.h
31//    for the public C++ API definition.
32// 2. Using WASM within the HTML ui. In this case these messages are used to
33//    {,un}marshall calls made through the JS<>WASM interop in
34//    src/trace_processor/rpc/wasm_bridge.cc .
35// 3. Using the HTTP+RPC interface, by running trace_processor_shell -D.
36//    In this case these messages are used to {,un}marshall HTTP requests and
37//    response made through src/trace_processor/rpc/httpd.cc .
38
39enum TraceProcessorApiVersion {
40  // This variable has been introduced in v15 and is used to deal with API
41  // mismatches between UI and trace_processor_shell --httpd.
42  //
43  // Prior to API version 11 this was incremented every time a new
44  // feature that the UI depended on was introduced (e.g. new tables,
45  // new SQL operators, metrics that are required by the UI, etc).
46  // This:
47  // a. Tended to be forgotten
48  // b. Still led to issues when the TP dropped *backwards*
49  //    compatibility of a feature (since we checked TP >= UI
50  //    TRACE_PROCESSOR_CURRENT_API_VERSION).
51  // Now the UI attempts to redirect the user to the matched version
52  // of the UI if one exists.
53  // See also StatusResult.api_version (below).
54  // Changes:
55  // 7. Introduce GUESS_CPU_SIZE
56  // 8. Add 'json' option to ComputeMetricArgs
57  // 9. Add get_thread_state_summary_for_interval.
58  // 10. Add 'slice_is_ancestor' to stdlib.
59  // 11. Removal of experimental module from stdlib.
60  // 12. Changed UI to be more aggresive about version matching.
61  //     Added version_code.
62  // 13. Added TPM_REGISTER_SQL_MODULE method.
63  // 14. Added parsing mode option to RESET method.
64  TRACE_PROCESSOR_CURRENT_API_VERSION = 14;
65}
66
67// At lowest level, the wire-format of the RPC protocol is a linear sequence of
68// TraceProcessorRpc messages on each side of the byte pipe
69// Each message is prefixed by a tag (field = 1, type = length delimited) and a
70// varint encoding its size (this is so the whole stream can also be read /
71// written as if it was a repeated field of TraceProcessorRpcStream).
72
73message TraceProcessorRpcStream {
74  repeated TraceProcessorRpc msg = 1;
75}
76
77message TraceProcessorRpc {
78  // A monotonic counter used only for debugging purposes, to detect if the
79  // underlying stream is missing or duping data. The counter starts at 0 on
80  // each side of the pipe and is incremented on each message.
81  // Do NOT expect that a response has the same |seq| of its corresponding
82  // request: some requests (e.g., a query returning many rows) can yield more
83  // than one response message, bringing the tx and rq seq our of sync.
84  optional int64 seq = 1;
85
86  // This is returned when some unrecoverable error has been detected by the
87  // peer. The typical case is TraceProcessor detecting that the |seq| sequence
88  // is broken (e.g. when having two tabs open with the same --httpd instance).
89  optional string fatal_error = 5;
90
91  enum TraceProcessorMethod {
92    reserved 4, 12;
93    reserved "TPM_QUERY_RAW_DEPRECATED";
94    reserved "TPM_REGISTER_SQL_MODULE";
95
96    TPM_UNSPECIFIED = 0;
97    TPM_APPEND_TRACE_DATA = 1;
98    TPM_FINALIZE_TRACE_DATA = 2;
99    TPM_QUERY_STREAMING = 3;
100    // Previously: TPM_QUERY_RAW_DEPRECATED
101    TPM_COMPUTE_METRIC = 5;
102    TPM_GET_METRIC_DESCRIPTORS = 6;
103    TPM_RESTORE_INITIAL_TABLES = 7;
104    TPM_ENABLE_METATRACE = 8;
105    TPM_DISABLE_AND_READ_METATRACE = 9;
106    TPM_GET_STATUS = 10;
107    TPM_RESET_TRACE_PROCESSOR = 11;
108    TPM_REGISTER_SQL_PACKAGE = 13;
109  }
110
111  oneof type {
112    // Client -> TraceProcessor requests.
113    TraceProcessorMethod request = 2;
114
115    // TraceProcessor -> Client responses.
116    TraceProcessorMethod response = 3;
117
118    // This is sent back instead of filling |response| when the client sends a
119    // |request| which is not known by the TraceProcessor service. This can
120    // happen when the client is newer than the service.
121    TraceProcessorMethod invalid_request = 4;
122  }
123
124  // Request/Response arguments.
125  // Not all requests / responses require an argument.
126
127  oneof args {
128    // TraceProcessorMethod request args.
129
130    // For TPM_APPEND_TRACE_DATA.
131    bytes append_trace_data = 101;
132    // For TPM_QUERY_STREAMING.
133    QueryArgs query_args = 103;
134    // For TPM_COMPUTE_METRIC.
135    ComputeMetricArgs compute_metric_args = 105;
136    // For TPM_ENABLE_METATRACE.
137    EnableMetatraceArgs enable_metatrace_args = 106;
138    // For TPM_RESET_TRACE_PROCESSOR.
139    ResetTraceProcessorArgs reset_trace_processor_args = 107;
140    // For TPM_REGISTER_SQL_PACKAGE.
141    RegisterSqlPackageArgs register_sql_package_args = 108;
142
143    // TraceProcessorMethod response args.
144    // For TPM_APPEND_TRACE_DATA.
145    AppendTraceDataResult append_result = 201;
146    // For TPM_QUERY_STREAMING.
147    QueryResult query_result = 203;
148    // For TPM_COMPUTE_METRIC.
149    ComputeMetricResult metric_result = 205;
150    // For TPM_GET_METRIC_DESCRIPTORS.
151    DescriptorSet metric_descriptors = 206;
152    // For TPM_DISABLE_AND_READ_METATRACE.
153    DisableAndReadMetatraceResult metatrace = 209;
154    // For TPM_GET_STATUS.
155    StatusResult status = 210;
156    // For TPM_REGISTER_SQL_PACKAGE.
157    RegisterSqlPackageResult register_sql_package_result = 211;
158    // For TPM_FINALIZE_TRACE_DATA.
159    FinalizeDataResult finalize_data_result = 212;
160  }
161
162  // Previously: RawQueryArgs for TPM_QUERY_RAW_DEPRECATED
163  reserved 104;
164  // Previously: RawQueryResult for TPM_QUERY_RAW_DEPRECATED
165  reserved 204;
166}
167
168message AppendTraceDataResult {
169  optional int64 total_bytes_parsed = 1;
170  optional string error = 2;
171}
172
173message QueryArgs {
174  optional string sql_query = 1;
175  // Was time_queued_ns
176  reserved 2;
177  // Optional string to tag this query with for performance diagnostic purposes.
178  optional string tag = 3;
179}
180
181// Output for the /query endpoint.
182// Returns a query result set, grouping cells into batches. Batching allows a
183// more efficient encoding of results, at the same time allowing to return
184// O(M) results in a pipelined fashion, without full-memory buffering.
185// Batches are split when either a large number of cells (~thousands) is reached
186// or the string/blob payload becomes too large (~hundreds of KB).
187// Data is batched in cells, scanning results by row -> column. e.g. if a query
188// returns 3 columns and 2 rows, the cells will be emitted in this order:
189// R0C0, R0C1, R0C2, R1C0, R1C1, R1C2.
190message QueryResult {
191  // This determines the number and names of columns.
192  repeated string column_names = 1;
193
194  // If non-emty the query returned an error. Note that some cells might still
195  // be present, if the error happened while iterating.
196  optional string error = 2;
197
198  // A batch contains an array of cell headers, stating the type of each cell.
199  // The payload of each cell is stored in the corresponding xxx_cells field
200  // below (unless the cell is NULL).
201  // So if |cells| contains: [VARINT, FLOAT64, VARINT, STRING], the results will
202  // be available as:
203  // [varint_cells[0], float64_cells[0], varint_cells[1], string_cells[0]].
204  message CellsBatch {
205    enum CellType {
206      CELL_INVALID = 0;
207      CELL_NULL = 1;
208      CELL_VARINT = 2;
209      CELL_FLOAT64 = 3;
210      CELL_STRING = 4;
211      CELL_BLOB = 5;
212    }
213    repeated CellType cells = 1 [packed = true];
214
215    repeated int64 varint_cells = 2 [packed = true];
216    repeated double float64_cells = 3 [packed = true];
217    repeated bytes blob_cells = 4;
218
219    // The string cells are concatenated in a single field. Each cell is
220    // NUL-terminated. This is because JS incurs into a non-negligible overhead
221    // when decoding strings and one decode + split('\0') is measurably faster
222    // than decoding N strings. See goto.google.com/postmessage-benchmark .
223    optional string string_cells = 5;
224
225    // If true this is the last batch for the query result.
226    optional bool is_last_batch = 6;
227
228    // Padding field. Used only to re-align and fill gaps in the binary format.
229    reserved 7;
230  }
231  repeated CellsBatch batch = 3;
232
233  // The number of statements in the provided SQL.
234  optional uint32 statement_count = 4;
235
236  // The number of statements which produced output rows in the provided SQL.
237  optional uint32 statement_with_output_count = 5;
238
239  // The last statement in the provided SQL.
240  optional string last_statement_sql = 6;
241}
242
243// Input for the /status endpoint.
244message StatusArgs {}
245
246// Output for the /status endpoint.
247message StatusResult {
248  // If present and not empty, a trace is already loaded already. This happens
249  // when using the HTTP+RPC mode nad passing a trace file to the shell, via
250  // trace_processor_shell -D trace_file.pftrace .
251  optional string loaded_trace_name = 1;
252
253  // Typically something like "v11.0.123", but could be just "v11" or "unknown",
254  // for binaries built from Bazel or other build configurations. This is for
255  // human presentation only, don't attempt to parse and reason on it.
256  optional string human_readable_version = 2;
257
258  // The API version is incremented every time a change that the UI depends
259  // on is introduced (e.g. adding a new table that the UI queries).
260  optional int32 api_version = 3;
261
262  // Typically something like "v42.1-deadbeef0", but could be just
263  // "v42", "v0.0", or unset for binaries built from Bazel or other
264  // build configurations. This can be compared with equality to other
265  // version codes to detect matched builds (for example to see if
266  // trace_processor_shell and the UI were built at the same revision)
267  // but you should not attempt to parse it as the format may change
268  // without warning.
269  optional string version_code = 4;
270}
271
272// Input for the /compute_metric endpoint.
273message ComputeMetricArgs {
274  enum ResultFormat {
275    BINARY_PROTOBUF = 0;
276    TEXTPROTO = 1;
277    JSON = 2;
278  }
279  repeated string metric_names = 1;
280  optional ResultFormat format = 2;
281}
282
283// Output for the /compute_metric endpoint.
284message ComputeMetricResult {
285  oneof result {
286    // This is meant to contain a perfetto.protos.TraceMetrics. We're using
287    // bytes instead of the actual type because we do not want to generate
288    // protozero code for the metrics protos. We always encode/decode metrics
289    // using a reflection based mechanism that does not require the compiled C++
290    // code. This allows us to read in new protos at runtime.
291    bytes metrics = 1;
292
293    // A perfetto.protos.TraceMetrics formatted as prototext.
294    string metrics_as_prototext = 3;
295
296    // A perfetto.protos.TraceMetrics formatted as json.
297    string metrics_as_json = 4;
298  }
299
300  optional string error = 2;
301}
302
303// Input for the /enable_metatrace endpoint.
304message EnableMetatraceArgs {
305  optional MetatraceCategories categories = 1;
306}
307
308// Output for the /enable_metatrace endpoint.
309message EnableMetatraceResult {}
310
311// Input for the /disable_and_read_metatrace endpoint.
312message DisableAndReadMetatraceArgs {}
313
314// Output for the /disable_and_read_metatrace endpoint.
315message DisableAndReadMetatraceResult {
316  // Bytes of perfetto.protos.Trace message. Stored as bytes
317  // to avoid adding a dependency on trace.proto.
318  optional bytes metatrace = 1;
319  optional string error = 2;
320}
321
322// Convenience wrapper for multiple descriptors, similar to FileDescriptorSet
323// in descriptor.proto.
324message DescriptorSet {
325  repeated DescriptorProto descriptors = 1;
326}
327
328// Input for setting Trace Processor config. This method works only in the WASM
329// mode. trace_processor_shell supports configuration through command line
330// flags.
331message ResetTraceProcessorArgs {
332  enum DropTrackEventDataBefore {
333    NO_DROP = 0;
334    TRACK_EVENT_RANGE_OF_INTEREST = 1;
335  }
336  enum ParsingMode {
337    DEFAULT = 0;
338    TOKENIZE_ONLY = 1;
339    TOKENIZE_AND_SORT = 2;
340  }
341  // Mirror of the corresponding perfetto::trace_processor::Config fields.
342  optional DropTrackEventDataBefore drop_track_event_data_before = 1;
343  optional bool ingest_ftrace_in_raw_table = 2;
344  optional bool analyze_trace_proto_content = 3;
345  optional bool ftrace_drop_until_all_cpus_valid = 4;
346  optional ParsingMode parsing_mode = 5;
347}
348
349message RegisterSqlPackageArgs {
350  message Module {
351    optional string name = 1;
352    optional string sql = 2;
353  }
354  optional string package_name = 1;
355  repeated Module modules = 2;
356  optional bool allow_override = 3;
357}
358
359message RegisterSqlPackageResult {
360  optional string error = 1;
361}
362
363message FinalizeDataResult {
364  optional string error = 1;
365}
366