• 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/config/data_source_config.proto";
20import "protos/perfetto/common/builtin_clock.proto";
21
22package perfetto.protos;
23
24// The overall config that is used when starting a new tracing session through
25// ProducerPort::StartTracing().
26// It contains the general config for the logging buffer(s) and the configs for
27// all the data source being enabled.
28//
29// Next id: 33.
30message TraceConfig {
31  message BufferConfig {
32    optional uint32 size_kb = 1;
33
34    // |page_size|, now deprecated.
35    reserved 2;
36
37    // |optimize_for|, now deprecated.
38    reserved 3;
39
40    enum FillPolicy {
41      UNSPECIFIED = 0;
42
43      // Default behavior. The buffer operates as a conventional ring buffer.
44      // If the writer is faster than the reader (or if the reader reads only
45      // after tracing is stopped) newly written packets will overwrite old
46      // packets.
47      RING_BUFFER = 1;
48
49      // Behaves like RING_BUFFER as long as there is space in the buffer or
50      // the reader catches up with the writer. As soon as the writer hits
51      // an unread chunk, it stops accepting new data in the buffer.
52      DISCARD = 2;
53    }
54    optional FillPolicy fill_policy = 4;
55  }
56  repeated BufferConfig buffers = 1;
57
58  message DataSource {
59    // Filters and data-source specific config. It contains also the unique name
60    // of the data source, the one passed in the  DataSourceDescriptor when they
61    // register on the service.
62    optional protos.DataSourceConfig config = 1;
63
64    // Optional. If multiple producers (~processes) expose the same data source
65    // and either |producer_name_filter| or |producer_name_regex_filter| is set,
66    // the data source is enabled only for producers whose names match any of
67    // the filters.
68    // |producer_name_filter| has to be an exact match, while
69    // |producer_name_regex_filter| is a regular expression.
70    // This allows to enable a data source only for specific processes.
71    // The "repeated" fields have OR semantics: specifying a filter ["foo",
72    // "bar"] will enable data sources on both "foo" and "bar" (if they exist).
73    repeated string producer_name_filter = 2;
74    repeated string producer_name_regex_filter = 3;
75  }
76  repeated DataSource data_sources = 2;
77
78  // Config for disabling builtin data sources in the tracing service.
79  message BuiltinDataSource {
80    // Disable emitting clock timestamps into the trace.
81    optional bool disable_clock_snapshotting = 1;
82
83    // Disable echoing the original trace config in the trace.
84    optional bool disable_trace_config = 2;
85
86    // Disable emitting system info (build fingerprint, cpuinfo, etc).
87    optional bool disable_system_info = 3;
88
89    // Disable emitting events for data-source state changes (e.g. the marker
90    // for all data sources having ACKed the start of the trace).
91    optional bool disable_service_events = 4;
92
93    // The authoritative clock domain for the trace. Defaults to BOOTTIME. See
94    // also ClockSnapshot's primary_trace_clock. The configured value is written
95    // into the trace as part of the ClockSnapshots emitted by the service.
96    // Trace processor will attempt to translate packet/event timestamps from
97    // various data sources (and their chosen clock domains) to this domain
98    // during import. Added in Android R.
99    optional BuiltinClock primary_trace_clock = 5;
100
101    // Time interval in between snapshotting of sync markers, clock snapshots,
102    // stats, and other periodic service-emitted events. Note that the service
103    // only keeps track of the first and the most recent snapshot until
104    // ReadBuffers() is called.
105    optional uint32 snapshot_interval_ms = 6;
106
107    // Hints to the service that a suspend-aware (i.e. counting time in suspend)
108    // clock should be used for periodic snapshots of service-emitted events.
109    // This means, if a snapshot *should* have happened during suspend, it will
110    // happen immediately after the device resumes.
111    //
112    // Choosing a clock like this is done on best-effort basis; not all
113    // platforms (e.g. Windows) expose a clock which can be used for periodic
114    // tasks counting suspend. If such a clock is not available, the service
115    // falls back to the best-available alternative.
116    //
117    // Introduced in Android S.
118    // TODO(lalitm): deprecate this in T and make this the default if nothing
119    // crashes in S.
120    optional bool prefer_suspend_clock_for_snapshot = 7;
121  }
122  optional BuiltinDataSource builtin_data_sources = 20;
123
124  // If specified, the trace will be stopped |duration_ms| after starting.
125  // This does *not* count the time the system is suspended, so we will run
126  // for duration_ms of system activity, not wall time.
127  //
128  // However in case of traces with triggers, see
129  // TriggerConfig.trigger_timeout_ms instead.
130  optional uint32 duration_ms = 3;
131
132  // This is set when --dropbox is passed to the Perfetto command line client
133  // and enables guardrails that limit resource usage for traces requested
134  // by statsd.
135  optional bool enable_extra_guardrails = 4;
136
137  enum LockdownModeOperation {
138    LOCKDOWN_UNCHANGED = 0;
139    LOCKDOWN_CLEAR = 1;
140    LOCKDOWN_SET = 2;
141  }
142  // Reject producers that are not running under the same UID as the tracing
143  // service.
144  optional LockdownModeOperation lockdown_mode = 5;
145
146  message ProducerConfig {
147    // Identifies the producer for which this config is for.
148    optional string producer_name = 1;
149
150    // Specifies the preferred size of the shared memory buffer. If the size is
151    // larger than the max size, the max will be used. If it is smaller than
152    // the page size or doesn't fit pages evenly into it, it will fall back to
153    // the size specified by the producer or finally the default shared memory
154    // size.
155    optional uint32 shm_size_kb = 2;
156
157    // Specifies the preferred size of each page in the shared memory buffer.
158    // Must be an integer multiple of 4K.
159    optional uint32 page_size_kb = 3;
160  }
161
162  repeated ProducerConfig producers = 6;
163
164  // Contains statsd-specific metadata about an alert associated with the trace.
165  message StatsdMetadata {
166    // The identifier of the alert which triggered this trace.
167    optional int64 triggering_alert_id = 1;
168    // The uid which registered the triggering configuration with statsd.
169    optional int32 triggering_config_uid = 2;
170    // The identifier of the config which triggered the alert.
171    optional int64 triggering_config_id = 3;
172    // The identifier of the subscription which triggered this trace.
173    optional int64 triggering_subscription_id = 4;
174  }
175
176  // Statsd-specific metadata.
177  optional StatsdMetadata statsd_metadata = 7;
178
179  // When true && |output_path| is empty, the EnableTracing() request must
180  // provide a file descriptor. The service will then periodically read packets
181  // out of the trace buffer and store it into the passed file.
182  // If |output_path| is not empty no fd should be passed, the service
183  // will create a new file and write into that (see comment below).
184  optional bool write_into_file = 8;
185
186  // This must point to a non-existing file. If the file exists the service
187  // will NOT overwrite and will fail instead as a security precaution.
188  // On Android, when this is used with the system traced, the path must be
189  // within /data/misc/perfetto-traces/ or the trace will fail.
190  // This option has been introduced in Android R. Before R write_into_file
191  // can be used only with the "pass a file descriptor over IPC" mode.
192  optional string output_path = 29;
193
194  // Optional. If non-zero tunes the write period. A min value of 100ms is
195  // enforced (i.e. smaller values are ignored).
196  optional uint32 file_write_period_ms = 9;
197
198  // Optional. When non zero the periodic write stops once at most X bytes
199  // have been written into the file. Tracing is disabled when this limit is
200  // reached, even if |duration_ms| has not been reached yet.
201  optional uint64 max_file_size_bytes = 10;
202
203  // Contains flags which override the default values of the guardrails inside
204  // Perfetto.
205  message GuardrailOverrides {
206    // Override the default limit (in bytes) for uploading data to server within
207    // a 24 hour period.
208    // On R-, this override only affected userdebug builds. Since S, it also
209    // affects user builds.
210    optional uint64 max_upload_per_day_bytes = 1;
211  }
212  optional GuardrailOverrides guardrail_overrides = 11;
213
214  // When true, data sources are not started until an explicit call to
215  // StartTracing() on the consumer port. This is to support early
216  // initialization and fast trace triggering. This can be used only when the
217  // Consumer explicitly triggers the StartTracing() method.
218  // This should not be used in a remote trace config via statsd, doing so will
219  // result in a hung trace session.
220  optional bool deferred_start = 12;
221
222  // When set, it periodically issues a Flush() to all data source, forcing them
223  // to commit their data into the tracing service. This can be used for
224  // quasi-real-time streaming mode and to guarantee some partial ordering of
225  // events in the trace in windows of X ms.
226  optional uint32 flush_period_ms = 13;
227
228  // Wait for this long for producers to acknowledge flush requests.
229  // Default 5s.
230  optional uint32 flush_timeout_ms = 14;
231
232  // Wait for this long for producers to acknowledge stop requests.
233  // Default 5s.
234  optional uint32 data_source_stop_timeout_ms = 23;
235
236  // |disable_clock_snapshotting| moved.
237  reserved 15;
238
239  // Android-only. If set, sends an intent to the Traceur system app when the
240  // trace ends to notify it about the trace readiness.
241  optional bool notify_traceur = 16;
242
243  // Android-only. If set to a value > 0, marks the trace session as a candidate
244  // for being attached to a bugreport. This field effectively acts as a z-index
245  // for bugreports. When Android's dumpstate runs perfetto
246  // --save-for-bugreport, traced will pick the tracing session with the highest
247  // score (score <= 0 is ignored), will steal its contents, save the trace into
248  // a known path and stop prematurely.
249  // This field was introduced in Android S.
250  optional int32 bugreport_score = 30;
251
252  // Triggers allow producers to start or stop the tracing session when an event
253  // occurs.
254  //
255  // For example if we are tracing probabilistically, most traces will be
256  // uninteresting. Triggers allow us to keep only the interesting ones such as
257  // those traces during which the device temperature reached a certain
258  // threshold. In this case the producer can activate a trigger to keep
259  // (STOP_TRACING) the trace, otherwise it can also begin a trace
260  // (START_TRACING) because it knows something is about to happen.
261  message TriggerConfig {
262    enum TriggerMode {
263      UNSPECIFIED = 0;
264
265      // When this mode is chosen, data sources are not started until one of the
266      // |triggers| are received. This supports early initialization and fast
267      // starting of the tracing system. On triggering, the session will then
268      // record for |stop_delay_ms|. However if no trigger is seen
269      // after |trigger_timeout_ms| the session will be stopped and no data will
270      // be returned.
271      START_TRACING = 1;
272
273      // When this mode is chosen, the session will be started via the normal
274      // EnableTracing() & StartTracing(). If no trigger is ever seen
275      // the session will be stopped after |trigger_timeout_ms| and no data will
276      // be returned. However if triggered the trace will stop after
277      // |stop_delay_ms| and any data in the buffer will be returned to the
278      // consumer.
279      STOP_TRACING = 2;
280    }
281    optional TriggerMode trigger_mode = 1;
282
283    message Trigger {
284      // The producer must specify this name to activate the trigger.
285      optional string name = 1;
286
287      // An std::regex that will match the producer that can activate this
288      // trigger. This is optional. If unset any producers can activate this
289      // trigger.
290      optional string producer_name_regex = 2;
291
292      // After a trigger is received either in START_TRACING or STOP_TRACING
293      // mode then the trace will end |stop_delay_ms| after triggering.
294      optional uint32 stop_delay_ms = 3;
295
296      // Limits the number of traces this trigger can start/stop in a rolling
297      // 24 hour window. If this field is unset or zero, no limit is applied and
298      // activiation of this trigger *always* starts/stops the trace.
299      optional uint32 max_per_24_h = 4;
300
301      // A value between 0 and 1 which encodes the probability of skipping a
302      // trigger with this name. This is useful for reducing the probability
303      // of high-frequency triggers from dominating trace finaization. If this
304      // field is unset or zero, the trigger will *never* be skipped. If this
305      // field is greater than or equal to 1, this trigger will *always* be
306      // skipped i.e. it will be as if this trigger was never included in the
307      // first place.
308      // This probability check is applied *before* any other limits. For
309      // example, if |max_per_24_h| is also set, first we will check if the
310      // probability bar is met and only then will we check the |max_per_24_h|
311      // limit.
312      optional double skip_probability = 5;
313    }
314    // A list of triggers which are related to this configuration. If ANY
315    // trigger is seen then an action will be performed based on |trigger_mode|.
316    repeated Trigger triggers = 2;
317
318    // Required and must be positive if a TriggerConfig is specified. This is
319    // how long this TraceConfig should wait for a trigger to arrive. After this
320    // period of time if no trigger is seen the TracingSession will be cleaned
321    // up.
322    optional uint32 trigger_timeout_ms = 3;
323  }
324  optional TriggerConfig trigger_config = 17;
325
326  // When this is non-empty the perfetto command line tool will ignore the rest
327  // of this TraceConfig and instead connect to the perfetto service as a
328  // producer and send these triggers, potentially stopping or starting traces
329  // that were previous configured to use a TriggerConfig.
330  repeated string activate_triggers = 18;
331
332  // Configuration for trace contents that reference earlier trace data. For
333  // example, a data source might intern strings, and emit packets containing
334  // {interned id : string} pairs. Future packets from that data source can then
335  // use the interned ids instead of duplicating the raw string contents. The
336  // trace parser will then need to use that interning table to fully interpret
337  // the rest of the trace.
338  message IncrementalStateConfig {
339    // If nonzero, notify eligible data sources to clear their incremental state
340    // periodically, with the given period. The notification is sent only to
341    // data sources that have |handles_incremental_state_clear| set in their
342    // DataSourceDescriptor. The notification requests that the data source
343    // stops referring to past trace contents. This is particularly useful when
344    // tracing in ring buffer mode, where it is not exceptional to overwrite old
345    // trace data.
346    //
347    // Warning: this time-based global clearing is likely to be removed in the
348    // future, to be replaced with a smarter way of sending the notifications
349    // only when necessary.
350    optional uint32 clear_period_ms = 1;
351  }
352  optional IncrementalStateConfig incremental_state_config = 21;
353
354  // Additional guardrail used by the Perfetto command line client.
355  // On user builds when --dropbox is set perfetto will refuse to trace unless
356  // this is also set.
357  // Added in Q.
358  optional bool allow_user_build_tracing = 19;
359
360  // If set the tracing service will ensure there is at most one tracing session
361  // with this key.
362  optional string unique_session_name = 22;
363
364  // Compress trace with the given method. Best effort.
365  enum CompressionType {
366    COMPRESSION_TYPE_UNSPECIFIED = 0;
367    COMPRESSION_TYPE_DEFLATE = 1;
368  }
369  optional CompressionType compression_type = 24;
370
371  // Android-only. Not for general use. If set, saves the trace into an
372  // incident. This field is read by perfetto_cmd, rather than the tracing
373  // service. This field must be set when passing the --upload flag to
374  // perfetto_cmd.
375  message IncidentReportConfig {
376    // In this message, either:
377    //  * all of |destination_package|, |destination_class| and |privacy_level|
378    //    must be set.
379    //  * |skip_incidentd| must be explicitly set to true.
380
381    optional string destination_package = 1;
382    optional string destination_class = 2;
383    // Level of filtering in the requested incident. See |Destination| in
384    // frameworks/base/core/proto/android/privacy.proto.
385    optional int32 privacy_level = 3;
386
387    // If true, then skips saving the trace to incidentd.
388    //
389    // This flag is useful in testing (e.g. Perfetto-statsd integration tests)
390    // or when we explicitly don't want traces to go to incidentd even when they
391    // usually would (e.g. configs deployed using statsd but only used for
392    // inclusion in bugreports using |bugreport_score|).
393    //
394    // The motivation for having this flag, instead of just not setting
395    // |incident_report_config|, is prevent accidents where
396    // |incident_report_config| is omitted by mistake.
397    optional bool skip_incidentd = 5;
398
399    // If true, do not write the trace into dropbox (i.e. incident only).
400    // Otherwise, write to both dropbox and incident.
401    // TODO(lalitm): remove this field as we no longer use Dropbox.
402    optional bool skip_dropbox = 4 [deprecated = true];
403  }
404  optional IncidentReportConfig incident_report_config = 25;
405
406  enum StatsdLogging {
407    STATSD_LOGGING_UNSPECIFIED = 0;
408    STATSD_LOGGING_ENABLED = 1;
409    STATSD_LOGGING_DISABLED = 2;
410  }
411
412  // Android-only. Not for general use. If specified, sets the logging to statsd
413  // of guardrails and checkpoints in the tracing service. perfetto_cmd sets
414  // this to enabled (if not explicitly set in the config) when specifying
415  // --upload.
416  optional StatsdLogging statsd_logging = 31;
417
418  // DEPRECATED. Was trace_uuid, use trace_uuid_msb and trace_uuid_lsb instead.
419  reserved 26;
420  // An identifier clients can use to tie this trace to other logging.
421  // Alternative encoding of trace_uuid as two int64s.
422  optional int64 trace_uuid_msb = 27;
423  optional int64 trace_uuid_lsb = 28;
424
425  // When set applies a post-filter to the trace contents using the filter
426  // provided. The filter is applied at ReadBuffers() time and works both in the
427  // case of IPC readback and write_into_file. This filter can be generated
428  // using `tools/proto_filter -s schema.proto -F filter_out.bytes` or
429  // `-T filter_out.escaped_string` (for .pbtx).
430  // Introduced in Android S. See go/trace-filtering for design.
431  message TraceFilter { optional bytes bytecode = 1; }
432  optional TraceFilter trace_filter = 32;
433}
434