aboutsummaryrefslogtreecommitdiff
path: root/protos/perfetto/ipc/producer_port.proto
blob: 50b90e7a2a7f54c6120ba5a97170397b9eb11501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

import "protos/perfetto/common/commit_data_request.proto";
import "protos/perfetto/config/data_source_config.proto";
import "protos/perfetto/common/data_source_descriptor.proto";

package perfetto.protos;

// IPC interface definition for the producer port of the tracing service.
service ProducerPort {
  // Called once only after establishing the connection with the Service.
  // The service replies sending the shared memory file descriptor in reply.
  rpc InitializeConnection(InitializeConnectionRequest)
      returns (InitializeConnectionResponse) {}

  // Advertises a data source.
  rpc RegisterDataSource(RegisterDataSourceRequest)
      returns (RegisterDataSourceResponse) {}

  // Unregisters a previously registered data source.
  rpc UnregisterDataSource(UnregisterDataSourceRequest)
      returns (UnregisterDataSourceResponse) {}

  // Sent by the client to request the service to:
  // 1) Move some chunks from the shmem buffer into the logging buffer.
  // 2) Patch the content of some chunks previously moved.
  // 3) Acknowledge a Flush() request.
  rpc CommitData(protos.CommitDataRequest) returns (CommitDataResponse) {}

  // This is a backchannel to get asynchronous commands / notifications back
  // from the Service.
  rpc GetAsyncCommand(GetAsyncCommandRequest)
      returns (stream GetAsyncCommandResponse) {}

  // ----------------------------------------------------
  // All methods below have been introduced in Android Q.
  // ----------------------------------------------------

  // Associates a trace writer with its target buffer.
  rpc RegisterTraceWriter(RegisterTraceWriterRequest)
      returns (RegisterTraceWriterResponse) {}

  // Removes a trace writer association previously added by
  // RegisterTraceWriter.
  rpc UnregisterTraceWriter(UnregisterTraceWriterRequest)
      returns (UnregisterTraceWriterResponse) {}

  // Sent by the client in response to a StartDataSource message, when a data
  // source is successfully started. This is expected only for data sources that
  // set the DataSourceDescriptor.will_notify_on_start flag when registering.
  rpc NotifyDataSourceStarted(NotifyDataSourceStartedRequest)
      returns (NotifyDataSourceStartedResponse) {}

  // Sent by the client in response to a StopDataSource message, when a data
  // source is successfully stopped. This is expected only for data sources that
  // set the DataSourceDescriptor.will_notify_on_stop flag when registering.
  rpc NotifyDataSourceStopped(NotifyDataSourceStoppedRequest)
      returns (NotifyDataSourceStoppedResponse) {}

  // Sent by the client to request the service to:
  // 1) Find all sessions which define these triggers
  // 2) Perform an action as defined in those sessions configs.
  rpc ActivateTriggers(ActivateTriggersRequest)
      returns (ActivateTriggersResponse) {}

  // ----------------------------------------------------
  // All methods below have been introduced in Android R.
  // ----------------------------------------------------

  // This is used to linearize the producer with the service and to guarantee
  // that all IPCs prior to this call have been seen and processed by the
  // service. Example:
  //   - RegisterDataSource(A)
  //   - RegisterDataSource(B)
  //   - Sync()
  // When the Sync() response is received, the producer is guaranteed that the
  // service has seen both data source registrations.
  rpc Sync(SyncRequest) returns (SyncResponse) {}
}

// Arguments for rpc InitializeConnection().
message InitializeConnectionRequest {
  // Optional. Provides a hint to the tracing service about the suggested size
  // of the shared memory buffer pages. The service is not required to respect
  // this if it has already another value in the configuration or if the hint
  // is unreasonably large. Must be an integer multiple of 4096. See tradeoff
  // considerations in shared_memory_abi.h.
  optional uint32 shared_memory_page_size_hint_bytes = 1;

  // Optional. Provides a hint to the tracing service about the suggested size
  // of the shared memory buffer. The service is not required to respect this
  // and might return a smaller buffer.
  optional uint32 shared_memory_size_hint_bytes = 2;

  // Required to match the producer config set by the service to the correct
  // producer.
  optional string producer_name = 3;

  enum ProducerSMBScrapingMode {
    // Use the service's default setting for SMB scraping.
    SMB_SCRAPING_UNSPECIFIED = 0;

    // Enable scraping of uncommitted chunks from the producer's shared memory
    // buffer.
    SMB_SCRAPING_ENABLED = 1;

    // Disable scraping of uncommitted chunks from the producer's shared memory
    // buffer.
    SMB_SCRAPING_DISABLED = 2;
  }

  // If provided, overrides the service's SMB scraping setting for the producer.
  optional ProducerSMBScrapingMode smb_scraping_mode = 4;

  enum ProducerBuildFlags {
    BUILD_FLAGS_UNSPECIFIED = 0;
    BUILD_FLAGS_DCHECKS_ON = 1;
    BUILD_FLAGS_DCHECKS_OFF = 2;
  }

  // If provided, reports the build flags of the producer. It's used merely for
  // error reporting, to print a log message when a producer connects to a
  // service that has mismatching build flags.
  optional ProducerBuildFlags build_flags = 5;

  // ---------------------------------------------------
  // All fields below have been introduced in Android R.
  // ---------------------------------------------------

  // Since Android R, this request can also transport an FD for the producer's
  // shared memory buffer, if allocated by the producer (e.g. for startup
  // tracing). In this case, |shared_memory_page_size_hint_bytes| is a required
  // field, and describes the SMB's page size. Note that the service may not
  // accept this SMB (e.g. because it is too old or its size / page size are
  // invalid) and instead allocate a new SMB which is provided in the
  // SetupTracing response. See TracingService::ConnectProducer() and
  // |using_shmem_provided_by_producer| in InitializeConnectionResponse.
  optional bool producer_provided_shmem = 6;

  // ---------------------------------------------------
  // All fields below have been introduced in Android S.
  // ---------------------------------------------------

  // The version of the client library used by the producer.
  // This is a human readable string with and its format varies depending on
  // the build system that is used to build the code and the repo (standalone
  // vs AOSP). This is intended for human debugging only.
  optional string sdk_version = 8;
}

