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 conjuction 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 // Additional guardrail used by the Perfetto command line client. 442 // On user builds when --dropbox is set perfetto will refuse to trace unless 443 // this is also set. 444 // Added in Q. 445 optional bool allow_user_build_tracing = 19; 446 447 // If set the tracing service will ensure there is at most one tracing session 448 // with this key. 449 optional string unique_session_name = 22; 450 451 // Compress trace with the given method. Best effort. 452 enum CompressionType { 453 COMPRESSION_TYPE_UNSPECIFIED = 0; 454 COMPRESSION_TYPE_DEFLATE = 1; 455 } 456 optional CompressionType compression_type = 24; 457 458 // DEPRECATED, was compress_from_cli. 459 reserved 37; 460 461 // Android-only. Not for general use. If set, saves the trace into an 462 // incident. This field is read by perfetto_cmd, rather than the tracing 463 // service. This field must be set when passing the --upload flag to 464 // perfetto_cmd. 465 message IncidentReportConfig { 466 // In this message, either: 467 // * all of |destination_package|, |destination_class| and |privacy_level| 468 // must be set. 469 // * |skip_incidentd| must be explicitly set to true. 470 471 optional string destination_package = 1; 472 optional string destination_class = 2; 473 // Level of filtering in the requested incident. See |Destination| in 474 // frameworks/base/core/proto/android/privacy.proto. 475 optional int32 privacy_level = 3; 476 477 // If true, then skips saving the trace to incidentd. 478 // 479 // This flag is useful in testing (e.g. Perfetto-statsd integration tests) 480 // or when we explicitly don't want traces to go to incidentd even when they 481 // usually would (e.g. configs deployed using statsd but only used for 482 // inclusion in bugreports using |bugreport_score|). 483 // 484 // The motivation for having this flag, instead of just not setting 485 // |incident_report_config|, is prevent accidents where 486 // |incident_report_config| is omitted by mistake. 487 optional bool skip_incidentd = 5; 488 489 // If true, do not write the trace into dropbox (i.e. incident only). 490 // Otherwise, write to both dropbox and incident. 491 // TODO(lalitm): remove this field as we no longer use Dropbox. 492 optional bool skip_dropbox = 4 [deprecated = true]; 493 } 494 optional IncidentReportConfig incident_report_config = 25; 495 496 enum StatsdLogging { 497 STATSD_LOGGING_UNSPECIFIED = 0; 498 STATSD_LOGGING_ENABLED = 1; 499 STATSD_LOGGING_DISABLED = 2; 500 } 501 502 // Android-only. Not for general use. If specified, sets the logging to statsd 503 // of guardrails and checkpoints in the tracing service. perfetto_cmd sets 504 // this to enabled (if not explicitly set in the config) when specifying 505 // --upload. 506 optional StatsdLogging statsd_logging = 31; 507 508 // DEPRECATED. Was trace_uuid, use trace_uuid_msb and trace_uuid_lsb instead. 509 reserved 26; 510 511 // An identifier clients can use to tie this trace to other logging. 512 // DEPRECATED as per v32. See TracePacket.trace_uuid for the authoritative 513 // Trace UUID. If this field is set, the tracing service will respect the 514 // requested UUID (i.e. TracePacket.trace_uuid == this field) but only if 515 // gap-less snapshotting is not used. 516 optional int64 trace_uuid_msb = 27 [deprecated = true]; 517 optional int64 trace_uuid_lsb = 28 [deprecated = true]; 518 519 // When set applies a post-filter to the trace contents using the filter 520 // provided. The filter is applied at ReadBuffers() time and works both in the 521 // case of IPC readback and write_into_file. This filter can be generated 522 // using `tools/proto_filter -s schema.proto -F filter_out.bytes` or 523 // `-T filter_out.escaped_string` (for .pbtx). See go/trace-filtering for 524 // design. 525 // 526 // Introduced in Android S, but it was broken (b/195065199). Reintroduced in 527 // Android T with a different field number. Updated in Android U with a new 528 // bytecode version which supports string filtering. 529 message TraceFilter { 530 // ========================= 531 // Filter bytecode. 532 // ========================= 533 534 // The bytecode as implemented in Android T. 535 optional bytes bytecode = 1; 536 537 // The bytecode as implemented in Android U. Adds support for string 538 // filtering. 539 optional bytes bytecode_v2 = 2; 540 541 // ========================= 542 // String filtering 543 // ========================= 544 545 // The principles and terminology of string filtering is heavily inspired by 546 // iptables. A "rule" decide how strings should be filtered. Each rule 547 // contains a "policy" which indicates the algorithm to use for filtering. 548 // A "chain" is a list of rules which will be sequentially checked against 549 // each string. 550 // 551 // The first rule which applies to the string terminates filtering for that 552 // string. If no rules apply, the string is left unchanged. 553 554 // A policy specifies which algorithm should be used for filtering the 555 // string. 556 enum StringFilterPolicy { 557 SFP_UNSPECIFIED = 0; 558 559 // Tries to match the string field against |regex_pattern|. If it 560 // matches, all matching groups are "redacted" (i.e. replaced with a 561 // constant string) and filtering is terminated (i.e. no further rules are 562 // checked). If it doesn't match, the string is left unchanged and the 563 // next rule in chain is considered. 564 SFP_MATCH_REDACT_GROUPS = 1; 565 566 // Like |SFP_MATCH_REDACT_GROUPS| but tries to do some pre-work before 567 // checking the regex. Specifically, it tries to parse the string field as 568 // an atrace tracepoint and checks if the post-tgid field starts with 569 // |atrace_post_tgid_starts_with|. The regex matching is only performed if 570 // this check succeeds. 571 SFP_ATRACE_MATCH_REDACT_GROUPS = 2; 572 573 // Tries to match the string field against |regex_pattern|. If it 574 // matches, filtering is terminated (i.e. no further rules are checked). 575 // If it doesn't match, the string is left unchanged and the next rule in 576 // chain is considered. 577 SFP_MATCH_BREAK = 3; 578 579 // Like |SFP_MATCH_BREAK| but tries to do some pre-work before checking 580 // the regex. Specifically, it tries to parse the string field as an 581 // atrace tracepoint and checks if the post-tgid field starts with 582 // |atrace_post_tgid_starts_with|. The regex matching is only performed if 583 // this check succeeds. 584 SFP_ATRACE_MATCH_BREAK = 4; 585 586 // Tries to repeatedly search (i.e. find substrings of) the string field 587 // with |regex_pattern|. For each match, redacts any matching groups (i.e. 588 // replaced with a constant string). Once there are no further matches, 589 // filtering is terminated (i.e. no further rules are checked). 590 // 591 // Note that this is policy is a "search" policy not a "match" policy 592 // unlike the above policies: 593 // * Match policies require matching the full string i.e. there is an 594 // implicit leading `^` and trailing `$`. 595 // * Search policies perform repeated partial matching of the string 596 // e.g. 597 // - String: `foo=aaa,bar=123,foo=bbb,baz=456` 598 // - Pattern: `foo=(\d+)` 599 // - Output: `foo=P6O,bar=123,foo=P6O,baz=456` 600 // where P6O is the redaction string 601 // 602 // All of this is only performed after some pre-work where we try to parse 603 // the string field as an atrace tracepoint and check if the post-tgid 604 // field starts with |atrace_post_tgid_starts_with|. 605 // 606 // If there are no partial matches, the string is left unchanged and the 607 // next rule in chain is considered. 608 SFP_ATRACE_REPEATED_SEARCH_REDACT_GROUPS = 5; 609 } 610 611 // A rule specifies how strings should be filtered. 612 message StringFilterRule { 613 // The policy (i.e. algorithm) dictating how strings matching this rule 614 // should be handled. 615 optional StringFilterPolicy policy = 1; 616 617 // The regex pattern used to match against each string. 618 optional string regex_pattern = 2; 619 620 // The string which should appear after the tgid in atrace tracepoint 621 // strings. 622 optional string atrace_payload_starts_with = 3; 623 } 624 625 // A chain is a list of rules which string will be sequentially checked 626 // against. 627 message StringFilterChain { 628 repeated StringFilterRule rules = 1; 629 } 630 optional StringFilterChain string_filter_chain = 3; 631 } 632 // old field number for trace_filter 633 reserved 32; 634 optional TraceFilter trace_filter = 33; 635 636 // Android-only. Not for general use. If set, reports the trace to the 637 // Android framework. This field is read by perfetto_cmd, rather than the 638 // tracing service. This field must be set when passing the --upload flag to 639 // perfetto_cmd. 640 message AndroidReportConfig { 641 // In this message, either: 642 // * |reporter_service_package| and |reporter_service_class| must be set. 643 // * |skip_reporting| must be explicitly set to true. 644 645 optional string reporter_service_package = 1; 646 optional string reporter_service_class = 2; 647 648 // If true, then skips reporting the trace to Android framework. 649 // 650 // This flag is useful in testing (e.g. Perfetto-statsd integration tests) 651 // or when we explicitly don't want to report traces to the framework even 652 // when they usually would (e.g. configs deployed using statsd but only 653 // used for inclusion in bugreports using |bugreport_score|). 654 // 655 // The motivation for having this flag, instead of just not setting 656 // |framework_report_config|, is prevent accidents where 657 // |framework_report_config| is omitted by mistake. 658 optional bool skip_report = 3; 659 660 // If true, will direct the Android framework to read the data in trace 661 // file and pass it to the reporter class over a pipe instead of passing 662 // the file descriptor directly. 663 // 664 // This flag is needed because the Android test framework does not 665 // currently support priv-app helper apps (in terms of SELinux) and we 666 // really don't want to add an allow rule for untrusted_app to receive 667 // trace fds. 668 // 669 // Because of this, we instead will direct the framework to create a new 670 // pipe and pass this to the reporter process instead. As the pipe is 671 // created by the framework, we won't have any problems with SELinux 672 // (system_server is already allowed to pass pipe fds, even 673 // to untrusted apps). 674 // 675 // As the name suggests this option *MUST* only be used for testing. 676 // Note that the framework will reject (and drop) files which are too 677 // large both for simplicity and to be minimize the amount of data we 678 // pass to a non-priv app (note that the framework will still check 679 // manifest permissions even though SELinux permissions are worked around). 680 optional bool use_pipe_in_framework_for_testing = 4; 681 } 682 optional AndroidReportConfig android_report_config = 34; 683 684 // If set, delays the start of tracing by a random duration. The duration is 685 // chosen from a uniform distribution between the specified minimum and 686 // maximum. 687 // Note: this delay is implemented by perfetto_cmd *not* by traced so will 688 // not work if you communicate with traced directly over the consumer API. 689 // Introduced in Android T. 690 message CmdTraceStartDelay { 691 optional uint32 min_delay_ms = 1; 692 optional uint32 max_delay_ms = 2; 693 } 694 optional CmdTraceStartDelay cmd_trace_start_delay = 35; 695 696 // When non-empty, ensures that for a each semaphore named `name at most 697 // `max_other_session_count`` *other* sessions (whose value is taken of the 698 // minimum of all values specified by this config or any already-running 699 // session) can be be running. 700 // 701 // If a semaphore "acquisition" fails, EnableTracing will return an error 702 // and the tracing session will not be started (or elgible to start in 703 // the case of deferred sessions). 704 // 705 // This is easiest to explain with an example. Suppose the tracing service has 706 // the following active tracing sessions: 707 // S1 = [{name=foo, max_other_session_count=2}, 708 // {name=bar, max_other_session_count=0}] 709 // S2 = [{name=foo, max_other_session_count=1}, 710 // {name=baz, max_other_session_count=1}] 711 // 712 // Then, for a new session, the following would be the expected behaviour of 713 // EnableSession given the state of `session_semaphores`. 714 // Q: session_semaphores = [] 715 // A: Allowed because it does not specify any semaphores. Will be allowed 716 // no matter the state of any other tracing session. 717 // Q: session_semaphores = [{name=baz, max_other_session_count=1}] 718 // A: Allowed because both S2 and this config specify 719 // max_other_session_count=1 for baz. 720 // Q: session_semaphores = [{name=foo, max_other_session_count=3}] 721 // A: Denied because S2 specified max_other_session_count=1 for foo and S1 722 // takes that slot. 723 // Q: session_semaphores = [{name=bar, max_other_session_count=0}] 724 // A: Denied because S1 takes the the slot specified by both S1 and 725 // this config. 726 // 727 // Introduced in 24Q3 (Android V). 728 message SessionSemaphore { 729 // The name of the semaphore. Acts as a unique identifier across all 730 // tracing sessions (including the one being started). 731 optional string name = 1; 732 733 // The maximum number of *other* sesssions which specify the same semaphore 734 // which can be active. The minimum of this value across all tracing 735 // sessions and the value specified by the config is used when deciding 736 // whether the tracing session can be started. 737 optional uint64 max_other_session_count = 2; 738 } 739 repeated SessionSemaphore session_semaphores = 39; 740} 741