• 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
19package perfetto.protos;
20
21import "protos/perfetto/common/builtin_clock.proto";
22import "protos/perfetto/config/data_source_config.proto";
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: 40.
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    // When true the buffer is moved (rather than copied) onto the cloned
57    // session, and an empty buffer of the same size is allocated in the source
58    // tracing session. This feature will likely get deprecated in the future.
59    // It been introduced mainly to support the surfaceflinger snapshot dump
60    // for bugreports, where SF can dumps O(400MB) into the bugreport trace. In
61    // that case we don't want to retain another in-memory copy of the buffer.
62    optional bool transfer_on_clone = 5;
63
64    // Used in conjunction with transfer_on_clone. When true the buffer is
65    // cleared before issuing the Flush(reason=kTraceClone). This is to ensure
66    // that if the data source took too long to write the data in a previous
67    // clone-related flush, we don't end up with a mixture of leftovers from
68    // the previous write and new data.
69    optional bool clear_before_clone = 6;
70  }
71  repeated BufferConfig buffers = 1;
72
73  message DataSource {
74    // Filters and data-source specific config. It contains also the unique name
75    // of the data source, the one passed in the  DataSourceDescriptor when they
76    // register on the service.
77    optional protos.DataSourceConfig config = 1;
78
79    // Optional. If multiple producers (~processes) expose the same data source
80    // and either |producer_name_filter| or |producer_name_regex_filter| is set,
81    // the data source is enabled only for producers whose names match any of
82    // the filters.
83    // |producer_name_filter| has to be an exact match, while
84    // |producer_name_regex_filter| is a regular expression.
85    // This allows to enable a data source only for specific processes.
86    // The "repeated" fields have OR semantics: specifying a filter ["foo",
87    // "bar"] will enable data sources on both "foo" and "bar" (if they exist).
88    repeated string producer_name_filter = 2;
89    repeated string producer_name_regex_filter = 3;
90  }
91  repeated DataSource data_sources = 2;
92
93  // Config for disabling builtin data sources in the tracing service.
94  message BuiltinDataSource {
95    // Disable emitting clock timestamps into the trace.
96    optional bool disable_clock_snapshotting = 1;
97
98    // Disable echoing the original trace config in the trace.
99    optional bool disable_trace_config = 2;
100
101    // Disable emitting system info (build fingerprint, cpuinfo, etc).
102    optional bool disable_system_info = 3;
103
104    // Disable emitting events for data-source state changes (e.g. the marker
105    // for all data sources having ACKed the start of the trace).
106    optional bool disable_service_events = 4;
107
108    // The authoritative clock domain for the trace. Defaults to BOOTTIME. See
109    // also ClockSnapshot's primary_trace_clock. The configured value is written
110    // into the trace as part of the ClockSnapshots emitted by the service.
111    // Trace processor will attempt to translate packet/event timestamps from
112    // various data sources (and their chosen clock domains) to this domain
113    // during import. Added in Android R.
114    optional BuiltinClock primary_trace_clock = 5;
115
116    // Time interval in between snapshotting of sync markers, clock snapshots,
117    // stats, and other periodic service-emitted events. Note that the service
118    // only keeps track of the first and the most recent snapshot until
119    // ReadBuffers() is called.
120    optional uint32 snapshot_interval_ms = 6;
121
122    // Hints to the service that a suspend-aware (i.e. counting time in suspend)
123    // clock should be used for periodic snapshots of service-emitted events.
124    // This means, if a snapshot *should* have happened during suspend, it will
125    // happen immediately after the device resumes.
126    //
127    // Choosing a clock like this is done on best-effort basis; not all
128    // platforms (e.g. Windows) expose a clock which can be used for periodic
129    // tasks counting suspend. If such a clock is not available, the service
130    // falls back to the best-available alternative.
131    //
132    // Introduced in Android S.
133    // TODO(lalitm): deprecate this in T and make this the default if nothing
134    // crashes in S.
135    optional bool prefer_suspend_clock_for_snapshot = 7;
136
137    // Disables the reporting of per-trace-writer histograms in TraceStats.
138    optional bool disable_chunk_usage_histograms = 8;
139  }
140  optional BuiltinDataSource builtin_data_sources = 20;
141
142  // If specified, the trace will be stopped |duration_ms| after starting.
143  // This does *not* count the time the system is suspended, so we will run
144  // for duration_ms of system activity, not wall time.
145  //
146  // However in case of traces with triggers, see
147  // TriggerConfig.trigger_timeout_ms instead.
148  optional uint32 duration_ms = 3;
149
150  // If true, tries to use CLOCK_BOOTTIME for duration_ms rather than
151  // CLOCK_MONOTONIC (which doesn't count time in suspend). Supported only on
152  // Linux/Android, no-op on other platforms. This is used when dealing with
153  // long (e.g. 24h) traces, where suspend can inflate them to weeks of
154  // wall-time, making them more likely to hit device reboots (and hence loss).
155  // This option also changes consistently the semantic of
156  // TriggerConfig.stop_delay_ms.
157  optional bool prefer_suspend_clock_for_duration = 36;
158
159  // This is set when --dropbox is passed to the Perfetto command line client
160  // and enables guardrails that limit resource usage for traces requested
161  // by statsd.
162  optional bool enable_extra_guardrails = 4;
163
164  enum LockdownModeOperation {
165    LOCKDOWN_UNCHANGED = 0;
166    LOCKDOWN_CLEAR = 1;
167    LOCKDOWN_SET = 2;
168  }
169  // Reject producers that are not running under the same UID as the tracing
170  // service.
171  optional LockdownModeOperation lockdown_mode = 5;
172
173  message ProducerConfig {
174    // Identifies the producer for which this config is for.
175    optional string producer_name = 1;
176
177    // Specifies the preferred size of the shared memory buffer. If the size is
178    // larger than the max size, the max will be used. If it is smaller than
179    // the page size or doesn't fit pages evenly into it, it will fall back to
180    // the size specified by the producer or finally the default shared memory
181    // size.
182    optional uint32 shm_size_kb = 2;
183
184    // Specifies the preferred size of each page in the shared memory buffer.
185    // Must be an integer multiple of 4K.
186    optional uint32 page_size_kb = 3;
187  }
188
189  repeated ProducerConfig producers = 6;
190
191  // Contains statsd-specific metadata about an alert associated with the trace.
192  message StatsdMetadata {
193    // The identifier of the alert which triggered this trace.
194    optional int64 triggering_alert_id = 1;
195    // The uid which registered the triggering configuration with statsd.
196    optional int32 triggering_config_uid = 2;
197    // The identifier of the config which triggered the alert.
198    optional int64 triggering_config_id = 3;
199    // The identifier of the subscription which triggered this trace.
200    optional int64 triggering_subscription_id = 4;
201  }
202
203  // Statsd-specific metadata.
204  optional StatsdMetadata statsd_metadata = 7;
205
206  // When true && |output_path| is empty, the EnableTracing() request must
207  // provide a file descriptor. The service will then periodically read packets
208  // out of the trace buffer and store it into the passed file.
209  // If |output_path| is not empty no fd should be passed, the service
210  // will create a new file and write into that (see comment below).
211  optional bool write_into_file = 8;
212
213  // This must point to a non-existing file. If the file exists the service
214  // will NOT overwrite and will fail instead as a security precaution.
215  // On Android, when this is used with the system traced, the path must be
216  // within /data/misc/perfetto-traces/ or the trace will fail.
217  // This option has been introduced in Android R. Before R write_into_file
218  // can be used only with the "pass a file descriptor over IPC" mode.
219  optional string output_path = 29;
220
221  // Optional. If non-zero tunes the write period. A min value of 100ms is
222  // enforced (i.e. smaller values are ignored).
223  optional uint32 file_write_period_ms = 9;
224
225  // Optional. When non zero the periodic write stops once at most X bytes
226  // have been written into the file. Tracing is disabled when this limit is
227  // reached, even if |duration_ms| has not been reached yet.
228  optional uint64 max_file_size_bytes = 10;
229
230  // Contains flags which override the default values of the guardrails inside
231  // Perfetto.
232  message GuardrailOverrides {
233    // Override the default limit (in bytes) for uploading data to server within
234    // a 24 hour period.
235    // On R-, this override only affected userdebug builds. Since S, it also
236    // affects user builds.
237    // In 24Q3+ (V+), this override is a noop because upload guardrail logic
238    // was removed from Perfetto.
239    optional uint64 max_upload_per_day_bytes = 1 [deprecated = true];
240
241    // Overrides the guardrail for maximum trace buffer size.
242    // Available on U+
243    optional uint32 max_tracing_buffer_size_kb = 2;
244  }
245  optional GuardrailOverrides guardrail_overrides = 11;
246
247  // When true, data sources are not started until an explicit call to
248  // StartTracing() on the consumer port. This is to support early
249  // initialization and fast trace triggering. This can be used only when the
250  // Consumer explicitly triggers the StartTracing() method.
251  // This should not be used in a remote trace config via statsd, doing so will
252  // result in a hung trace session.
253  optional bool deferred_start = 12;
254
255  // When set, it periodically issues a Flush() to all data source, forcing them
256  // to commit their data into the tracing service. This can be used for
257  // quasi-real-time streaming mode and to guarantee some partial ordering of
258  // events in the trace in windows of X ms.
259  optional uint32 flush_period_ms = 13;
260
261  // Wait for this long for producers to acknowledge flush requests.
262  // Default 5s.
263  optional uint32 flush_timeout_ms = 14;
264
265  // Wait for this long for producers to acknowledge stop requests.
266  // Default 5s.
267  optional uint32 data_source_stop_timeout_ms = 23;
268
269  // |disable_clock_snapshotting| moved.
270  reserved 15;
271
272  // Android-only. If set, sends an intent to the Traceur system app when the
273  // trace ends to notify it about the trace readiness.
274  optional bool notify_traceur = 16;
275
276  // This field was introduced in Android S.
277  // Android-only. If set to a value > 0, marks the trace session as a candidate
278  // for being attached to a bugreport. This field effectively acts as a z-index
279  // for bugreports. When Android's dumpstate runs perfetto
280  // --save-for-bugreport, traced will pick the tracing session with the highest
281  // score (score <= 0 is ignored) and:
282  // On Android S, T:  will steal its contents, save the trace into
283  //     a known path and stop prematurely.
284  // On Android U+: will create a read-only snapshot and save that into a known
285  //     path, without stoppin the original tracing session.
286  // When this field is set the tracing session becomes eligible to be cloned
287  // by other UIDs.
288  optional int32 bugreport_score = 30;
289
290  // When set, defines name of the file that will be saved under
291  // /data/misc/perfetto-traces/bugreport/ when using --save-all-for-bugreport.
292  // If omitted, traces will be named systrace.pftrace, systrace_1.pftrace, etc,
293  // starting from the highest `bugreport_score`.
294  // Introduced in v42 / Android V.
295  optional string bugreport_filename = 38;
296
297  // Triggers allow producers to start or stop the tracing session when an event
298  // occurs.
299  //
300  // For example if we are tracing probabilistically, most traces will be
301  // uninteresting. Triggers allow us to keep only the interesting ones such as
302  // those traces during which the device temperature reached a certain
303  // threshold. In this case the producer can activate a trigger to keep
304  // (STOP_TRACING) the trace, otherwise it can also begin a trace
305  // (START_TRACING) because it knows something is about to happen.
306  message TriggerConfig {
307    enum TriggerMode {
308      UNSPECIFIED = 0;
309
310      // When this mode is chosen, data sources are not started until one of the
311      // |triggers| are received. This supports early initialization and fast
312      // starting of the tracing system. On triggering, the session will then
313      // record for |stop_delay_ms|. However if no trigger is seen
314      // after |trigger_timeout_ms| the session will be stopped and no data will
315      // be returned.
316      START_TRACING = 1;
317
318      // When this mode is chosen, the session will be started via the normal
319      // EnableTracing() & StartTracing(). If no trigger is ever seen
320      // the session will be stopped after |trigger_timeout_ms| and no data will
321      // be returned. However if triggered the trace will stop after
322      // |stop_delay_ms| and any data in the buffer will be returned to the
323      // consumer.
324      STOP_TRACING = 2;
325
326      // 3 was taken by CLONE_SNAPSHOT but that has been moved to 4.
327      // The early implementation of CLONE_SNAPSHOT had various bugs
328      // (b/290798988, b/290799105) and made it into Android U. The number
329      // change is to make sure nobody rolls out a config that hits the broken
330      // behaviour.
331      reserved 3;
332
333      // When this mode is chosen, this causes a snapshot of the current tracing
334      // session to be created after |stop_delay_ms| while the current tracing
335      // session continues undisturbed (% an extra flush). This mode can be
336      // used only when the tracing session is handled by the "perfetto" cmdline
337      // client (which is true in 90% of cases). Part of the business logic
338      // necessary for this behavior, and ensuing file handling, lives in
339      // perfetto_cmd.cc . On other consumers, this causes only a notification
340      // of the trigger through a CloneTriggerHit ObservableEvent. The custom
341      // consumer is supposed to call CloneSession() itself after the event.
342      // Use use_clone_snapshot_if_available=true when targeting older versions
343      // of perfetto.
344      CLONE_SNAPSHOT = 4;
345
346      // NOTE: CLONE_SNAPSHOT should be used only when we targeting Android V+
347      // (15+) / Perfetto v38+. A bug in older versions of the tracing service
348      // might cause indefinitely long tracing sessions (see b/274931668).
349    }
350    optional TriggerMode trigger_mode = 1;
351
352    // This flag is really a workaround for b/274931668. This is needed only
353    // when deploying configs to different versions of the tracing service.
354    // When this is set to true this has the same effect of setting trigger_mode
355    // to CLONE_SNAPSHOT on newer versions of the service. This boolean has been
356    // introduced to allow to have configs that use CLONE_SNAPSHOT on newer
357    // versions of Android and fall back to STOP_TRACING on older versions where
358    // CLONE_SNAPSHOT did not exist.
359    // When using this flag, trigger_mode must be set to STOP_TRACING.
360    optional bool use_clone_snapshot_if_available = 5;
361
362    // DEPRECATED, was use_clone_snapshot_if_available in U. See the comment
363    // around CLONE_SNAPSHOT.
364    reserved 4;
365
366    message Trigger {
367      // The producer must specify this name to activate the trigger.
368      optional string name = 1;
369
370      // An std::regex that will match the producer that can activate this
371      // trigger. This is optional. If unset any producers can activate this
372      // trigger.
373      optional string producer_name_regex = 2;
374
375      // After a trigger is received either in START_TRACING or STOP_TRACING
376      // mode then the trace will end |stop_delay_ms| after triggering.
377      // In CLONE_SNAPSHOT mode, this is the delay between the trigger and the
378      // snapshot.
379      // If |prefer_suspend_clock_for_duration| is set, the duration will be
380      // based on wall-clock, counting also time in suspend.
381      optional uint32 stop_delay_ms = 3;
382
383      // Limits the number of traces this trigger can start/stop in a rolling
384      // 24 hour window. If this field is unset or zero, no limit is applied and
385      // activiation of this trigger *always* starts/stops the trace.
386      optional uint32 max_per_24_h = 4;
387
388      // A value between 0 and 1 which encodes the probability of skipping a
389      // trigger with this name. This is useful for reducing the probability
390      // of high-frequency triggers from dominating trace finaization. If this
391      // field is unset or zero, the trigger will *never* be skipped. If this
392      // field is greater than or equal to 1, this trigger will *always* be
393      // skipped i.e. it will be as if this trigger was never included in the
394      // first place.
395      // This probability check is applied *before* any other limits. For
396      // example, if |max_per_24_h| is also set, first we will check if the
397      // probability bar is met and only then will we check the |max_per_24_h|
398      // limit.
399      optional double skip_probability = 5;
400    }
401    // A list of triggers which are related to this configuration. If ANY
402    // trigger is seen then an action will be performed based on |trigger_mode|.
403    repeated Trigger triggers = 2;
404
405    // Required and must be positive if a TriggerConfig is specified. This is
406    // how long this TraceConfig should wait for a trigger to arrive. After this
407    // period of time if no trigger is seen the TracingSession will be cleaned
408    // up.
409    optional uint32 trigger_timeout_ms = 3;
410  }
411  optional TriggerConfig trigger_config = 17;
412
413  // When this is non-empty the perfetto command line tool will ignore the rest
414  // of this TraceConfig and instead connect to the perfetto service as a
415  // producer and send these triggers, potentially stopping or starting traces
416  // that were previous configured to use a TriggerConfig.
417  repeated string activate_triggers = 18;
418
419  // Configuration for trace contents that reference earlier trace data. For
420  // example, a data source might intern strings, and emit packets containing
421  // {interned id : string} pairs. Future packets from that data source can then
422  // use the interned ids instead of duplicating the raw string contents. The
423  // trace parser will then need to use that interning table to fully interpret
424  // the rest of the trace.
425  message IncrementalStateConfig {
426    // If nonzero, notify eligible data sources to clear their incremental state
427    // periodically, with the given period. The notification is sent only to
428    // data sources that have |handles_incremental_state_clear| set in their
429    // DataSourceDescriptor. The notification requests that the data source
430    // stops referring to past trace contents. This is particularly useful when
431    // tracing in ring buffer mode, where it is not exceptional to overwrite old
432    // trace data.
433    //
434    // Warning: this time-based global clearing is likely to be removed in the
435    // future, to be replaced with a smarter way of sending the notifications
436    // only when necessary.
437    optional uint32 clear_period_ms = 1;
438  }
439  optional IncrementalStateConfig incremental_state_config = 21;
440
441  // No longer needed as we unconditionally allow tracing on user builds.
442  optional bool allow_user_build_tracing = 19 [deprecated = true];
443
444  // If set the tracing service will ensure there is at most one tracing session
445  // with this key.
446  optional string unique_session_name = 22;
447
448  // Compress trace with the given method. Best effort.
449  enum CompressionType {
450    COMPRESSION_TYPE_UNSPECIFIED = 0;
451    COMPRESSION_TYPE_DEFLATE = 1;
452  }
453  optional CompressionType compression_type = 24;
454
455  // DEPRECATED, was compress_from_cli.
456  reserved 37;
457
458  // Android-only. Not for general use. If set, saves the trace into an
459  // incident. This field is read by perfetto_cmd, rather than the tracing
460  // service. This field must be set when passing the --upload flag to
461  // perfetto_cmd.
462  message IncidentReportConfig {
463    // In this message, either:
464    //  * all of |destination_package|, |destination_class| and |privacy_level|
465    //    must be set.
466    //  * |skip_incidentd| must be explicitly set to true.
467
468    optional string destination_package = 1;
469    optional string destination_class = 2;
470    // Level of filtering in the requested incident. See |Destination| in
471    // frameworks/base/core/proto/android/privacy.proto.
472    optional int32 privacy_level = 3;
473
474    // If true, then skips saving the trace to incidentd.
475    //
476    // This flag is useful in testing (e.g. Perfetto-statsd integration tests)
477    // or when we explicitly don't want traces to go to incidentd even when they
478    // usually would (e.g. configs deployed using statsd but only used for
479    // inclusion in bugreports using |bugreport_score|).
480    //
481    // The motivation for having this flag, instead of just not setting
482    // |incident_report_config|, is prevent accidents where
483    // |incident_report_config| is omitted by mistake.
484    optional bool skip_incidentd = 5;
485
486    // If true, do not write the trace into dropbox (i.e. incident only).
487    // Otherwise, write to both dropbox and incident.
488    // TODO(lalitm): remove this field as we no longer use Dropbox.
489    optional bool skip_dropbox = 4 [deprecated = true];
490  }
491  optional IncidentReportConfig incident_report_config = 25;
492
493  enum StatsdLogging {
494    STATSD_LOGGING_UNSPECIFIED = 0;
495    STATSD_LOGGING_ENABLED = 1;
496    STATSD_LOGGING_DISABLED = 2;
497  }
498
499  // Android-only. Not for general use. If specified, sets the logging to statsd
500  // of guardrails and checkpoints in the tracing service. perfetto_cmd sets
501  // this to enabled (if not explicitly set in the config) when specifying
502  // --upload.
503  optional StatsdLogging statsd_logging = 31;
504
505  // DEPRECATED. Was trace_uuid, use trace_uuid_msb and trace_uuid_lsb instead.
506  reserved 26;
507
508  // An identifier clients can use to tie this trace to other logging.
509  // DEPRECATED as per v32. See TracePacket.trace_uuid for the authoritative
510  // Trace UUID. If this field is set, the tracing service will respect the
511  // requested UUID (i.e. TracePacket.trace_uuid == this field) but only if
512  // gap-less snapshotting is not used.
513  optional int64 trace_uuid_msb = 27 [deprecated = true];
514  optional int64 trace_uuid_lsb = 28 [deprecated = true];
515
516  // When set applies a post-filter to the trace contents using the filter
517  // provided. The filter is applied at ReadBuffers() time and works both in the
518  // case of IPC readback and write_into_file. This filter can be generated
519  // using `tools/proto_filter -s schema.proto -F filter_out.bytes` or
520  // `-T filter_out.escaped_string` (for .pbtx). See go/trace-filtering for
521  // design.
522  //
523  // Introduced in Android S, but it was broken (b/195065199). Reintroduced in
524  // Android T with a different field number. Updated in Android U with a new
525  // bytecode version which supports string filtering.
526  message TraceFilter {
527    // =========================
528    // Filter bytecode.
529    // =========================
530
531    // The bytecode as implemented in Android T.
532    optional bytes bytecode = 1;
533
534    // The bytecode as implemented in Android U. Adds support for string
535    // filtering.
536    optional bytes bytecode_v2 = 2;
537
538    // =========================
539    // String filtering
540    // =========================
541
542    // The principles and terminology of string filtering is heavily inspired by
543    // iptables. A "rule" decide how strings should be filtered. Each rule
544    // contains a "policy" which indicates the algorithm to use for filtering.
545    // A "chain" is a list of rules which will be sequentially checked against
546    // each string.
547    //
548    // The first rule which applies to the string terminates filtering for that
549    // string. If no rules apply, the string is left unchanged.
550
551    // A policy specifies which algorithm should be used for filtering the
552    // string.
553    enum StringFilterPolicy {
554      SFP_UNSPECIFIED = 0;
555
556      // Tries to match the string field against |regex_pattern|. If it
557      // matches, all matching groups are "redacted" (i.e. replaced with a
558      // constant string) and filtering is terminated (i.e. no further rules are
559      // checked). If it doesn't match, the string is left unchanged and the
560      // next rule in chain is considered.
561      SFP_MATCH_REDACT_GROUPS = 1;
562
563      // Like |SFP_MATCH_REDACT_GROUPS| but tries to do some pre-work before
564      // checking the regex. Specifically, it tries to parse the string field as
565      // an atrace tracepoint and checks if the post-tgid field starts with
566      // |atrace_post_tgid_starts_with|. The regex matching is only performed if
567      // this check succeeds.
568      SFP_ATRACE_MATCH_REDACT_GROUPS = 2;
569
570      // Tries to match the string field against |regex_pattern|. If it
571      // matches, filtering is terminated (i.e. no further rules are checked).
572      // If it doesn't match, the string is left unchanged and the next rule in
573      // chain is considered.
574      SFP_MATCH_BREAK = 3;
575
576      // Like |SFP_MATCH_BREAK| but tries to do some pre-work before checking
577      // the regex. Specifically, it tries to parse the string field as an
578      // atrace tracepoint and checks if the post-tgid field starts with
579      // |atrace_post_tgid_starts_with|. The regex matching is only performed if
580      // this check succeeds.
581      SFP_ATRACE_MATCH_BREAK = 4;
582
583      // Tries to repeatedly search (i.e. find substrings of) the string field
584      // with |regex_pattern|. For each match, redacts any matching groups (i.e.
585      // replaced with a constant string). Once there are no further matches,
586      // filtering is terminated (i.e. no further rules are checked).
587      //
588      // Note that this is policy is a "search" policy not a "match" policy
589      // unlike the above policies:
590      //  * Match policies require matching the full string i.e. there is an
591      //    implicit leading `^` and trailing `$`.
592      //  * Search policies perform repeated partial matching of the string
593      //    e.g.
594      //      - String: `foo=aaa,bar=123,foo=bbb,baz=456`
595      //      - Pattern: `foo=(\d+)`
596      //      - Output: `foo=P6O,bar=123,foo=P6O,baz=456`
597      //    where P6O is the redaction string
598      //
599      // All of this is only performed after some pre-work where we try to parse
600      // the string field as an atrace tracepoint and check if the post-tgid
601      // field starts with |atrace_post_tgid_starts_with|.
602      //
603      // If there are no partial matches, the string is left unchanged and the
604      // next rule in chain is considered.
605      SFP_ATRACE_REPEATED_SEARCH_REDACT_GROUPS = 5;
606    }
607
608    // A rule specifies how strings should be filtered.
609    message StringFilterRule {
610      // The policy (i.e. algorithm) dictating how strings matching this rule
611      // should be handled.
612      optional StringFilterPolicy policy = 1;
613
614      // The regex pattern used to match against each string.
615      optional string regex_pattern = 2;
616
617      // The string which should appear after the tgid in atrace tracepoint
618      // strings.
619      optional string atrace_payload_starts_with = 3;
620    }
621
622    // A chain is a list of rules which string will be sequentially checked
623    // against.
624    message StringFilterChain {
625      repeated StringFilterRule rules = 1;
626    }
627    optional StringFilterChain string_filter_chain = 3;
628  }
629  // old field number for trace_filter
630  reserved 32;
631  optional TraceFilter trace_filter = 33;
632
633  // Android-only. Not for general use. If set, reports the trace to the
634  // Android framework. This field is read by perfetto_cmd, rather than the
635  // tracing service. This field must be set when passing the --upload flag to
636  // perfetto_cmd.
637  message AndroidReportConfig {
638    // In this message, either:
639    //  * |reporter_service_package| and |reporter_service_class| must be set.
640    //  * |skip_reporting| must be explicitly set to true.
641
642    optional string reporter_service_package = 1;
643    optional string reporter_service_class = 2;
644
645    // If true, then skips reporting the trace to Android framework.
646    //
647    // This flag is useful in testing (e.g. Perfetto-statsd integration tests)
648    // or when we explicitly don't want to report traces to the framework even
649    // when they usually would (e.g. configs deployed using statsd but only
650    // used for inclusion in bugreports using |bugreport_score|).
651    //
652    // The motivation for having this flag, instead of just not setting
653    // |framework_report_config|, is prevent accidents where
654    // |framework_report_config| is omitted by mistake.
655    optional bool skip_report = 3;
656
657    // If true, will direct the Android framework to read the data in trace
658    // file and pass it to the reporter class over a pipe instead of passing
659    // the file descriptor directly.
660    //
661    // This flag is needed because the Android test framework does not
662    // currently support priv-app helper apps (in terms of SELinux) and we
663    // really don't want to add an allow rule for untrusted_app to receive
664    // trace fds.
665    //
666    // Because of this, we instead will direct the framework to create a new
667    // pipe and pass this to the reporter process instead. As the pipe is
668    // created by the framework, we won't have any problems with SELinux
669    // (system_server is already allowed to pass pipe fds, even
670    // to untrusted apps).
671    //
672    // As the name suggests this option *MUST* only be used for testing.
673    // Note that the framework will reject (and drop) files which are too
674    // large both for simplicity and to be minimize the amount of data we
675    // pass to a non-priv app (note that the framework will still check
676    // manifest permissions even though SELinux permissions are worked around).
677    optional bool use_pipe_in_framework_for_testing = 4;
678  }
679  optional AndroidReportConfig android_report_config = 34;
680
681  // If set, delays the start of tracing by a random duration. The duration is
682  // chosen from a uniform distribution between the specified minimum and
683  // maximum.
684  // Note: this delay is implemented by perfetto_cmd *not* by traced so will
685  // not work if you communicate with traced directly over the consumer API.
686  // Introduced in Android T.
687  message CmdTraceStartDelay {
688    optional uint32 min_delay_ms = 1;
689    optional uint32 max_delay_ms = 2;
690  }
691  optional CmdTraceStartDelay cmd_trace_start_delay = 35;
692
693  // When non-empty, ensures that for a each semaphore named `name at most
694  // `max_other_session_count`` *other* sessions (whose value is taken of the
695  // minimum of all values specified by this config or any already-running
696  // session) can be be running.
697  //
698  // If a semaphore "acquisition" fails, EnableTracing will return an error
699  // and the tracing session will not be started (or elgible to start in
700  // the case of deferred sessions).
701  //
702  // This is easiest to explain with an example. Suppose the tracing service has
703  // the following active tracing sessions:
704  //   S1 = [{name=foo, max_other_session_count=2},
705  //         {name=bar, max_other_session_count=0}]
706  //   S2 = [{name=foo, max_other_session_count=1},
707  //         {name=baz, max_other_session_count=1}]
708  //
709  // Then, for a new session, the following would be the expected behaviour of
710  // EnableSession given the state of `session_semaphores`.
711  //   Q: session_semaphores = []
712  //   A: Allowed because it does not specify any semaphores. Will be allowed
713  //      no matter the state of any other tracing session.
714  //   Q: session_semaphores = [{name=baz, max_other_session_count=1}]
715  //   A: Allowed because both S2 and this config specify
716  //      max_other_session_count=1 for baz.
717  //   Q: session_semaphores = [{name=foo, max_other_session_count=3}]
718  //   A: Denied because S2 specified max_other_session_count=1 for foo and S1
719  //      takes that slot.
720  //   Q: session_semaphores = [{name=bar, max_other_session_count=0}]
721  //   A: Denied because S1 takes the the slot specified by both S1 and
722  //      this config.
723  //
724  // Introduced in 24Q3 (Android V).
725  message SessionSemaphore {
726    // The name of the semaphore. Acts as a unique identifier across all
727    // tracing sessions (including the one being started).
728    optional string name = 1;
729
730    // The maximum number of *other* sesssions which specify the same semaphore
731    // which can be active. The minimum of this value across all tracing
732    // sessions and the value specified by the config is used when deciding
733    // whether the tracing session can be started.
734    optional uint64 max_other_session_count = 2;
735  }
736  repeated SessionSemaphore session_semaphores = 39;
737}
738