• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  TRACE_PROCESSOR_CURRENT_API_VERSION = 12;
63}
64
65// At lowest level, the wire-format of the RPC protocol is a linear sequence of
66// TraceProcessorRpc messages on each side of the byte pipe
67// Each message is prefixed by a tag (field = 1, type = length delimited) and a
68// varint encoding its size (this is so the whole stream can also be read /
69// written as if it was a repeated field of TraceProcessorRpcStream).
70
71message TraceProcessorRpcStream {
72  repeated TraceProcessorRpc msg = 1;
73}
74
75message TraceProcessorRpc {
76  // A monotonic counter used only for debugging purposes, to detect if the
77  // underlying stream is missing or duping data. The counter starts at 0 on
78  // each side of the pipe and is incremented on each message.
79  // Do NOT expect that a response has the same |seq| of its corresponding
80  // request: some requests (e.g., a query returning many rows) can yield more
81  // than one response message, bringing the tx and rq seq our of sync.
82  optional int64 seq = 1;
83
84  // This is returned when some unrecoverable error has been detected by the
85  // peer. The typical case is TraceProcessor detecting that the |seq| sequence
86  // is broken (e.g. when having two tabs open with the same --httpd instance).
87  optional string fatal_error = 5;
88
89  enum TraceProcessorMethod {
90    TPM_UNSPECIFIED = 0;
91    TPM_APPEND_TRACE_DATA = 1;
92    TPM_FINALIZE_TRACE_DATA = 2;
93    TPM_QUERY_STREAMING = 3;
94    // Previously: TPM_QUERY_RAW_DEPRECATED
95    reserved 4;
96    reserved "TPM_QUERY_RAW_DEPRECATED";
97    TPM_COMPUTE_METRIC = 5;
98    TPM_GET_METRIC_DESCRIPTORS = 6;
99    TPM_RESTORE_INITIAL_TABLES = 7;
100    TPM_ENABLE_METATRACE = 8;
101    TPM_DISABLE_AND_READ_METATRACE = 9;
102    TPM_GET_STATUS = 10;
103    TPM_RESET_TRACE_PROCESSOR = 11;
104  }
105
106  oneof type {
107    // Client -> TraceProcessor requests.
108    TraceProcessorMethod request = 2;
109
110    // TraceProcessor -> Client responses.
111    TraceProcessorMethod response = 3;
112
113    // This is sent back instead of filling |response| when the client sends a
114    // |request| which is not known by the TraceProcessor service. This can
115    // happen when the client is newer than the service.
116    TraceProcessorMethod invalid_request = 4;
117  }
118
119  // Request/Response arguments.
120  // Not all requests / responses require an argument.
121
122  oneof args {
123    // TraceProcessorMethod request args.
124
125    // For TPM_APPEND_TRACE_DATA.
126    bytes append_trace_data = 101;
127    // For TPM_QUERY_STREAMING.
128    QueryArgs query_args = 103;
129    // For TPM_COMPUTE_METRIC.
130    ComputeMetricArgs compute_metric_args = 105;
131    // For TPM_ENABLE_METATRACE.
132    EnableMetatraceArgs enable_metatrace_args = 106;
133    // For TPM_RESET_TRACE_PROCESSOR.
134    ResetTraceProcessorArgs reset_trace_processor_args = 107;
135
136    // TraceProcessorMethod response args.
137    // For TPM_APPEND_TRACE_DATA.
138    AppendTraceDataResult append_result = 201;
139    // For TPM_QUERY_STREAMING.
140    QueryResult query_result = 203;
141    // For TPM_COMPUTE_METRIC.
142    ComputeMetricResult metric_result = 205;
143    // For TPM_GET_METRIC_DESCRIPTORS.
144    DescriptorSet metric_descriptors = 206;
145    // For TPM_DISABLE_AND_READ_METATRACE.
146    DisableAndReadMetatraceResult metatrace = 209;
147    // For TPM_GET_STATUS.
148    StatusResult status = 210;
149  }
150
151  // Previously: RawQueryArgs for TPM_QUERY_RAW_DEPRECATED
152  reserved 104;
153  // Previously: RawQueryResult for TPM_QUERY_RAW_DEPRECATED
154  reserved 204;
155}
156
157message AppendTraceDataResult {
158  optional int64 total_bytes_parsed = 1;
159  optional string error = 2;
160}
161
162message QueryArgs {
163  optional string sql_query = 1;
164  // Was time_queued_ns
165  reserved 2;
166  // Optional string to tag this query with for performance diagnostic purposes.
167  optional string tag = 3;
168}
169
170// Output for the /query endpoint.
171// Returns a query result set, grouping cells into batches. Batching allows a
172// more efficient encoding of results, at the same time allowing to return
173// O(M) results in a pipelined fashion, without full-memory buffering.
174// Batches are split when either a large number of cells (~thousands) is reached
175// or the string/blob payload becomes too large (~hundreds of KB).
176// Data is batched in cells, scanning results by row -> column. e.g. if a query
177// returns 3 columns and 2 rows, the cells will be emitted in this order:
178// R0C0, R0C1, R0C2, R1C0, R1C1, R1C2.
179message QueryResult {
180  // This determines the number and names of columns.
181  repeated string column_names = 1;
182
183  // If non-emty the query returned an error. Note that some cells might still
184  // be present, if the error happened while iterating.
185  optional string error = 2;
186
187  // A batch contains an array of cell headers, stating the type of each cell.
188  // The payload of each cell is stored in the corresponding xxx_cells field
189  // below (unless the cell is NULL).
190  // So if |cells| contains: [VARINT, FLOAT64, VARINT, STRING], the results will
191  // be available as:
192  // [varint_cells[0], float64_cells[0], varint_cells[1], string_cells[0]].
193  message CellsBatch {
194    enum CellType {
195      CELL_INVALID = 0;
196      CELL_NULL = 1;
197      CELL_VARINT = 2;
198      CELL_FLOAT64 = 3;
199      CELL_STRING = 4;
200      CELL_BLOB = 5;
201    }
202    repeated CellType cells = 1 [packed = true];
203
204    repeated int64 varint_cells = 2 [packed = true];
205    repeated double float64_cells = 3 [packed = true];
206    repeated bytes blob_cells = 4;
207
208    // The string cells are concatenated in a single field. Each cell is
209    // NUL-terminated. This is because JS incurs into a non-negligible overhead
210    // when decoding strings and one decode + split('\0') is measurably faster
211    // than decoding N strings. See goto.google.com/postmessage-benchmark .
212    optional string string_cells = 5;
213
214    // If true this is the last batch for the query result.
215    optional bool is_last_batch = 6;
216
217    // Padding field. Used only to re-align and fill gaps in the binary format.
218    reserved 7;
219  }
220  repeated CellsBatch batch = 3;
221
222  // The number of statements in the provided SQL.
223  optional uint32 statement_count = 4;
224
225  // The number of statements which produced output rows in the provided SQL.
226  optional uint32 statement_with_output_count = 5;
227
228  // The last statement in the provided SQL.
229  optional string last_statement_sql = 6;
230}
231
232// Input for the /status endpoint.
233message StatusArgs {}
234
235// Output for the /status endpoint.
236message StatusResult {
237  // If present and not empty, a trace is already loaded already. This happens
238  // when using the HTTP+RPC mode nad passing a trace file to the shell, via
239  // trace_processor_shell -D trace_file.pftrace .
240  optional string loaded_trace_name = 1;
241
242  // Typically something like "v11.0.123", but could be just "v11" or "unknown",
243  // for binaries built from Bazel or other build configurations. This is for
244  // human presentation only, don't attempt to parse and reason on it.
245  optional string human_readable_version = 2;
246
247  // The API version is incremented every time a change that the UI depends
248  // on is introduced (e.g. adding a new table that the UI queries).
249  optional int32 api_version = 3;
250
251  // Typically something like "v42.1-deadbeef0", but could be just
252  // "v42", "v0.0", or unset for binaries built from Bazel or other
253  // build configurations. This can be compared with equality to other
254  // version codes to detect matched builds (for example to see if
255  // trace_processor_shell and the UI were built at the same revision)
256  // but you should not attempt to parse it as the format may change
257  // without warning.
258  optional string version_code = 4;
259}
260
261// Input for the /compute_metric endpoint.
262message ComputeMetricArgs {
263  enum ResultFormat {
264    BINARY_PROTOBUF = 0;
265    TEXTPROTO = 1;
266    JSON = 2;
267  }
268  repeated string metric_names = 1;
269  optional ResultFormat format = 2;
270}
271
272// Output for the /compute_metric endpoint.
273message ComputeMetricResult {
274  oneof result {
275    // This is meant to contain a perfetto.protos.TraceMetrics. We're using
276    // bytes instead of the actual type because we do not want to generate
277    // protozero code for the metrics protos. We always encode/decode metrics
278    // using a reflection based mechanism that does not require the compiled C++
279    // code. This allows us to read in new protos at runtime.
280    bytes metrics = 1;
281
282    // A perfetto.protos.TraceMetrics formatted as prototext.
283    string metrics_as_prototext = 3;
284
285    // A perfetto.protos.TraceMetrics formatted as json.
286    string metrics_as_json = 4;
287  }
288
289  optional string error = 2;
290}
291
292// Input for the /enable_metatrace endpoint.
293message EnableMetatraceArgs {
294  optional MetatraceCategories categories = 1;
295}
296
297// Output for the /enable_metatrace endpoint.
298message EnableMetatraceResult {}
299
300// Input for the /disable_and_read_metatrace endpoint.
301message DisableAndReadMetatraceArgs {}
302
303// Output for the /disable_and_read_metatrace endpoint.
304message DisableAndReadMetatraceResult {
305  // Bytes of perfetto.protos.Trace message. Stored as bytes
306  // to avoid adding a dependency on trace.proto.
307  optional bytes metatrace = 1;
308  optional string error = 2;
309}
310
311// Convenience wrapper for multiple descriptors, similar to FileDescriptorSet
312// in descriptor.proto.
313message DescriptorSet {
314  repeated DescriptorProto descriptors = 1;
315}
316
317// Input for setting Trace Processor config. This method works only in the WASM
318// mode. trace_processor_shell supports configuration through command line
319// flags.
320message ResetTraceProcessorArgs {
321  enum DropTrackEventDataBefore {
322    NO_DROP = 0;
323    TRACK_EVENT_RANGE_OF_INTEREST = 1;
324  }
325  // Mirror of the corresponding perfetto::trace_processor::Config fields.
326  optional DropTrackEventDataBefore drop_track_event_data_before = 1;
327  optional bool ingest_ftrace_in_raw_table = 2;
328  optional bool analyze_trace_proto_content = 3;
329  optional bool ftrace_drop_until_all_cpus_valid = 4;
330}
331