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 210message FlushResponse {} 211 212// Arguments for rpc Detach 213message DetachRequest { 214 optional string key = 1; 215} 216 217message DetachResponse {} 218 219// Arguments for rpc Attach. 220message AttachRequest { 221 optional string key = 1; 222} 223 224message AttachResponse { 225 optional protos.TraceConfig trace_config = 1; 226} 227 228// Arguments for rpc GetTraceStats. 229 230message GetTraceStatsRequest {} 231 232message GetTraceStatsResponse { 233 optional TraceStats trace_stats = 1; 234} 235 236// Arguments for rpc ObserveEvents. 237 238// To stop observing events of a certain type, send a request with the remaining 239// types. To stop observing completely, send an empty request. 240message ObserveEventsRequest { 241 repeated ObservableEvents.Type events_to_observe = 1; 242} 243 244message ObserveEventsResponse { 245 optional ObservableEvents events = 1; 246} 247 248// Arguments for rpc QueryServiceState. 249message QueryServiceStateRequest {} 250 251message QueryServiceStateResponse { 252 // In order to avoid hitting IPC message size limitations, the service will 253 // return >1 replies for each query, chunking the TracingServiceState. The 254 // receiver is expected to merge replies together and parse that when the 255 // last reply is received (i.e. when IPC's |has_more| == false). 256 optional TracingServiceState service_state = 1; 257} 258 259// Arguments for rpc QueryCapabilities. 260message QueryCapabilitiesRequest {} 261 262message QueryCapabilitiesResponse { 263 optional TracingServiceCapabilities capabilities = 1; 264} 265 266// Arguments for rpc SaveTraceForBugreport. 267message SaveTraceForBugreportRequest {} 268 269// This response is sent only after the trace was saved into file (if succeeded) 270// or something failed. 271message SaveTraceForBugreportResponse { 272 // If true, an eligible the trace was saved into a known location (on Android 273 // /data/misc/perfetto-traces, see GetBugreportTracePath()). 274 // If false no trace with bugreport_score > 0 was found or an error occurred. 275 // see |msg| in that case for details about the failure. 276 optional bool success = 1; 277 optional string msg = 2; 278} 279 280// Arguments for rpc CloneSession. 281message CloneSessionRequest { 282 // The session ID to clone. If session_id == kBugreportSessionId (0xff...ff) 283 // the session with the highest bugreport score is cloned (if any exists). 284 optional uint64 session_id = 1; 285} 286 287message CloneSessionResponse { 288 // If true, the clone was successful. If false it failed and |error| contains 289 // the details about the failure. 290 optional bool success = 1; 291 optional string error = 2; 292 293 // The UUID of the cloned session. 294 optional int64 uuid_msb = 3; 295 optional int64 uuid_lsb = 4; 296} 297