Present fu is not sold, reading where a few autumn.

What is Perfetto?

Perfetto is a new platform-level tracing tool introduced in Android 10. This is a more general and complex open source tracking project for Android, Linux, and Chrome. Unlike Systrace, it provides a superset of data sources that allows you to record trace records of any length in a protobuf-encoded binary stream. You can open these trace records in the Perfetto interface.

Perfetto and Systrace, right?

  • Open the Perfetto file and Systrace file in the Perfetto interface. Open the Systrace file using the older Systrace viewer in the Perfetto interface (use the Open with Legacy UI link).
  • usetraceconvThe tool converts Perfetto trace records to the old Systrace text format.
  • Systrace and Perfetto do not collect detailed information about code execution in the application process. To learn more about what methods your application is executing and how much CPU it is using, use CPU Profiler.

What sources does Perfetto collect performance data from?

  • Collect kernel information using ftrace
  • Collect user-space annotations in services and applications using Atrace
  • Use Heapprofd to collect local memory usage information for services and applications

Field experience

(1) Configuration options – Data source selection

Perfetto contains the following two modes to determine the data source used to record trace data:

  • Lightweight mode: Select only a subset of data sources, specifically Atrace and FTrace. But this model can provide something similar tosystraceThe interface.
  • Normal mode: gets its configuration from the protocol buffer and lets you use data sources other than Atrace and ftrace to get the most out of itperfettoThe function.

(2) Lightweight mode

General syntax for using perfetto in lightweight mode is as follows:

// Lightweight mode syntax: Adb shell perfetto [- time record time > <] [- buffer size > < buffer space] [- size < file size limit >] [< atrace category > | < ftrace events > | < records of all events in group > ]... // If you are small white, don't pay attention to those tedious parameters, see a simple operation chestnut: // (1) --out /data/misc/perfetto-traces/trace --out /data/misc/perfetto-traces/trace --out /data/misc/perfetto-traces/trace > adb shell perfetto --time 5s --out /data/misc/perfetto-traces/trace //adb pull /data/misc/perfetto-traces/traceCopy the code

(3) Common mode

The general syntax for using perfetto in normal mode is as follows:

/ Common mode syntax: Adb shell perfetto [-- TXT < PBTXT flag (optional) >] --config CONFIG_FILE < specify the path to the configuration file, Adb shell perfetto --config :test --out /data/misc/perfetto-traces/traceCopy the code

(4) PerfettoUI trace file

How is the painting style fresh, functional diversity, excited, pro test easy to use, highly recommended.

(5) Look up the dictionary

In the process of operation, there will certainly be errors, this time, do not worry, open Xinhua dictionary (ADB shell perfetto -h), and then compare the error message, you can solve most of the problem.

E:\>adb shell perfetto -h
perfetto_cmd.cc:205
Usage: perfetto
  --background     -d      : Exits immediately and continues tracing in
                             background
  --config         -c      : /path/to/trace/config/file or - for stdin
  --out            -o      : /path/to/out/trace/file or - for stdout
  --dropbox           TAG  : Upload trace into DropBox using tag TAG
  --no-guardrails          : Ignore guardrails triggered when using --dropbox
                             (for testing).
  --txt                    : Parse config as pbtxt. Not for production use.
                             Not a stable API.
  --reset-guardrails       : Resets the state of the guardails and exits
                             (for testing).
  --query                  : Queries the service state and prints it as
                             human-readable text.
  --query-raw              : Like --query, but prints raw proto-encoded bytes
                             of tracing_service_state.proto.
  --help           -h


light configuration flags: (only when NOT using -c/--config)
  --time           -t      : Trace duration N[s,m,h] (default: 10s)
  --buffer         -b      : Ring buffer size N[mb,gb] (default: 32mb)
  --size           -s      : Max file size N[mb,gb] (default: in-memory ring-buffer only)
  ATRACE_CAT               : Record ATRACE_CAT (e.g. wm)
  FTRACE_GROUP/FTRACE_NAME : Record ftrace event (e.g. sched/sched_switch)
  FTRACE_GROUP'/*'          : Record all events in group (e.g. sched'/*')


statsd-specific flags:
  --alert-id           : ID of the alert that triggered this trace.
  --config-id          : ID of the triggering config.
  --config-uid         : UID of app which registered the config.
  --subscription-id    : ID of the subscription that triggered this trace.

Detach mode. DISCOURAGED, read https://docs.perfetto.dev/#/detached-mode :
  --detach=key          : Detach from the tracing session with the given key.
  --attach=key [--stop] : Re-attach to the session (optionally stop tracing once reattached).
  --is_detached=key     : Check if the session can be re-attached (0:Yes, 2:No, 1:Error).

E:\>
Copy the code

Now start practicing…

Xiaobian extension links

  • SamplePop code download
  • Android Performance Optimization family Bucket

Refer to the link

  • The first article you should read
  • New tools and new experiences for Perfetto

In the distance, beneath the blue sky, the waves of golden wheat were surging

❤ ❤ than heart