xref: /aosp_15_r20/external/perfetto/protos/perfetto/ipc/producer_port.proto (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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  // Indicates whether the service would like to use SMB emulation for the
190  // connection, and request the client to send chunk data over the socket e.g.
191  // for remote connection from a VM guest.
192  optional bool use_shmem_emulation = 3;
193}
194
195// Arguments for rpc RegisterDataSource().
196
197message RegisterDataSourceRequest {
198  optional protos.DataSourceDescriptor data_source_descriptor = 1;
199}
200
201message RegisterDataSourceResponse {
202  // Only set in case of errors, when |data_source_id| == 0.
203  optional string error = 1;
204};
205
206// Arguments for rpc UpdateDataSource().
207
208message UpdateDataSourceRequest {
209  // The new data_source_descriptor.{id, name} must match {id, name} of a
210  // data source previously registered via RegisterDataSource().
211  optional protos.DataSourceDescriptor data_source_descriptor = 1;
212}
213
214message UpdateDataSourceResponse {};
215
216// Arguments for rpc UnregisterDataSource().
217
218message UnregisterDataSourceRequest {
219  // The name of the data source to unregister, as previously passed in
220  // |RegisterDataSourceRequest.name|.
221  optional string data_source_name = 1;
222}
223
224message UnregisterDataSourceResponse {}
225
226// Arguments for rpc RegisterTraceWriter().
227
228message RegisterTraceWriterRequest {
229  // The ID of a producer's trace writer.
230  optional uint32 trace_writer_id = 1;
231
232  // The ID of the target buffer that the trace writer commits its chunks to.
233  optional uint32 target_buffer = 2;
234}
235
236message RegisterTraceWriterResponse {}
237
238// Arguments for rpc UnregisterTraceWriter().
239
240message UnregisterTraceWriterRequest {
241  // The ID of a producer's trace writer.
242  optional uint32 trace_writer_id = 1;
243}
244
245message UnregisterTraceWriterResponse {}
246
247// Arguments for rpc CommitData().
248// See commit_data_request.proto for CommitDataRequest. That has its own file
249// because it is used also as input to generate C++ classes (xxx.gen.h).
250
251message CommitDataResponse {}
252
253// Arguments for rpc NotifyDataSourceStarted().
254
255message NotifyDataSourceStartedRequest {
256  // ID of the data source that has successfully started.
257  optional uint64 data_source_id = 1;
258}
259
260message NotifyDataSourceStartedResponse {}
261
262// Arguments for rpc NotifyDataSourceStopped().
263
264message NotifyDataSourceStoppedRequest {
265  // ID of the data source that has successfully stopped.
266  optional uint64 data_source_id = 1;
267}
268
269message NotifyDataSourceStoppedResponse {}
270
271// Arguments for rpc ActivateTriggersRequest().
272
273message ActivateTriggersRequest {
274  repeated string trigger_names = 1;
275}
276
277message ActivateTriggersResponse {}
278
279// Arguments for rpc GetAsyncCommand().
280
281message GetAsyncCommandRequest {}
282
283message GetAsyncCommandResponse {
284  // Called after SetupTracing and before StartDataSource.
285  // This message was introduced in Android Q.
286  message SetupDataSource {
287    optional uint64 new_instance_id = 1;
288    optional protos.DataSourceConfig config = 2;
289  }
290
291  message StartDataSource {
292    optional uint64 new_instance_id = 1;
293
294    // For backwards compat reasons (with Android P), the config passed here
295    // is identical to the one passed to SetupDataSource.config.
296    optional protos.DataSourceConfig config = 2;
297  }
298
299  message StopDataSource { optional uint64 instance_id = 1; }
300
301  // On Android/Linux/Mac this message also transports the file descriptor for
302  // the shared memory buffer (not a proto field).
303  message SetupTracing {
304    optional uint32 shared_buffer_page_size_kb = 1;
305
306    // On Windows, instead, we pass the name (an unguessable token) of a shared
307    // memory region that can be attached by the other process by name.
308    // Introduced in v13.
309    optional string shm_key_windows = 2;
310  }
311
312  message Flush {
313    // The instance id (i.e. StartDataSource.new_instance_id) of the data
314    // sources to flush.
315    repeated uint64 data_source_ids = 1;
316
317    // A monotonic counter generated by the service. The producer is simply
318    // expected to copy this value back into the CommitDataRequest, so the
319    // service can tell when the data for this flush has been committed.
320    optional uint64 request_id = 2;
321
322    // More details such as flush reason and originator. Introduced in v38 / V.
323    // See FlushFlags in include/perfetto/ext/tracing/core/flush_flags.h.
324    optional uint64 flags = 3;
325  }
326
327  // Instructs the given data sources to stop referring to any trace contents
328  // emitted so far. Sent only to active data sources that set
329  // |handles_incremental_state_clear| in their DataSourceDescriptor.
330  //
331  // Added to perfetto tree in May 2019.
332  message ClearIncrementalState {
333    // The instance id (i.e. StartDataSource.new_instance_id) of the data
334    // sources that should clear their incremental state.
335    repeated uint64 data_source_ids = 1;
336  }
337
338  // Next id: 8.
339  oneof cmd {
340    SetupTracing setup_tracing = 3;
341    SetupDataSource setup_data_source = 6;
342    StartDataSource start_data_source = 1;
343    StopDataSource stop_data_source = 2;
344    // id == 4 was teardown_tracing, never implemented.
345    Flush flush = 5;
346    ClearIncrementalState clear_incremental_state = 7;
347  }
348}
349
350// Arguments for rpc Sync().
351message SyncRequest {}
352message SyncResponse {}
353