| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 |
Chrome Tracing Tools - Guide
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.
[TOC]
What's supported?
| Platform | Trace Recording | Trace Symbolization |
|---|---|---|
| Android | ✔️ | ✔️ |
| Linux | ❌ (use https://ui.perfetto.dev) | ✔️ |
| MacOS | ❌ (use https://ui.perfetto.dev) | ✔️ |
| Windows | ❌ | ❌ |
Profiling Chrome
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.
Android:
Setting up to collect profiles:
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 ChromePublic.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:
- Unofficial:
enable_profiling=true,arm_use_thumb=false,is_component_build=falseandsymbol_level=1. - Official: for arm32 you can use
is_official_build=true,symbol_level=1.
- Unofficial:
-
-
Official builds: arm32, arm64, x86-64.
- Official builds need to be installed from the play store.
- For arm32, only canary and dev channels are supported.
Note: x86 architecture is not supported for this.
Supported architectures for CPU profiling:
-
CPU profiling not supported on emulators.
-
Official builds: arm32 and arm64.
- Official builds need to be downloaded from the play store.
- For arm32, only canary and dev channels are supported.
-
Local builds: arm32 and arm64
- Include gn arg:
symbol_level=1so that function names are included in symbol files. For arm32, include the following gn args:is_official_build=true,symbol_level=1.
- Include gn arg:
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:
- Run:
build/android/adb_chrome_public_command_line \ --memlog-sampling-rate=1000000 --memlog=browser \ --use-heap-profiling-proto-writer- Alternatively you can enable heap profiling from chrome://memory-internals.
- For CPU sampling profiling, no Chrome command line setup is needed.
-
Make sure that the Chrome browser installed has permission to access device storage. Chrome needs permission to write traces to disk (outside data dir).
- On your device/emulator with Chrome: Setting > Apps > App Info, then click the Chrome app you want to profile. Click on App Permissions and allow access to device storage.
-
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_osas the profiled device and setis_debug=falsein gn args.
Collecting profiles:
Using Perfetto UI (https://ui.perfetto.dev):
Heap profiling:
- Enable memory-infra (high-overhead) for memory in Chrome categories and collect traces. this would capture a profile every 10 seconds.
CPU profiling:
- For CPU profiling, enable cpu_profiler (high overhead) in Chrome categories and collect traces.
Note: Download and symbolize this profile using symbolization steps below.
For local builds:
-
Find the browser you want to profile. The
--browserflag will be used to select the browser.- Examples for local builds:
--browser=build(for clankium),--browser=chromium(for chromium),--browser=beta,--browser=stable.--helpwill give a list of all possible browser options.
- Examples for local builds:
-
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- When collecting heap profiles, samples are collected every 10 seconds.
Extend the time for heap profiling by setting the
--timeflag greater than 10 seconds to actually collect heap samples. For example, specifying--time=300will ensure heap samples are taken every 10 seconds for five minutes.
- When collecting heap profiles, samples are collected every 10 seconds.
Extend the time for heap profiling by setting the
For official builds:
-
Find the browser you want to profile. The
--browserflag will be used to select the browser.- Examples for official builds:
--browser=beta,--browser=canary,--browser=stable.--helpwill give a list of all possible browser options.
- Examples for official builds:
-
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- When collecting heap profiles, samples are collected every 10 seconds.
Extend the time for heap profiling by setting the
--timeflag greater than 10 seconds to actually collect heap samples. For example, specifying--time=300will ensure heap samples are taken every 10 seconds for five minutes.
- When collecting heap profiles, samples are collected every 10 seconds.
Extend the time for heap profiling by setting the
Notes:
-
To specify the kind of profile to collect, the
--enable_profilerflag is needed. You can specify eithercpuormemoryor 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
--viewflag 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_symsflag. -
It is not needed, but if you want to specify the directory to hold breakpad files, use the
--breakpad_output_dirflag. -
If symbolization is not needed, the
--skip_symbolizeflag specifies that a trace should skip symbolization after collection. If specified omit the--dump_symsand--local_build_dirflags since symbolization is not needed.
For Mac and Linux:
Collecting profiles:
Using Perfetto UI (https://ui.perfetto.dev):
Heap profiling:
- Enable memory-infra (high-overhead) for memory in Chrome categories and collect traces. this would capture a profile every 10 seconds.
CPU profiling:
- For CPU profiling, enable cpu_profiler (high overhead) in Chrome categories and collect traces.
Note: Download and symbolize this profile using symbolization steps below.
For Windows:
You can collect a trace using https://ui.perfetto.dev, but symbolizing on Windows is not currently supported with this script.
Symbolizing traces (Only works for proto traces)
Android, Linux, Mac:
For local builds:
Symbolization setup:
- Build dump_syms by running: ninja -C out/build_dir dump_syms.
- Find the trace you want to symbolize.
Symbolizing:
- Run symbolize_trace:
tools/tracing/symbolize_trace [trace_file] --local_build_dir=LOCAL_BUILD_DIR
For official builds:
- Skip this step for Mac and Linux. Build dump_syms by running: ninja -C out/build_dir dump_syms.
- Run symbolize_trace:
tools/tracing/symbolize_trace [trace_file]
- Include
--dump_syms=DUMP_SYMSfor 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
--viewflag 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.
Windows and Chrome OS: Not yet supported.
Caching Symbols for Multiple Traces:
-
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_startupandsymbolize_tracescripts). If--breakpad_output_diris specified in the first run, the flag can be replaced with--local_breakpad_dirto 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
-
Troubleshooting:
-
If
tools/tracing/profile_chrome_startupgivesError : Activity Classor the desired Chrome browser does not open:- Check that the browser given for the
--browserflag matches the build of the browser you want to profile.
- Check that the browser given for the
-
If heap profiling gives and empty trace:
- Make sure 'memory' is included as an argument for the
--enable_profilerflag. - Make sure that the
--timeflag is set to a value greater than 10. - Make sure Chrome is able to read the command line (give storage permission, as outlined in steps to profile Chrome) and that Chrome is restarted after setting the command line for memlog.
- Make sure 'memory' is included as an argument for the
-
If symbolization fails because dump_syms cannot be found:
- Make sure that the dump_syms binary you built is given for the
--dump_symsor that the binary can be found in the directory given for--local_build_dir
- Make sure that the dump_syms binary you built is given for the
-
If an error shows that no symbolizer is found:
- Try building the trace_to_text tool in perfetto, using instructions
found here: https://perfetto.dev/docs/contributing/build-instructions.
You can try the script again, specifying the
--symbolizerflag, or you can use the trace_to_text tool directly by running:path/to/trace_to_text [trace_file]
- Try building the trace_to_text tool in perfetto, using instructions
found here: https://perfetto.dev/docs/contributing/build-instructions.
You can try the script again, specifying the
See the google internal design doc for more details pertaining to this tool: https://docs.google.com/document/d/1BJPbcl5SPjOvuRuP1JSFAUPK3ZWNIS7j1h94rPHRzVE