• 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 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// Arguments for rpc InitializeConnection().
98message InitializeConnectionRequest {
99  // Optional. Provides a hint to the tracing service about the suggested size
100  // of the shared memory buffer pages. The service is not required to respect
101  // this if it has already another value in the configuration or if the hint
102  // is unreasonably large. Must be an integer multiple of 4096. See tradeoff
103  // considerations in shared_memory_abi.h.
104  optional uint32 shared_memory_page_size_hint_bytes = 1;
105
106  // Optional. Provides a hint to the tracing service about the suggested size
107  // of the shared memory buffer. The service is not required to respect this
108  // and might return a smaller buffer.
109  optional uint32 shared_memory_size_hint_bytes = 2;
110
111  // Required to match the producer config set by the service to the correct
112  // producer.
113  optional string producer_name = 3;
114
115  enum ProducerSMBScrapingMode {
116    // Use the service's default setting for SMB scraping.
117    SMB_SCRAPING_UNSPECIFIED = 0;
118
119    // Enable scraping of uncommitted chunks from the producer's shared memory
120    // buffer.
121    SMB_SCRAPING_ENABLED = 1;
122
123    // Disable scraping of uncommitted chunks from the producer's shared memory
124    // buffer.
125    SMB_SCRAPING_DISABLED = 2;
126  }
127
128  // If provided, overrides the service's SMB scraping setting for the producer.
129  optional ProducerSMBScrapingMode smb_scraping_mode = 4;
130
131  enum ProducerBuildFlags {
132    BUILD_FLAGS_UNSPECIFIED = 0;
133    BUILD_FLAGS_DCHECKS_ON = 1;
134    BUILD_FLAGS_DCHECKS_OFF = 2;
135  }
136
137  // If provided, reports the build flags of the producer. It's used merely for
138  // error reporting, to print a log message when a producer connects to a
139  // service that has mismatching build flags.
140  optional ProducerBuildFlags build_flags = 5;
141
142  // ---------------------------------------------------
143  // All fields below have been introduced in Android R.
144  // ---------------------------------------------------
145
146  // Since Android R, this request can also transport an FD for the producer's
147  // shared memory buffer, if allocated by the producer (e.g. for startup
148  // tracing). In this case, |shared_memory_page_size_hint_bytes| is a required
149  // field, and describes the SMB's page size. Note that the service may not
150  // accept this SMB (e.g. because it is too old or its size / page size are
151  // invalid) and instead allocate a new SMB which is provided in the
152  // SetupTracing response. See TracingService::ConnectProducer() and
153  // |using_shmem_provided_by_producer| in InitializeConnectionResponse.
154  optional bool producer_provided_shmem = 6;
155
156  // ---------------------------------------------------
157  // All fields below have been introduced in Android S.
158  // ---------------------------------------------------
159
160  // The version of the client library used by the producer.
161  // This is a human readable string with and its format varies depending on
162  // the build system that is used to build the code and the repo (standalone
163  // vs AOSP). This is intended for human debugging only.
164  optional string sdk_version = 8;
165}
166
167message InitializeConnectionResponse {
168  // Indicates whether the service accepted the SMB provided by the producer in
169  // InitializeConnectionRequest (if any). If false, the shared memory buffer FD
170  // will provided by the service via the SetupTracing async command.
171  optional bool using_shmem_provided_by_producer = 1;
172
173  // Indicates to the producer that the service allows direct SMB patching of
174  // chunks that have not yet been committed to it.
175  // This field has been introduced in Android S.
176  optional bool direct_smb_patching_supported = 2;
177}
178
179// Arguments for rpc RegisterDataSource().
180
181message RegisterDataSourceRequest {
182  optional protos.DataSourceDescriptor data_source_descriptor = 1;
183}
184
185message RegisterDataSourceResponse {
186  // Only set in case of errors, when |data_source_id| == 0.
187  optional string error = 1;
188};
189
190// Arguments for rpc UnregisterDataSource().
191
192message UnregisterDataSourceRequest {
193  // The name of the data source to unregister, as previously passed in
194  // |RegisterDataSourceRequest.name|.
195  optional string data_source_name = 1;
196}
197
198message UnregisterDataSourceResponse {}
199
200// Arguments for rpc RegisterTraceWriter().
201
202message RegisterTraceWriterRequest {
203  // The ID of a producer's trace writer.
204  optional uint32 trace_writer_id = 1;
205
206  // The ID of the target buffer that the trace writer commits its chunks to.
207  optional uint32 target_buffer = 2;
208}
209
210message RegisterTraceWriterResponse {}
211
212// Arguments for rpc UnregisterTraceWriter().
213
214message UnregisterTraceWriterRequest {
215  // The ID of a producer's trace writer.
216  optional uint32 trace_writer_id = 1;
217}
218
219message UnregisterTraceWriterResponse {}
220
221// Arguments for rpc CommitData().
222// See commit_data_request.proto for CommitDataRequest. That has its own file
223// because it is used also as input to generate C++ classes (xxx.gen.h).
224
225message CommitDataResponse {}
226
227// Arguments for rpc NotifyDataSourceStarted().
228
229message NotifyDataSourceStartedRequest {
230  // ID of the data source that has successfully started.
231  optional uint64 data_source_id = 1;
232}
233
234message NotifyDataSourceStartedResponse {}
235
236// Arguments for rpc NotifyDataSourceStopped().
237
238message NotifyDataSourceStoppedRequest {
239  // ID of the data source that has successfully stopped.
240  optional uint64 data_source_id = 1;
241}
242
243message NotifyDataSourceStoppedResponse {}
244
245// Arguments for rpc ActivateTriggersRequest().
246
247message ActivateTriggersRequest {
248  repeated string trigger_names = 1;
249}
250
251message ActivateTriggersResponse {}
252
253// Arguments for rpc GetAsyncCommand().
254
255message GetAsyncCommandRequest {}
256
257message GetAsyncCommandResponse {
258  // Called after SetupTracing and before StartDataSource.
259  // This message was introduced in Android Q.
260  message SetupDataSource {
261    optional uint64 new_instance_id = 1;
262    optional protos.DataSourceConfig config = 2;
263  }
264
265  message StartDataSource {
266    optional uint64 new_instance_id = 1;
267
268    // For backwards compat reasons (with Android P), the config passed here
269    // is identical to the one passed to SetupDataSource.config.
270    optional protos.DataSourceConfig config = 2;
271  }
272
273  message StopDataSource { optional uint64 instance_id = 1; }
274
275  // On Android/Linux/Mac this message also transports the file descriptor for
276  // the shared memory buffer (not a proto field).
277  message SetupTracing {
278    optional uint32 shared_buffer_page_size_kb = 1;
279  }
280
281  message Flush {
282    // The instance id (i.e. StartDataSource.new_instance_id) of the data
283    // sources to flush.
284    repeated uint64 data_source_ids = 1;
285
286    // A monotonic counter generated by the service. The producer is simply
287    // expected to copy this value back into the CommitDataRequest, so the
288    // service can tell when the data for this flush has been committed.
289    optional uint64 request_id = 2;
290  }
291
292  // Instructs the given data sources to stop referring to any trace contents
293  // emitted so far. Sent only to active data sources that set
294  // |handles_incremental_state_clear| in their DataSourceDescriptor.
295  //
296  // Added to perfetto tree in May 2019.
297  message ClearIncrementalState {
298    // The instance id (i.e. StartDataSource.new_instance_id) of the data
299    // sources that should clear their incremental state.
300    repeated uint64 data_source_ids = 1;
301  }
302
303  // Next id: 8.
304  oneof cmd {
305    SetupTracing setup_tracing = 3;
306    SetupDataSource setup_data_source = 6;
307    StartDataSource start_data_source = 1;
308    StopDataSource stop_data_source = 2;
309    // id == 4 was teardown_tracing, never implemented.
310    Flush flush = 5;
311    ClearIncrementalState clear_incremental_state = 7;
312  }
313}
314
315// Arguments for rpc Sync().
316message SyncRequest {}
317message SyncResponse {}
318