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