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"; 18option optimize_for = LITE_RUNTIME; 19 20import "perfetto/common/observable_events.proto"; 21import "perfetto/common/trace_stats.proto"; 22import "perfetto/config/trace_config.proto"; 23 24package perfetto.protos; 25 26// IPC interface definition for the consumer port of the tracing service. 27service ConsumerPort { 28 // Creates the ring buffers that will be used for the tracing session. 29 // TODO(primiano): not implemented yet. EnableTracing will implicitly create 30 // the required buffer. This is to allow Enabling/Disabling tracing with 31 // different configs without losing the contents of the buffers for the 32 // previous tracing session. 33 // rpc CreateBuffers(CreateBuffersRequest) returns (CreateBuffersResponse) {} 34 35 // Enables tracing for one or more data sources. At least one buffer must have 36 // been previously created. The EnableTracingResponse is sent when tracing is 37 // disabled (either explicitly or because of the |duration_ms| expired). 38 // If |deferred_start| == true in the passed TraceConfig, all the tracing 39 // harness is brought up (creating buffers and data sources) without actually 40 // starting the data sources. Data sources will be started upon an explicit 41 // StartTracing() call. 42 // Note that |deferred_start| and StartTracing() have been introduced only 43 // in Android Q and are not supported in Android P. 44 rpc EnableTracing(EnableTracingRequest) returns (EnableTracingResponse) {} 45 46 // Disables tracing for one or more data sources. 47 rpc DisableTracing(DisableTracingRequest) returns (DisableTracingResponse) {} 48 49 // Streams back the contents of one or more buffers. One call is enough to 50 // drain all the buffers. The response consists in a sequence of 51 // ReadBufferResponse messages (hence the "stream" in the return type), each 52 // carrying one or more TracePacket(s). An EOF flag is attached to the last 53 // ReadBufferResponse through the |has_more| == false field. 54 rpc ReadBuffers(ReadBuffersRequest) returns (stream ReadBuffersResponse) {} 55 56 // Destroys the buffers previously created. Note: all buffers are destroyed 57 // implicitly if the Consumer disconnects. 58 rpc FreeBuffers(FreeBuffersRequest) returns (FreeBuffersResponse) {} 59 60 // Asks the service to request to all data sources involved in the tracing 61 // session to commit their data into the trace buffer. The FlushResponse is 62 // sent only: 63 // - After the data has been committed (in which case FlushResponse succeeds) 64 // or 65 // - After FlushRequest.timeout_ms milliseconds (in which case the 66 // FlushResponse is rejected and fails). 67 rpc Flush(FlushRequest) returns (FlushResponse) {} 68 69 // ---------------------------------------------------- 70 // All methods below have been introduced in Android Q. 71 // ---------------------------------------------------- 72 73 // Starts tracing. Only valid if EnableTracing() was called setting 74 // deferred_start = true in the TraceConfig passed to EnableTracing(). 75 rpc StartTracing(StartTracingRequest) returns (StartTracingResponse) {} 76 77 // Changes the configuration for a running tracing session; only possible 78 // for a subset of configuration options. 79 rpc ChangeTraceConfig(ChangeTraceConfigRequest) 80 returns (ChangeTraceConfigResponse) {} 81 82 // Allows the consumer to detach from the session. The session will keep 83 // running even if the consumer disconnects and the consumer will not receive 84 // any further IPC until reattached. 85 rpc Detach(DetachRequest) returns (DetachResponse) {} 86 87 // Allows the consumer to re-attach to a previously detached session. The 88 // consumer will start receiving IPC notification for that session. 89 // The session will be terminated if the consumer closes the IPC channel, as 90 // in the standard non-detached case. 91 rpc Attach(AttachRequest) returns (AttachResponse) {} 92 93 // Allows the consumer to obtain statistics about the current tracing session, 94 // such as buffer usage stats. Intended for debugging or UI use. 95 rpc GetTraceStats(GetTraceStatsRequest) returns (GetTraceStatsResponse) {} 96 97 // Allows the consumer to observe certain state changes, such as data source 98 // instances starting to record. 99 rpc ObserveEvents(ObserveEventsRequest) 100 returns (stream ObserveEventsResponse) {} 101 102 // TODO rpc ListDataSources(), for the UI. 103} 104 105// Arguments for rpc EnableTracing(). 106message EnableTracingRequest { 107 optional protos.TraceConfig trace_config = 1; 108 109 // Introduced in Android Q. This is used for re-attaching to the end-of-trace 110 // EnableTracingResponse notification after a Detach+Attach request. 111 // When this flag is set the |trace_config| is ignored and no method is called 112 // on the tracing service. 113 optional bool attach_notification_only = 2; 114} 115 116message EnableTracingResponse { 117 oneof state { bool disabled = 1; } 118} 119 120// Arguments for rpc StartTracing(). 121message StartTracingRequest {} 122 123message StartTracingResponse {} 124 125// Arguments for rpc ChangeTraceConfig(). 126message ChangeTraceConfigRequest { 127 optional protos.TraceConfig trace_config = 1; 128} 129 130message ChangeTraceConfigResponse {} 131 132// Arguments for rpc DisableTracing(). 133message DisableTracingRequest { 134 // TODO: not supported yet, selectively disable only some data sources. 135 // repeated string data_source_name; 136} 137 138message DisableTracingResponse {} 139 140// Arguments for rpc ReadBuffers(). 141message ReadBuffersRequest { 142 // The |id|s of the buffer, as passed to CreateBuffers(). 143 // TODO: repeated uint32 buffer_ids = 1; 144} 145 146message ReadBuffersResponse { 147 // TODO: uint32 buffer_id = 1; 148 149 // Each streaming reply returns one or more slices for one or more trace 150 // packets, or even just a portion of it (if it's too big to fit within one 151 // IPC). The returned slices are ordered and contiguous: packets' slices are 152 // not interleaved and slices are sent only once all slices for a packet are 153 // available (i.e. the consumer will never see any gap). 154 message Slice { 155 optional bytes data = 1; 156 157 // When true, this is the last slice for the packet. A ReadBufferResponse 158 // might have no slices marked as |last_slice_for_packet|==true, in the case 159 // of a very large packet that gets chunked into several IPCs (in which case 160 // only the last IPC for the packet will have this flag set). 161 optional bool last_slice_for_packet = 2; 162 } 163 repeated Slice slices = 2; 164} 165 166// Arguments for rpc FreeBuffers(). 167message FreeBuffersRequest { 168 // The |id|s of the buffer, as passed to CreateBuffers(). 169 repeated uint32 buffer_ids = 1; 170} 171 172message FreeBuffersResponse {} 173 174// Arguments for rpc Flush(). 175message FlushRequest { 176 optional uint32 timeout_ms = 1; 177} 178 179message FlushResponse {} 180 181// Arguments for rpc Detach 182message DetachRequest { 183 optional string key = 1; 184} 185 186message DetachResponse {} 187 188// Arguments for rpc Attach. 189message AttachRequest { 190 optional string key = 1; 191} 192 193message AttachResponse { 194 optional protos.TraceConfig trace_config = 1; 195} 196 197// Arguments for rpc GetTraceStats. 198 199message GetTraceStatsRequest {} 200 201message GetTraceStatsResponse { 202 optional TraceStats trace_stats = 1; 203} 204 205// Arguments for rpc ObserveEvents. 206 207// To stop observing events of a certain type, send a request with the remaining 208// types. To stop observing completely, send an empty request. 209message ObserveEventsRequest { 210 repeated ObservableEvents.Type events_to_observe = 1; 211} 212 213message ObserveEventsResponse { 214 optional ObservableEvents events = 1; 215} 216