• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/commit_data_request.proto";
20import "protos/perfetto/config/data_source_config.proto";
21import "protos/perfetto/common/data_source_descriptor.proto";
22
23package perfetto.protos;
24
25// IPC interface definition for the producer port of the tracing service.
26service ProducerPort {
27  // Called once only after establishing the connection with the Service.
28  // The service replies sending the shared memory file descriptor in reply.
29  rpc InitializeConnection(InitializeConnectionRequest)
30      returns (InitializeConnectionResponse) {}
31
32  // Advertises a new data source.
33  rpc RegisterDataSource(RegisterDataSourceRequest)
34      returns (RegisterDataSourceResponse) {}
35
36  // Unregisters a previously registered data source.
37  rpc UnregisterDataSource(UnregisterDataSourceRequest)
38      returns (UnregisterDataSourceResponse) {}
39
40  // Sent by the client to request the service to:
41  // 1) Move some chunks from the shmem buffer into the logging buffer.
42  // 2) Patch the content of some chunks previously moved.
43  // 3) Acknowledge a Flush() request.
44  rpc CommitData(protos.CommitDataRequest) returns (CommitDataResponse) {}
45
46  // This is a backchannel to get asynchronous commands / notifications back
47  // from the Service.
48  rpc GetAsyncCommand(GetAsyncCommandRequest)
49      returns (stream GetAsyncCommandResponse) {}
50
51  // ----------------------------------------------------
52  // All methods below have been introduced in Android Q.
53  // ----------------------------------------------------
54
55  // Associates a trace writer with its target buffer.
56  rpc RegisterTraceWriter(RegisterTraceWriterRequest)
57      returns (RegisterTraceWriterResponse) {}
58
59  // Removes a trace writer association previously added by
60  // RegisterTraceWriter.
61  rpc UnregisterTraceWriter(UnregisterTraceWriterRequest)
62      returns (UnregisterTraceWriterResponse) {}
63
64  // Sent by the client in response to a StartDataSource message, when a data
65  // source is successfully started. This is expected only for data sources that
66  // set the DataSourceDescriptor.will_notify_on_start flag when registering.
67  rpc NotifyDataSourceStarted(NotifyDataSourceStartedRequest)
68      returns (NotifyDataSourceStartedResponse) {}
69
70  // Sent by the client in response to a StopDataSource message, when a data
71  // source is successfully stopped. This is expected only for data sources that
72  // set the DataSourceDescriptor.will_notify_on_stop flag when registering.
73  rpc NotifyDataSourceStopped(NotifyDataSourceStoppedRequest)
74      returns (NotifyDataSourceStoppedResponse) {}
75
76  // Sent by the client to request the service to:
77  // 1) Find all sessions which define these triggers
78  // 2) Perform an action as defined in those sessions configs.
79  rpc ActivateTriggers(ActivateTriggersRequest)
80      returns (ActivateTriggersResponse) {}
81
82  // ----------------------------------------------------
83  // All methods below have been introduced in Android R.
84  // ----------------------------------------------------
85
86  // This is used to linearize the producer with the service and to guarantee
87  // that all IPCs prior to this call have been seen and processed by the
88  // service. Example:
89  //   - RegisterDataSource(A)
90  //   - RegisterDataSource(B)
91  //   - Sync()
92  // When the Sync() response is received, the producer is guaranteed that the
93  // service has seen both data source registrations.
94  rpc Sync(SyncRequest) returns (SyncResponse) {}
95
96  // ----------------------------------------------------
97  // All methods below have been introduced in Android T.
98  // ----------------------------------------------------
99
100  // Updates the data source descriptor for an already-registered data source.
101  // This can be used to update the list of features supported.
102  // Only the data source with a matching data_source_descriptor.id is updated.
103  // The data_source_descriptor.name cannot be changed.
104  rpc UpdateDataSource(UpdateDataSourceRequest)
105      returns (UpdateDataSourceResponse) {}
106}
107
108// Arguments for rpc InitializeConnection().
109message InitializeConnectionRequest {
110  // Optional. Provides a hint to the tracing service about the suggested size
111  // of the shared memory buffer pages. The service is not required to respect
112  // this if it has already another value in the configuration or if the hint
113  // is unreasonably large. Must be an integer multiple of 4096. See tradeoff
114  // considerations in shared_memory_abi.h.
115  optional uint32 shared_memory_page_size_hint_bytes = 1;
116
117  // Optional. Provides a hint to the tracing service about the suggested size
118  // of the shared memory buffer. The service is not required to respect this
119  // and might return a smaller buffer.
120  optional uint32 shared_memory_size_hint_bytes = 2;
121
122  // Required to match the producer config set by the service to the correct
123  // producer.
124  optional string producer_name = 3;
125
126  enum ProducerSMBScrapingMode {
127    // Use the service's default setting for SMB scraping.
128    SMB_SCRAPING_UNSPECIFIED = 0;
129
130    // Enable scraping of uncommitted chunks from the producer's shared memory
131    // buffer.
132    SMB_SCRAPING_ENABLED = 1;
133
134    // Disable scraping of uncommitted chunks from the producer's shared memory
135    // buffer.
136    SMB_SCRAPING_DISABLED = 2;
137  }
138
139  // If provided, overrides the service's SMB scraping setting for the producer.
140  optional ProducerSMBScrapingMode smb_scraping_mode = 4;
141
142  // Was build_flags = BUILD_FLAGS_DCHECKS_ON|OFF. It was used to emit an error
143  // when DCHECKs level didn't match between service and producer (in turn that
144  // would crash the service when applying patches).
145  // Removed in v20 as part of b/197340286.
146  reserved 5;
147
148  // ---------------------------------------------------
149  // All fields below have been introduced in Android R.
150  // ---------------------------------------------------
151
152  // Since Android R, this request can also transport an FD for the producer's
153  // shared memory buffer, if allocated by the producer (e.g. for startup
154  // tracing). In this case, |shared_memory_page_size_hint_bytes| is a required
155  // field, and describes the SMB's page size. Note that the service may not
156  // accept this SMB (e.g. because it is too old or its size / page size are
157  // invalid) and instead allocate a new SMB which is provided in the
158  // SetupTracing response. See TracingService::ConnectProducer() and
159  // |using_shmem_provided_by_producer| in InitializeConnectionResponse.
160  optional bool producer_provided_shmem = 6;
161
162  // ---------------------------------------------------
163  // All fields below have been introduced in Android S.
164  // ---------------------------------------------------
165
166  // The version of the client library used by the producer.
167  // This is a human readable string with and its format varies depending on
168  // the build system that is used to build the code and the repo (standalone
169  // vs AOSP). This is intended for human debugging only.
170  optional string sdk_version = 8;
171
172  // On Windows, when producer_provided_shmem = true, the client creates a named
173  // SHM region and passes the name (an unguessable token) back to the service.
174  // Introduced in v13.
175  optional string shm_key_windows = 7;
176}
177
178message InitializeConnectionResponse {
179  // Indicates whether the service accepted the SMB provided by the producer in
180  // InitializeConnectionRequest (if any). If false, the shared memory buffer FD
181  // will provided by the service via the SetupTracing async command.
182  optional bool using_shmem_provided_by_producer = 1;
183
184  // Indicates to the producer that the service allows direct SMB patching of
185  // chunks that have not yet been committed to it.
186  // This field has been introduced in Android S.
187  optional bool direct_smb_patching_supported = 2;
188}
189
190// Arguments for rpc RegisterDataSource().
191
192message RegisterDataSourceRequest {
193  optional protos.DataSourceDescriptor data_source_descriptor = 1;
194}
195
196message RegisterDataSourceResponse {
197  // Only set in case of errors, when |data_source_id| == 0.
198  optional string error = 1;
199};
200
201// Arguments for rpc UpdateDataSource().
202
203message UpdateDataSourceRequest {
204  // The new data_source_descriptor.{id, name} must match {id, name} of a
205  // data source previously registered via RegisterDataSource().
206  optional protos.DataSourceDescriptor data_source_descriptor = 1;
207}
208
209message UpdateDataSourceResponse {};
210
211// Arguments for rpc UnregisterDataSource().
212
213message UnregisterDataSourceRequest {
214  // The name of the data source to unregister, as previously passed in
215  // |RegisterDataSourceRequest.name|.
216  optional string data_source_name = 1;
217}
218
219message UnregisterDataSourceResponse {}
220
221// Arguments for rpc RegisterTraceWriter().
222
223message RegisterTraceWriterRequest {
224  // The ID of a producer's trace writer.
225  optional uint32 trace_writer_id = 1;
226
227  // The ID of the target buffer that the trace writer commits its chunks to.
228  optional uint32 target_buffer = 2;
229}
230
231message RegisterTraceWriterResponse {}
232
233// Arguments for rpc UnregisterTraceWriter().
234
235message UnregisterTraceWriterRequest {
236  // The ID of a producer's trace writer.
237  optional uint32 trace_writer_id = 1;
238}
239
240message UnregisterTraceWriterResponse {}
241
242// Arguments for rpc CommitData().
243// See commit_data_request.proto for CommitDataRequest. That has its own file
244// because it is used also as input to generate C++ classes (xxx.gen.h).
245
246message CommitDataResponse {}
247
248// Arguments for rpc NotifyDataSourceStarted().
249
250message NotifyDataSourceStartedRequest {
251  // ID of the data source that has successfully started.
252  optional uint64 data_source_id = 1;
253}
254
255message NotifyDataSourceStartedResponse {}
256
257// Arguments for rpc NotifyDataSourceStopped().
258
259message NotifyDataSourceStoppedRequest {
260  // ID of the data source that has successfully stopped.
261  optional uint64 data_source_id = 1;
262}
263
264message NotifyDataSourceStoppedResponse {}
265
266// Arguments for rpc ActivateTriggersRequest().
267
268message ActivateTriggersRequest {
269  repeated string trigger_names = 1;
270}
271
272message ActivateTriggersResponse {}
273
274// Arguments for rpc GetAsyncCommand().
275
276message GetAsyncCommandRequest {}
277
278message GetAsyncCommandResponse {
279  // Called after SetupTracing and before StartDataSource.
280  // This message was introduced in Android Q.
281  message SetupDataSource {
282    optional uint64 new_instance_id = 1;
283    optional protos.DataSourceConfig config = 2;
284  }
285
286  message StartDataSource {
287    optional uint64 new_instance_id = 1;
288
289    // For backwards compat reasons (with Android P), the config passed here
290    // is identical to the one passed to SetupDataSource.config.
291    optional protos.DataSourceConfig config = 2;
292  }
293
294  message StopDataSource { optional uint64 instance_id = 1; }
295
296  // On Android/Linux/Mac this message also transports the file descriptor for
297  // the shared memory buffer (not a proto field).
298  message SetupTracing {
299    optional uint32 shared_buffer_page_size_kb = 1;
300
301    // On Windows, instead, we pass the name (an unguessable token) of a shared
302    // memory region that can be attached by the other process by name.
303    // Introduced in v13.
304    optional string shm_key_windows = 2;
305  }
306
307  message Flush {
308    // The instance id (i.e. StartDataSource.new_instance_id) of the data
309    // sources to flush.
310    repeated uint64 data_source_ids = 1;
311
312    // A monotonic counter generated by the service. The producer is simply
313    // expected to copy this value back into the CommitDataRequest, so the
314    // service can tell when the data for this flush has been committed.
315    optional uint64 request_id = 2;
316  }
317
318  // Instructs the given data sources to stop referring to any trace contents
319  // emitted so far. Sent only to active data sources that set
320  // |handles_incremental_state_clear| in their DataSourceDescriptor.
321  //
322  // Added to perfetto tree in May 2019.
323  message ClearIncrementalState {
324    // The instance id (i.e. StartDataSource.new_instance_id) of the data
325    // sources that should clear their incremental state.
326    repeated uint64 data_source_ids = 1;
327  }
328
329  // Next id: 8.
330  oneof cmd {
331    SetupTracing setup_tracing = 3;
332    SetupDataSource setup_data_source = 6;
333    StartDataSource start_data_source = 1;
334    StopDataSource stop_data_source = 2;
335    // id == 4 was teardown_tracing, never implemented.
336    Flush flush = 5;
337    ClearIncrementalState clear_incremental_state = 7;
338  }
339}
340
341// Arguments for rpc Sync().
342message SyncRequest {}
343message SyncResponse {}
344