The tools/tracing directory contains scripts for both recording and symbolizing traces in proto file format. This doc outlines different use cases for the tool. Each use case shows what arguments are most important for the script to work. Run tools/tracing/profile_chrome_startup --help
or tools/tracing/symbolize_trace --help
for more details on more command-line flags.
Platform | Trace Recording | Trace Symbolization |
---|---|---|
Android | ✔️ | ✔️ |
Linux | ❌ (use https://ui.perfetto.dev) | ✔️ |
MacOS | ❌ (use https://ui.perfetto.dev) | ✔️ |
Windows | ❌ | ❌ |
For local builds: In order for this tool to work, make sure that a build directory for Chrome exists and that Chrome is built with the gn arg ‘symbol_level’ >= 1.
Supported architectures for heap profiling:
Local builds: arm32, arm64, x86-64
Set ‘symbol_level’ to 1 or 2 in gn args. Symbols are used to add function names to CPU and heap profiles. Level 1 only includes public functions. Level 2 includes all function names but takes longer to build.
Emulator: Use x86-64 architecture. x86 architecture is not supported.
Arm64: If you are building for arm64 and using the primary apk (chrome.apk or monochrome.apk), then profiling works with all the builds.
Arm64-secondary: If you are using builds from secondary arch folder (clang_arm32), then make sure the arm32 gn args defined below are included.
Prefer to use arm64/x86-64 primary since arm32 support is less stable.
For arm32, set these gn args:
enable_profiling=true
, arm_use_thumb=false
, is_component_build=false
and symbol_level=1
.is_official_build=true
, symbol_level=1
.Official builds: arm32, arm64, x86-64.
Note: x86 architecture is not supported for this.
Supported architectures for CPU profiling:
CPU profiling not supported on emulators.
Official builds: arm32 and arm64.
Local builds: arm32 and arm64
symbol_level=1
so that function names are included in symbol files. For arm32, include the following gn args: is_official_build=true
, symbol_level=1
.Setup steps:
Build Chrome using x86-64 (with gn arg: target_os="x64"
for local builds) or other supported architectures.
Skip this step if heap profiling is not needed. Setup Chrome command line for enabling heap profiling before starting Chrome:
build/android/adb_chrome_public_command_line \ --memlog-sampling-rate=1000000 --memlog=browser \ --use-heap-profiling-proto-writer
Make sure that the Chrome browser installed has permission to access device storage. Chrome needs permission to write traces to disk (outside data dir).
Build dump_syms by running: ninja -C out/build_dir dump_syms. This is needed for official builds too. You need to setup a local directory with the same target_os
as the profiled device and set is_debug=false
in gn args.
Heap profiling:
CPU profiling:
Note: Download and symbolize this profile using symbolization steps below.
Find the browser you want to profile. The --browser
flag will be used to select the browser.
--browser=build
(for clankium), --browser=chromium
(for chromium), --browser=beta
, --browser=stable
. --help
will give a list of all possible browser options.Run profile_chrome_startup:
tools/tracing/profile_chrome_startup \ --local_build_dir=LOCAL_BUILD_DIR --browser=BROWSER \ [--enable_profiler={memory,cpu}]
Example heap profiling:
tools/tracing/profile_chrome_startup \ --local_build_dir=out/Release --browser=build --enable_profiler=memory
--time
flag greater than 10 seconds to actually collect heap samples. For example, specifying --time=300
will ensure heap samples are taken every 10 seconds for five minutes.Find the browser you want to profile. The --browser
flag will be used to select the browser.
--browser=beta
, --browser=canary
, --browser=stable
. --help
will give a list of all possible browser options.Run profile_chrome_startup:
tools/tracing/profile_chrome_startup \ --dump_syms=DUMP_SYMS --browser=BROWSER [--enable_profiler={memory,cpu}]
Example heap profiling:
tools/tracing/profile_chrome_startup \ --dump_syms=out/Release/dump_syms \ local_build_dir=out/Release --browser=stable --enable_profiler=memory
--time
flag greater than 10 seconds to actually collect heap samples. For example, specifying --time=300
will ensure heap samples are taken every 10 seconds for five minutes.Notes:
To specify the kind of profile to collect, the --enable_profiler
flag is needed. You can specify either cpu
or memory
or a comma-separated list containing both as arguments.
To enable/disable specific Chrome categories while recording a trace, use the --chrome_categories flag
.
To view a symbolized trace automatically after symbolization, you can pass the --view
flag to automatically open the symbolized trace in https://ui.perfetto.dev.
For steps to save time on multiple runs, refer to Caching Symbols for Multiple Traces section for additional flags to add to the command line.
In case dump_syms is not found by the script, specify the --dump_syms
flag.
It is not needed, but if you want to specify the directory to hold breakpad files, use the --breakpad_output_dir
flag.
If symbolization is not needed, the --skip_symbolize
flag specifies that a trace should skip symbolization after collection. If specified omit the --dump_syms
and --local_build_dir
flags since symbolization is not needed.
Heap profiling:
CPU profiling:
Note: Download and symbolize this profile using symbolization steps below.
You can collect a trace using https://ui.perfetto.dev, but symbolizing on Windows is not currently supported with this script.
tools/tracing/symbolize_trace [trace_file] --local_build_dir=LOCAL_BUILD_DIR
tools/tracing/symbolize_trace [trace_file]
--dump_syms=DUMP_SYMS
for Android. Mac and Linux official builds do not require dump_syms, but for Android traces, a path to dump_syms should be found.Notes
To view a symbolized trace automiatically after symbolization, you can pass the --view
flag to automatically open the symbolized trace in https://ui.perfetto.dev.
For steps to save time on multiple runs, refer to Caching Symbols for Multiple Traces section for additional flags to add to the command line.
To cache symbols for symbolizing different traces from the same build of Chrome include the --breakpad_output_dir flag (this will work for both profile_chrome_startup
and symbolize_trace
scripts). If --breakpad_output_dir
is specified in the first run, the flag can be replaced with --local_breakpad_dir
to save time in subsequent runs, by using the breakpad symbols that have been stored. Ex:
For tools/tracing/profile_chrome_startup
:
1st run: tools/tracing/profile_chrome_startup --breakpad_output_dir=/tmp
Future runs: tools/tracing/profile_chrome_startup --local_breakpad_dir=/tmp
For tools/tracing/symbolize_trace
:
1st run: tools/tracing/symbolize_trace [trace_file1] --breakpad_output_dir=/tmp
Future runs: tools/tracing/symbolize_trace [trace_file2] --local_breakpad_dir=/tmp
If tools/tracing/profile_chrome_startup
gives Error : Activity Class
or the desired Chrome browser does not open:
--browser
flag matches the build of the browser you want to profile.If heap profiling gives and empty trace:
--enable_profiler
flag.--time
flag is set to a value greater than 10.If symbolization fails because dump_syms cannot be found:
--dump_syms
or that the binary can be found in the directory given for --local_build_dir
If an error shows that no symbolizer is found:
--symbolizer
flag, or you can use the trace_to_text tool directly by running: path/to/trace_to_text [trace_file]
See the google internal design doc for more details pertaining to this tool: https://docs.google.com/document/d/1BJPbcl5SPjOvuRuP1JSFAUPK3ZWNIS7j1h94rPHRzVE