1/* 2 * Copyright (C) 2017 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 19import "protos/perfetto/common/observable_events.proto"; 20import "protos/perfetto/common/tracing_service_state.proto"; 21import "protos/perfetto/common/tracing_service_capabilities.proto"; 22import "protos/perfetto/common/trace_stats.proto"; 23import "protos/perfetto/config/trace_config.proto"; 24 25package perfetto.protos; 26 27// IPC interface definition for the consumer port of the tracing service. 28service ConsumerPort { 29 // Enables tracing for one or more data sources. At least one buffer must have 30 // been previously created. The EnableTracingResponse is sent when tracing is 31 // disabled (either explicitly or because of the |duration_ms| expired). 32 // If |deferred_start| == true in the passed TraceConfig, all the tracing 33 // harness is brought up (creating buffers and data sources) without actually 34 // starting the data sources. Data sources will be started upon an explicit 35 // StartTracing() call. 36 // Note that |deferred_start| and StartTracing() have been introduced only 37 // in Android Q and are not supported in Android P. 38 rpc EnableTracing(EnableTracingRequest) returns (EnableTracingResponse) {} 39 40 // Disables tracing for one or more data sources. 41 rpc DisableTracing(DisableTracingRequest) returns (DisableTracingResponse) {} 42 43 // Streams back the contents of one or more buffers. One call is enough to 44 // drain all the buffers. The response consists in a sequence of 45 // ReadBufferResponse messages (hence the "stream" in the return type), each 46 // carrying one or more TracePacket(s). An EOF flag is attached to the last 47 // ReadBufferResponse through the |has_more| == false field. 48 rpc ReadBuffers(ReadBuffersRequest) returns (stream ReadBuffersResponse) {} 49 50 // Destroys the buffers previously created. Note: all buffers are destroyed 51 // implicitly if the Consumer disconnects. 52 rpc FreeBuffers(FreeBuffersRequest) returns (FreeBuffersResponse) {} 53 54 // Asks the service to request to all data sources involved in the tracing 55 // session to commit their data into the trace buffer. The FlushResponse is 56 // sent only: 57 // - After the data has been committed (in which case FlushResponse succeeds) 58 // or 59 // - After FlushRequest.timeout_ms milliseconds (in which case the 60 // FlushResponse is rejected and fails). 61 rpc Flush(FlushRequest) returns (FlushResponse) {} 62 63 // ---------------------------------------------------- 64 // All methods below have been introduced in Android Q. 65 // ---------------------------------------------------- 66 67 // Starts tracing. Only valid if EnableTracing() was called setting 68 // deferred_start = true in the TraceConfig passed to EnableTracing(). 69 rpc StartTracing(StartTracingRequest) returns (StartTracingResponse) {} 70 71 // Changes the configuration for a running tracing session; only possible 72 // for a subset of configuration options. 73 rpc ChangeTraceConfig(ChangeTraceConfigRequest) 74 returns (ChangeTraceConfigResponse) {} 75 76 // Allows the consumer to detach from the session. The session will keep 77 // running even if the consumer disconnects and the consumer will not receive 78 // any further IPC until reattached. 79 rpc Detach(DetachRequest) returns (DetachResponse) {} 80 81 // Allows the consumer to re-attach to a previously detached session. The 82 // consumer will start receiving IPC notification for that session. 83 // The session will be terminated if the consumer closes the IPC channel, as 84 // in the standard non-detached case. 85 rpc Attach(AttachRequest) returns (AttachResponse) {} 86 87 // Allows the consumer to obtain statistics about the current tracing session, 88 // such as buffer usage stats. Intended for debugging or UI use. 89 rpc GetTraceStats(GetTraceStatsRequest) returns (GetTraceStatsResponse) {} 90 91 // Allows the consumer to observe certain state changes, such as data source 92 // instances starting to record. 93 rpc ObserveEvents(ObserveEventsRequest) 94 returns (stream ObserveEventsResponse) {} 95 96 // ---------------------------------------------------- 97 // All methods below have been introduced in Android R. 98 // ---------------------------------------------------- 99 100 // Allows to obtain the list of data sources connected and their descriptors. 101 rpc QueryServiceState(QueryServiceStateRequest) 102 returns (stream QueryServiceStateResponse) {} 103 104 // Obtains a list of features supported by the service. This is to deal with 105 // backward/forward compatibility and feature detection. 106 rpc QueryCapabilities(QueryCapabilitiesRequest) 107 returns (QueryCapabilitiesResponse) {} 108 109 // ---------------------------------------------------- 110 // All methods below have been introduced in Android S. 111 // ---------------------------------------------------- 112 113 // This method has been deprecated and removed in Android U in favour of 114 // CloneSession. 115 rpc SaveTraceForBugreport(SaveTraceForBugreportRequest) 116 returns (SaveTraceForBugreportResponse) {} 117 118 // ---------------------------------------------------- 119 // All methods below have been introduced in Android U. 120 // ---------------------------------------------------- 121 122 // Clones an existing tracing session and binds the consumer to it (as if 123 // the session was created via EnableTracing), copying over all the tracing 124 // data (including metadata and stats). 125 // The cloned session is stopped and read-only (as if DisableTracing was 126 // invoked). 127 // A consumer can clone a session only if the uid of the consumer matches the 128 // uid of the source session or if the consumer uid is 0 (root). 129 rpc CloneSession(CloneSessionRequest) returns (CloneSessionResponse) {} 130} 131 132// Arguments for rpc EnableTracing(). 133message EnableTracingRequest { 134 optional protos.TraceConfig trace_config = 1; 135 136 // Introduced in Android Q. This is used for re-attaching to the end-of-trace 137 // EnableTracingResponse notification after a Detach+Attach request. 138 // When this flag is set the |trace_config| is ignored and no method is called 139 // on the tracing service. 140 optional bool attach_notification_only = 2; 141} 142 143message EnableTracingResponse { 144 oneof state { bool disabled = 1; } 145 146 // If present and non-empty tracing was disabled because of an error. 147 // Introduced in Android S. 148 optional string error = 3; 149} 150 151// Arguments for rpc StartTracing(). 152message StartTracingRequest {} 153 154message StartTracingResponse {} 155 156// Arguments for rpc ChangeTraceConfig(). 157message ChangeTraceConfigRequest { 158 optional protos.TraceConfig trace_config = 1; 159} 160 161message ChangeTraceConfigResponse {} 162 163// Arguments for rpc DisableTracing(). 164message DisableTracingRequest { 165 // TODO: not supported yet, selectively disable only some data sources. 166 // repeated string data_source_name; 167} 168 169message DisableTracingResponse {} 170 171// Arguments for rpc ReadBuffers(). 172message ReadBuffersRequest { 173 // The |id|s of the buffer, as passed to CreateBuffers(). 174 // TODO: repeated uint32 buffer_ids = 1; 175} 176 177message ReadBuffersResponse { 178 // TODO: uint32 buffer_id = 1; 179 180 // Each streaming reply returns one or more slices for one or more trace 181 // packets, or even just a portion of it (if it's too big to fit within one 182 // IPC). The returned slices are ordered and contiguous: packets' slices are 183 // not interleaved and slices are sent only once all slices for a packet are 184 // available (i.e. the consumer will never see any gap). 185 message Slice { 186 optional bytes data = 1; 187 188 // When true, this is the last slice for the packet. A ReadBufferResponse 189 // might have no slices marked as |last_slice_for_packet|==true, in the case 190 // of a very large packet that gets chunked into several IPCs (in which case 191 // only the last IPC for the packet will have this flag set). 192 optional bool last_slice_for_packet = 2; 193 } 194 repeated Slice slices = 2; 195} 196 197// Arguments for rpc FreeBuffers(). 198message FreeBuffersRequest { 199 // The |id|s of the buffer, as passed to CreateBuffers(). 200 repeated uint32 buffer_ids = 1; 201} 202 203message FreeBuffersResponse {} 204 205// Arguments for rpc Flush(). 206message FlushRequest { 207 optional uint32 timeout_ms = 1; 208 209 // More details such as flush reason and originator. Introduced in v38 / V. 210 // See FlushFlags in include/perfetto/ext/tracing/core/flush_flags.h. 211 optional uint64 flags = 2; 212} 213 214message FlushResponse {} 215 216// Arguments for rpc Detach 217message DetachRequest { 218 optional string key = 1; 219} 220 221message DetachResponse {} 222 223// Arguments for rpc Attach. 224message AttachRequest { 225 optional string key = 1; 226} 227 228message AttachResponse { 229 optional protos.TraceConfig trace_config = 1; 230} 231 232// Arguments for rpc GetTraceStats. 233 234message GetTraceStatsRequest {} 235 236message GetTraceStatsResponse { 237 optional TraceStats trace_stats = 1; 238} 239 240// Arguments for rpc ObserveEvents. 241 242// To stop observing events of a certain type, send a request with the remaining 243// types. To stop observing completely, send an empty request. 244message ObserveEventsRequest { 245 repeated ObservableEvents.Type events_to_observe = 1; 246} 247 248message ObserveEventsResponse { 249 optional ObservableEvents events = 1; 250} 251 252// Arguments for rpc QueryServiceState. 253message QueryServiceStateRequest { 254 // If set, only the TracingServiceState.tracing_sessions is filled. Producers 255 // and data sources are omitted. 256 optional bool sessions_only = 1; 257} 258 259message QueryServiceStateResponse { 260 // In order to avoid hitting IPC message size limitations, the service will 261 // return >1 replies for each query, chunking the TracingServiceState. The 262 // receiver is expected to merge replies together and parse that when the 263 // last reply is received (i.e. when IPC's |has_more| == false). 264 optional TracingServiceState service_state = 1; 265} 266 267// Arguments for rpc QueryCapabilities. 268message QueryCapabilitiesRequest {} 269 270message QueryCapabilitiesResponse { 271 optional TracingServiceCapabilities capabilities = 1; 272} 273 274// Arguments for rpc SaveTraceForBugreport. 275message SaveTraceForBugreportRequest {} 276 277// This response is sent only after the trace was saved into file (if succeeded) 278// or something failed. 279message SaveTraceForBugreportResponse { 280 // If true, an eligible the trace was saved into a known location (on Android 281 // /data/misc/perfetto-traces, see GetBugreportTracePath()). 282 // If false no trace with bugreport_score > 0 was found or an error occurred. 283 // see |msg| in that case for details about the failure. 284 optional bool success = 1; 285 optional string msg = 2; 286} 287 288// Arguments for rpc CloneSession. 289message CloneSessionRequest { 290 oneof selector { 291 // The session ID to clone. If session_id == kBugreportSessionId (0xff...ff) 292 // the session with the highest bugreport score is cloned (if any exists). 293 uint64 session_id = 1; 294 295 // The unique_session_name of the tracing session to clone. Tracing sessions 296 // that are clones of other tracing sessions are ignored. 297 string unique_session_name = 4; 298 } 299 300 // If set, the trace filter will not have effect on the cloned session. 301 // Used for bugreports. 302 optional bool skip_trace_filter = 2; 303 304 // If set, affects the generation of the FlushFlags::CloneTarget to be set 305 // to kBugreport when requesting the flush to the producers. 306 optional bool for_bugreport = 3; 307 308 // If set, this is stored in the trace as name of the trigger that caused the 309 // clone. 310 optional string clone_trigger_name = 5; 311 // If set, this is stored in the trace as name of the producer that triggered 312 // the clone. 313 optional string clone_trigger_producer_name = 6; 314 // If set, this is stored in the trace as uid of the producer that triggered 315 // the clone. 316 optional int32 clone_trigger_trusted_producer_uid = 7; 317 // If set, this is stored in the trace as timestamp of the trigger that caused 318 // the clone. 319 optional uint64 clone_trigger_boot_time_ns = 8; 320} 321 322message CloneSessionResponse { 323 // If true, the clone was successful. If false it failed and |error| contains 324 // the details about the failure. 325 optional bool success = 1; 326 optional string error = 2; 327 328 // The UUID of the cloned session. 329 optional int64 uuid_msb = 3; 330 optional int64 uuid_lsb = 4; 331} 332