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