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"; 22 23// This file defines the schema for {,un}marshalling arguments and return values 24// when interfacing to the trace processor binary interface. 25 26// The Trace Processor can be used in three modes: 27// 1. Fully native from C++ or directly using trace_processor_shell. 28// In this case, this file isn't really relevant because no binary 29// marshalling is involved. Look at include/trace_processor/trace_processor.h 30// for the public C++ API definition. 31// 2. Using WASM within the HTML ui. In this case these messages are used to 32// {,un}marshall calls made through the JS<>WASM interop in 33// src/trace_processor/rpc/wasm_bridge.cc . 34// 3. Using the HTTP+RPC interface, by running trace_processor_shell -D. 35// In this case these messages are used to {,un}marshall HTTP requests and 36// response made through src/trace_processor/rpc/httpd.cc . 37 38enum TraceProcessorApiVersion { 39 // This variable has been introduced in v15 and is used to deal with API 40 // mismatches between UI and trace_processor_shell --httpd. Increment this 41 // every time a new feature that the UI depends on is being introduced (e.g. 42 // new tables, new SQL operators, metrics that are required by the UI). 43 // See also TraceProcessorVersion (below). 44 TRACE_PROCESSOR_CURRENT_API_VERSION = 3; 45} 46 47// At lowest level, the wire-format of the RPC procol is a linear sequence of 48// TraceProcessorRpc messages on each side of the byte pipe 49// Each message is prefixed by a tag (field = 1, type = length delimited) and a 50// varint encoding its size (this is so the whole stream can also be read / 51// written as if it was a repeated field of TraceProcessorRpcStream). 52 53message TraceProcessorRpcStream { 54 repeated TraceProcessorRpc msg = 1; 55} 56 57message TraceProcessorRpc { 58 // A monotonic counter used only for debugging purposes, to detect if the 59 // underlying stream is missing or duping data. The counter starts at 0 on 60 // each side of the pipe and is incremented on each message. 61 // Do NOT expect that a response has the same |seq| of its corresponding 62 // request: some requests (e.g., a query returning many rows) can yield more 63 // than one response message, bringing the tx and rq seq our of sync. 64 optional int64 seq = 1; 65 66 // This is returned when some unrecoverable error has been detected by the 67 // peer. The typical case is TraceProcessor detecting that the |seq| sequence 68 // is broken (e.g. when having two tabs open with the same --httpd instance). 69 optional string fatal_error = 5; 70 71 enum TraceProcessorMethod { 72 TPM_UNSPECIFIED = 0; 73 TPM_APPEND_TRACE_DATA = 1; 74 TPM_FINALIZE_TRACE_DATA = 2; 75 TPM_QUERY_STREAMING = 3; 76 TPM_QUERY_RAW_DEPRECATED = 4; 77 TPM_COMPUTE_METRIC = 5; 78 TPM_GET_METRIC_DESCRIPTORS = 6; 79 TPM_RESTORE_INITIAL_TABLES = 7; 80 TPM_ENABLE_METATRACE = 8; 81 TPM_DISABLE_AND_READ_METATRACE = 9; 82 TPM_GET_STATUS = 10; 83 } 84 85 oneof type { 86 // Client -> TraceProcessor requests. 87 TraceProcessorMethod request = 2; 88 89 // TraceProcessor -> Client responses. 90 TraceProcessorMethod response = 3; 91 92 // This is sent back instead of filling |response| when the client sends a 93 // |request| which is not known by the TraceProcessor service. This can 94 // happen when the client is newer than the service. 95 TraceProcessorMethod invalid_request = 4; 96 } 97 98 // Request/Response arguments. 99 // Not all requests / responses require an argument. 100 101 oneof args { 102 // TraceProcessorMethod request args. 103 104 // For TPM_APPEND_TRACE_DATA. 105 bytes append_trace_data = 101; 106 // For TPM_QUERY_STREAMING. 107 QueryArgs query_args = 103; 108 // For TPM_QUERY_RAW_DEPRECATED. 109 RawQueryArgs raw_query_args = 104; 110 // For TPM_COMPUTE_METRIC. 111 ComputeMetricArgs compute_metric_args = 105; 112 113 // TraceProcessorMethod response args. 114 // For TPM_APPEND_TRACE_DATA. 115 AppendTraceDataResult append_result = 201; 116 // For TPM_QUERY_STREAMING. 117 QueryResult query_result = 203; 118 // For TPM_QUERY_RAW_DEPRECATED. 119 RawQueryResult raw_query_result = 204; 120 // For TPM_COMPUTE_METRIC. 121 ComputeMetricResult metric_result = 205; 122 // For TPM_GET_METRIC_DESCRIPTORS. 123 DescriptorSet metric_descriptors = 206; 124 // For TPM_DISABLE_AND_READ_METATRACE. 125 DisableAndReadMetatraceResult metatrace = 209; 126 // For TPM_GET_STATUS. 127 StatusResult status = 210; 128 } 129} 130 131message AppendTraceDataResult { 132 optional int64 total_bytes_parsed = 1; 133 optional string error = 2; 134} 135 136message QueryArgs { 137 optional string sql_query = 1; 138 139 // Was time_queued_ns 140 reserved 2; 141} 142 143// Input for the /raw_query endpoint. 144message RawQueryArgs { 145 optional string sql_query = 1; 146 147 // Was time_queued_ns 148 reserved 2; 149} 150 151// Output for the /raw_query endpoint. 152// DEPRECATED, use /query. See QueryResult below. 153message RawQueryResult { 154 message ColumnDesc { 155 optional string name = 1; 156 enum Type { 157 UNKNOWN = 0; 158 LONG = 1; 159 DOUBLE = 2; 160 STRING = 3; 161 } 162 optional Type type = 2; 163 } 164 message ColumnValues { 165 // Only one of this field will be filled for each column (according to the 166 // corresponding descriptor) and that one will have precisely |num_records| 167 // elements. 168 repeated int64 long_values = 1; 169 repeated double double_values = 2; 170 repeated string string_values = 3; 171 172 // This will be set to true or false depending on whether the data at the 173 // given index is NULL. 174 repeated bool is_nulls = 4; 175 } 176 repeated ColumnDesc column_descriptors = 1; 177 optional uint64 num_records = 2; 178 repeated ColumnValues columns = 3; 179 optional string error = 4; 180 optional uint64 execution_time_ns = 5; 181} 182 183// Output for the /query endpoint. 184// Returns a query result set, grouping cells into batches. Batching allows a 185// more efficient encoding of results, at the same time allowing to return 186// O(M) results in a pipelined fashion, without full-memory buffering. 187// Batches are split when either a large number of cells (~thousands) is reached 188// or the string/blob payload becomes too large (~hundreds of KB). 189// Data is batched in cells, scanning results by row -> column. e.g. if a query 190// returns 3 columns and 2 rows, the cells will be emitted in this order: 191// R0C0, R0C1, R0C2, R1C0, R1C1, R1C2. 192message QueryResult { 193 // This determines the number and names of columns. 194 repeated string column_names = 1; 195 196 // If non-emty the query returned an error. Note that some cells might still 197 // be present, if the error happened while iterating. 198 optional string error = 2; 199 200 // A batch contains an array of cell headers, stating the type of each cell. 201 // The payload of each cell is stored in the corresponding xxx_cells field 202 // below (unless the cell is NULL). 203 // So if |cells| contains: [VARINT, FLOAT64, VARINT, STRING], the results will 204 // be available as: 205 // [varint_cells[0], float64_cells[0], varint_cells[1], string_cells[0]]. 206 message CellsBatch { 207 enum CellType { 208 CELL_INVALID = 0; 209 CELL_NULL = 1; 210 CELL_VARINT = 2; 211 CELL_FLOAT64 = 3; 212 CELL_STRING = 4; 213 CELL_BLOB = 5; 214 } 215 repeated CellType cells = 1 [packed = true]; 216 217 repeated int64 varint_cells = 2 [packed = true]; 218 repeated double float64_cells = 3 [packed = true]; 219 repeated bytes blob_cells = 4; 220 221 // The string cells are concatenated in a single field. Each cell is 222 // NUL-terminated. This is because JS incurs into a non-negligible overhead 223 // when decoding strings and one decode + split('\0') is measurably faster 224 // than decoding N strings. See goto.google.com/postmessage-benchmark . 225 optional string string_cells = 5; 226 227 // If true this is the last batch for the query result. 228 optional bool is_last_batch = 6; 229 230 // Padding field. Used only to re-align and fill gaps in the binary format. 231 reserved 7; 232 } 233 repeated CellsBatch batch = 3; 234 235 // The number of statements in the provided SQL. 236 optional uint32 statement_count = 4; 237 238 // The number of statements which produced output rows in the provided SQL. 239 optional uint32 statement_with_output_count = 5; 240} 241 242// Input for the /status endpoint. 243message StatusArgs {} 244 245// Output for the /status endpoint. 246message StatusResult { 247 // If present and not empty, a trace is already loaded already. This happens 248 // when using the HTTP+RPC mode nad passing a trace file to the shell, via 249 // trace_processor_shell -D trace_file.pftrace . 250 optional string loaded_trace_name = 1; 251 252 // Typically something like "v11.0.123", but could be just "v11" or "unknown", 253 // for binaries built from Bazel or other build configurations. This is for 254 // human presentation only, don't attempt to parse and reason on it. 255 optional string human_readable_version = 2; 256 257 // The API version is incremented every time a change that the UI depends 258 // on is introduced (e.g. adding a new table that the UI queries). 259 optional int32 api_version = 3; 260} 261 262// Input for the /compute_metric endpoint. 263message ComputeMetricArgs { 264 enum ResultFormat { 265 BINARY_PROTOBUF = 0; 266 TEXTPROTO = 1; 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 286 optional string error = 2; 287} 288 289// Input for the /enable_metatrace endpoint. 290message EnableMetatraceArgs {} 291 292// Output for the /enable_metatrace endpoint. 293message EnableMetatraceResult {} 294 295// Input for the /disable_and_read_metatrace endpoint. 296message DisableAndReadMetatraceArgs {} 297 298// Output for the /disable_and_read_metatrace endpoint. 299message DisableAndReadMetatraceResult { 300 // Bytes of perfetto.protos.Trace message. Stored as bytes 301 // to avoid adding a dependency on trace.proto. 302 optional bytes metatrace = 1; 303 optional string error = 2; 304} 305 306// Convenience wrapper for multiple descriptors, similar to FileDescriptorSet 307// in descriptor.proto. 308message DescriptorSet { 309 repeated DescriptorProto descriptors = 1; 310} 311