• 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
157message InitializeConnectionResponse {
158  // Indicates whether the service accepted the SMB provided by the producer in
159  // InitializeConnectionRequest (if any). If false, the shared memory buffer FD
160  // will provided by the service via the SetupTracing async command.
161  optional bool using_shmem_provided_by_producer = 1;
162}
163
164// Arguments for rpc RegisterDataSource().
165
166message RegisterDataSourceRequest {
167  optional protos.DataSourceDescriptor data_source_descriptor = 1;
168}
169
170message RegisterDataSourceResponse {
171  // Only set in case of errors, when |data_source_id| == 0.
172  optional string error = 1;
173};
174
175// Arguments for rpc UnregisterDataSource().
176
177message UnregisterDataSourceRequest {
178  // The name of the data source to unregister, as previously passed in
179  // |RegisterDataSourceRequest.name|.
180  optional string data_source_name = 1;
181}
182
183message UnregisterDataSourceResponse {}
184
185// Arguments for rpc RegisterTraceWriter().
186
187message RegisterTraceWriterRequest {
188  // The ID of a producer's trace writer.
189  optional uint32 trace_writer_id = 1;
190
191  // The ID of the target buffer that the trace writer commits its chunks to.
192  optional uint32 target_buffer = 2;
193}
194
195message RegisterTraceWriterResponse {}
196
197// Arguments for rpc UnregisterTraceWriter().
198
199message UnregisterTraceWriterRequest {
200  // The ID of a producer's trace writer.
201  optional uint32 trace_writer_id = 1;
202}
203
204message UnregisterTraceWriterResponse {}
205
206// Arguments for rpc CommitData().
207// See commit_data_request.proto for CommitDataRequest. That has its own file
208// because it is used also as input to generate C++ classes (xxx.gen.h).
209
210message CommitDataResponse {}
211
212// Arguments for rpc NotifyDataSourceStarted().
213
214message NotifyDataSourceStartedRequest {
215  // ID of the data source that has successfully started.
216  optional uint64 data_source_id = 1;
217}
218
219message NotifyDataSourceStartedResponse {}
220
221// Arguments for rpc NotifyDataSourceStopped().
222
223message NotifyDataSourceStoppedRequest {
224  // ID of the data source that has successfully stopped.
225  optional uint64 data_source_id = 1;
226}
227
228message NotifyDataSourceStoppedResponse {}
229
230// Arguments for rpc ActivateTriggersRequest().
231
232message ActivateTriggersRequest {
233  repeated string trigger_names = 1;
234}
235
236message ActivateTriggersResponse {}
237
238// Arguments for rpc GetAsyncCommand().
239
240message GetAsyncCommandRequest {}
241
242message GetAsyncCommandResponse {
243  // Called after SetupTracing and before StartDataSource.
244  // This message was introduced in Android Q.
245  message SetupDataSource {
246    optional uint64 new_instance_id = 1;
247    optional protos.DataSourceConfig config = 2;
248  }
249
250  message StartDataSource {
251    optional uint64 new_instance_id = 1;
252
253    // For backwards compat reasons (with Android P), the config passed here
254    // is identical to the one passed to SetupDataSource.config.
255    optional protos.DataSourceConfig config = 2;
256  }
257
258  message StopDataSource { optional uint64 instance_id = 1; }
259
260  // This message also transports the file descriptor for the shared memory
261  // buffer (not a proto field).
262  message SetupTracing { optional uint32 shared_buffer_page_size_kb = 1; }
263
264  message Flush {
265    // The instance id (i.e. StartDataSource.new_instance_id) of the data
266    // sources to flush.
267    repeated uint64 data_source_ids = 1;
268
269    // A monotonic counter generated by the service. The producer is simply
270    // expected to copy this value back into the CommitDataRequest, so the
271    // service can tell when the data for this flush has been committed.
272    optional uint64 request_id = 2;
273  }
274
275  // Instructs the given data sources to stop referring to any trace contents
276  // emitted so far. Sent only to active data sources that set
277  // |handles_incremental_state_clear| in their DataSourceDescriptor.
278  //
279  // Added to perfetto tree in May 2019.
280  message ClearIncrementalState {
281    // The instance id (i.e. StartDataSource.new_instance_id) of the data
282    // sources that should clear their incremental state.
283    repeated uint64 data_source_ids = 1;
284  }
285
286  // Next id: 8.
287  oneof cmd {
288    SetupTracing setup_tracing = 3;
289    SetupDataSource setup_data_source = 6;
290    StartDataSource start_data_source = 1;
291    StopDataSource stop_data_source = 2;
292    // id == 4 was teardown_tracing, never implemented.
293    Flush flush = 5;
294    ClearIncrementalState clear_incremental_state = 7;
295  }
296}
297
298// Arguments for rpc Sync().
299message SyncRequest {}
300message SyncResponse {}
301