message InitializeConnectionResponse {
  // Indicates whether the service accepted the SMB provided by the producer in
  // InitializeConnectionRequest (if any). If false, the shared memory buffer FD
  // will provided by the service via the SetupTracing async command.
  optional bool using_shmem_provided_by_producer = 1;

  // Indicates to the producer that the service allows direct SMB patching of
  // chunks that have not yet been committed to it.
  // This field has been introduced in Android S.
  optional bool direct_smb_patching_supported = 2;
}

// Arguments for rpc RegisterDataSource().

message RegisterDataSourceRequest {
  optional protos.DataSourceDescriptor data_source_descriptor = 1;
}

message RegisterDataSourceResponse {
  // Only set in case of errors, when |data_source_id| == 0.
  optional string error = 1;
};

// Arguments for rpc UnregisterDataSource().

message UnregisterDataSourceRequest {
  // The name of the data source to unregister, as previously passed in
  // |RegisterDataSourceRequest.name|.
  optional string data_source_name = 1;
}

message UnregisterDataSourceResponse {}

// Arguments for rpc RegisterTraceWriter().

message RegisterTraceWriterRequest {
  // The ID of a producer's trace writer.
  optional uint32 trace_writer_id = 1;

  // The ID of the target buffer that the trace writer commits its chunks to.
  optional uint32 target_buffer = 2;
}

message RegisterTraceWriterResponse {}

// Arguments for rpc UnregisterTraceWriter().

message UnregisterTraceWriterRequest {
  // The ID of a producer's trace writer.
  optional uint32 trace_writer_id = 1;
}

message UnregisterTraceWriterResponse {}

// Arguments for rpc CommitData().
// See commit_data_request.proto for CommitDataRequest. That has its own file
// because it is used also as input to generate C++ classes (xxx.gen.h).

message CommitDataResponse {}

// Arguments for rpc NotifyDataSourceStarted().

message NotifyDataSourceStartedRequest {
  // ID of the data source that has successfully started.
  optional uint64 data_source_id = 1;
}

message NotifyDataSourceStartedResponse {}

// Arguments for rpc NotifyDataSourceStopped().

message NotifyDataSourceStoppedRequest {
  // ID of the data source that has successfully stopped.
  optional uint64 data_source_id = 1;
}

message NotifyDataSourceStoppedResponse {}

// Arguments for rpc ActivateTriggersRequest().

message ActivateTriggersRequest {
  repeated string trigger_names = 1;
}

message ActivateTriggersResponse {}

// Arguments for rpc GetAsyncCommand().

message GetAsyncCommandRequest {}

message GetAsyncCommandResponse {
  // Called after SetupTracing and before StartDataSource.
  // This message was introduced in Android Q.
  message SetupDataSource {
    optional uint64 new_instance_id = 1;
    optional protos.DataSourceConfig config = 2;
  }

  message StartDataSource {
    optional uint64 new_instance_id = 1;

    // For backwards compat reasons (with Android P), the config passed here
    // is identical to the one passed to SetupDataSource.config.
    optional protos.DataSourceConfig config = 2;
  }

  message StopDataSource { optional uint64 instance_id = 1; }

  // On Android/Linux/Mac this message also transports the file descriptor for
  // the shared memory buffer (not a proto field).
  message SetupTracing {
    optional uint32 shared_buffer_page_size_kb = 1;
  }

  message Flush {
    // The instance id (i.e. StartDataSource.new_instance_id) of the data
    // sources to flush.
    repeated uint64 data_source_ids = 1;

    // A monotonic counter generated by the service. The producer is simply
    // expected to copy this value back into the CommitDataRequest, so the
    // service can tell when the data for this flush has been committed.
    optional uint64 request_id = 2;
  }

  // Instructs the given data sources to stop referring to any trace contents
  // emitted so far. Sent only to active data sources that set
  // |handles_incremental_state_clear| in their DataSourceDescriptor.
  //
  // Added to perfetto tree in May 2019.
  message ClearIncrementalState {
    // The instance id (i.e. StartDataSource.new_instance_id) of the data
    // sources that should clear their incremental state.
    repeated uint64 data_source_ids = 1;
  }

  // Next id: 8.
  oneof cmd {
    SetupTracing setup_tracing = 3;
    SetupDataSource setup_data_source = 6;
    StartDataSource start_data_source = 1;
    StopDataSource stop_data_source = 2;
    // id == 4 was teardown_tracing, never implemented.
    Flush flush = 5;
    ClearIncrementalState clear_incremental_state = 7;
  }
}

// Arguments for rpc Sync().
message SyncRequest {}
message SyncResponse {}