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 // Creates the ring buffers that will be used for the tracing session. 30 // TODO(primiano): not implemented yet. EnableTracing will implicitly create 31 // the required buffer. This is to allow Enabling/Disabling tracing with 32 // different configs without losing the contents of the buffers for the 33 // previous tracing session. 34 // rpc CreateBuffers(CreateBuffersRequest) returns (CreateBuffersResponse) {} 35 36 // Enables tracing for one or more data sources. At least one buffer must have 37 // been previously created. The EnableTracingResponse is sent when tracing is 38 // disabled (either explicitly or because of the |duration_ms| expired). 39 // If |deferred_start| == true in the passed TraceConfig, all the tracing 40 // harness is brought up (creating buffers and data sources) without actually 41 // starting the data sources. Data sources will be started upon an explicit 42 // StartTracing() call. 43 // Note that |deferred_start| and StartTracing() have been introduced only 44 // in Android Q and are not supported in Android P. 45 rpc EnableTracing(EnableTracingRequest) returns (EnableTracingResponse) {} 46 47 // Disables tracing for one or more data sources. 48 rpc DisableTracing(DisableTracingRequest) returns (DisableTracingResponse) {} 49 50 // Streams back the contents of one or more buffers. One call is enough to 51 // drain all the buffers. The response consists in a sequence of 52 // ReadBufferResponse messages (hence the "stream" in the return type), each 53 // carrying one or more TracePacket(s). An EOF flag is attached to the last 54 // ReadBufferResponse through the |has_more| == false field. 55 rpc ReadBuffers(ReadBuffersRequest) returns (stream ReadBuffersResponse) {} 56 57 // Destroys the buffers previously created. Note: all buffers are destroyed 58 // implicitly if the Consumer disconnects. 59 rpc FreeBuffers(FreeBuffersRequest) returns (FreeBuffersResponse) {} 60 61 // Asks the service to request to all data sources involved in the tracing 62 // session to commit their data into the trace buffer. The FlushResponse is 63 // sent only: 64 // - After the data has been committed (in which case FlushResponse succeeds) 65 // or 66 // - After FlushRequest.timeout_ms milliseconds (in which case the 67 // FlushResponse is rejected and fails). 68 rpc Flush(FlushRequest) returns (FlushResponse) {} 69 70 // ---------------------------------------------------- 71 // All methods below have been introduced in Android Q. 72 // ---------------------------------------------------- 73 74 // Starts tracing. Only valid if EnableTracing() was called setting 75 // deferred_start = true in the TraceConfig passed to EnableTracing(). 76 rpc StartTracing(StartTracingRequest) returns (StartTracingResponse) {} 77 78 // Changes the configuration for a running tracing session; only possible 79 // for a subset of configuration options. 80 rpc ChangeTraceConfig(ChangeTraceConfigRequest) 81 returns (ChangeTraceConfigResponse) {} 82 83 // Allows the consumer to detach from the session. The session will keep 84 // running even if the consumer disconnects and the consumer will not receive 85 // any further IPC until reattached. 86 rpc Detach(DetachRequest) returns (DetachResponse) {} 87 88 // Allows the consumer to re-attach to a previously detached session. The 89 // consumer will start receiving IPC notification for that session. 90 // The session will be terminated if the consumer closes the IPC channel, as 91 // in the standard non-detached case. 92 rpc Attach(AttachRequest) returns (AttachResponse) {} 93 94 // Allows the consumer to obtain statistics about the current tracing session, 95 // such as buffer usage stats. Intended for debugging or UI use. 96 rpc GetTraceStats(GetTraceStatsRequest) returns (GetTraceStatsResponse) {} 97 98 // Allows the consumer to observe certain state changes, such as data source 99 // instances starting to record. 100 rpc ObserveEvents(ObserveEventsRequest) 101 returns (stream ObserveEventsResponse) {} 102 103 // ---------------------------------------------------- 104 // All methods below have been introduced in Android R. 105 // ---------------------------------------------------- 106 107 // Allows to obtain the list of data sources connected and their descriptors. 108 rpc QueryServiceState(QueryServiceStateRequest) 109 returns (stream QueryServiceStateResponse) {} 110 111 // Obtains a list of features supported by the service. This is to deal with 112 // backward/forward compatibility and feature detection. 113 rpc QueryCapabilities(QueryCapabilitiesRequest) 114 returns (QueryCapabilitiesResponse) {} 115 116 // ---------------------------------------------------- 117 // All methods below have been introduced in Android S. 118 // ---------------------------------------------------- 119 rpc SaveTraceForBugreport(SaveTraceForBugreportRequest) 120 returns (SaveTraceForBugreportResponse) {} 121} 122 123// Arguments for rpc EnableTracing(). 124message EnableTracingRequest { 125 optional protos.TraceConfig trace_config = 1; 126 127 // Introduced in Android Q. This is used for re-attaching to the end-of-trace 128 // EnableTracingResponse notification after a Detach+Attach request. 129 // When this flag is set the |trace_config| is ignored and no method is called 130 // on the tracing service. 131 optional bool attach_notification_only = 2; 132} 133 134message EnableTracingResponse { 135 oneof state { bool disabled = 1; } 136 137 // If present and non-empty tracing was disabled because of an error. 138 // Introduced in Android S. 139 optional string error = 3; 140} 141 142// Arguments for rpc StartTracing(). 143message StartTracingRequest {} 144 145message StartTracingResponse {} 146 147// Arguments for rpc ChangeTraceConfig(). 148message ChangeTraceConfigRequest { 149 optional protos.TraceConfig trace_config = 1; 150} 151 152message ChangeTraceConfigResponse {} 153 154// Arguments for rpc DisableTracing(). 155message DisableTracingRequest { 156 // TODO: not supported yet, selectively disable only some data sources. 157 // repeated string data_source_name; 158} 159 160message DisableTracingResponse {} 161 162// Arguments for rpc ReadBuffers(). 163message ReadBuffersRequest { 164 // The |id|s of the buffer, as passed to CreateBuffers(). 165 // TODO: repeated uint32 buffer_ids = 1; 166} 167 168message ReadBuffersResponse { 169 // TODO: uint32 buffer_id = 1; 170 171 // Each streaming reply returns one or more slices for one or more trace 172 // packets, or even just a portion of it (if it's too big to fit within one 173 // IPC). The returned slices are ordered and contiguous: packets' slices are 174 // not interleaved and slices are sent only once all slices for a packet are 175 // available (i.e. the consumer will never see any gap). 176 message Slice { 177 optional bytes data = 1; 178 179 // When true, this is the last slice for the packet. A ReadBufferResponse 180 // might have no slices marked as |last_slice_for_packet|==true, in the case 181 // of a very large packet that gets chunked into several IPCs (in which case 182 // only the last IPC for the packet will have this flag set). 183 optional bool last_slice_for_packet = 2; 184 } 185 repeated Slice slices = 2; 186} 187 188// Arguments for rpc FreeBuffers(). 189message FreeBuffersRequest { 190 // The |id|s of the buffer, as passed to CreateBuffers(). 191 repeated uint32 buffer_ids = 1; 192} 193 194message FreeBuffersResponse {} 195 196// Arguments for rpc Flush(). 197message FlushRequest { 198 optional uint32 timeout_ms = 1; 199} 200 201message FlushResponse {} 202 203// Arguments for rpc Detach 204message DetachRequest { 205 optional string key = 1; 206} 207 208message DetachResponse {} 209 210// Arguments for rpc Attach. 211message AttachRequest { 212 optional string key = 1; 213} 214 215message AttachResponse { 216 optional protos.TraceConfig trace_config = 1; 217} 218 219// Arguments for rpc GetTraceStats. 220 221message GetTraceStatsRequest {} 222 223message GetTraceStatsResponse { 224 optional TraceStats trace_stats = 1; 225} 226 227// Arguments for rpc ObserveEvents. 228 229// To stop observing events of a certain type, send a request with the remaining 230// types. To stop observing completely, send an empty request. 231message ObserveEventsRequest { 232 repeated ObservableEvents.Type events_to_observe = 1; 233} 234 235message ObserveEventsResponse { 236 optional ObservableEvents events = 1; 237} 238 239// Arguments for rpc QueryServiceState. 240message QueryServiceStateRequest {} 241 242message QueryServiceStateResponse { 243 // In order to avoid hitting IPC message size limitations, the service will 244 // return >1 replies for each query, chunking the TracingServiceState. The 245 // receiver is expected to merge replies together and parse that when the 246 // last reply is received (i.e. when IPC's |has_more| == false). 247 optional TracingServiceState service_state = 1; 248} 249 250// Arguments for rpc QueryCapabilities. 251message QueryCapabilitiesRequest {} 252 253message QueryCapabilitiesResponse { 254 optional TracingServiceCapabilities capabilities = 1; 255} 256 257// Arguments for rpc SaveTraceForBugreport. 258message SaveTraceForBugreportRequest {} 259 260// This response is sent only after the trace was saved into file (if succeeded) 261// or something failed. 262message SaveTraceForBugreportResponse { 263 // If true, an eligible the trace was saved into a known location (on Android 264 // /data/misc/perfetto-traces, see GetBugreportPath()). 265 // If false no trace with bugreport_score > 0 was found or an error occurred. 266 // see |msg| in that case for details about the failure. 267 optional bool success = 1; 268 optional string msg = 2; 269} 270