Scripts reference

Record a profile is used to record profiling data for Android applications and native executables.

# Record an Android application.
$ ./ -p simpleperf.example.cpp

# Record an Android application with Java code compiled into native instructions.
$ ./ -p simpleperf.example.cpp --compile_java_code

# Record the launch of an Activity of an Android application.
$ ./ -p simpleperf.example.cpp -a .SleepActivity

# Record a native process.
$ ./ -np surfaceflinger

# Record a native process given its pid.
$ ./ --pid 11324

# Record a command.
$ ./ -cmd \
    "dex2oat --dex-file=/data/local/tmp/app-debug.apk --oat-file=/data/local/tmp/a.oat"

# Record an Android application, and use -r to send custom options to the record command.
$ ./ -p simpleperf.example.cpp \
    -r "-e cpu-clock -g --duration 30"

# Record both on CPU time and off CPU time.
$ ./ -p simpleperf.example.cpp \
    -r "-e task-clock -g -f 1000 --duration 10 --trace-offcpu"

# Save profiling data in a custom file (like instead of
$ ./ -p simpleperf.example.cpp -o

Profile from launch of an application

Sometimes we want to profile the launch-time of an application. To support this, we added --app in the record command. The --app option sets the package name of the Android application to profile. If the app is not already running, the record command will poll for the app process in a loop with an interval of 1ms. So to profile from launch of an application, we can first start the record command with --app, then start the app. Below is an example.

$ ./ record --app simpleperf.example.cpp \
    -g --duration 1 -o /data/local/tmp/
# Start the app manually or using the `am` command.

To make it convenient to use, supports using the -a option to start an Activity after recording has started.

$ ./ -p simpleperf.example.cpp -a .MainActivity is used to control recording in application code. It does preparation work before recording, and collects profiling data files after recording.

Here are the details. records profiling data while the USB cable isn‘t connected. Maybe is more suitable, which also don’t need USB cable when recording. Below is an example.

$ ./ start -p simpleperf.example.cpp
# After the command finishes successfully, unplug the USB cable, run the
# SimpleperfExampleCpp app. After a few seconds, plug in the USB cable.
$ ./ stop
# It may take a while to stop recording. After that, the profiling data is collected in
# on host.

The binary_cache directory is a directory holding binaries needed by a profiling data file. The binaries are expected to be unstripped, having debug information and symbol tables. The binary_cache directory is used by report scripts to read symbols of binaries. It is also used by to generate annotated source code and disassembly.

By default, builds the binary_cache directory after recording. But we can also build binary_cache for existing profiling data files using It is useful when you record profiling data using simpleperf record directly, to do system wide profiling or record without the USB cable connected. can either pull binaries from an Android device, or find binaries in directories on the host (via -lib).

# Generate binary_cache for, by pulling binaries from the device.
$ ./

# Generate binary_cache, by pulling binaries from the device and finding binaries in
# SimpleperfExampleCpp.
$ ./ -lib path_of_SimpleperfExampleCpp

This script pushes the simpleperf executable on the device, and run a simpleperf command on the device. It is more convenient than running adb commands manually.

Viewing the profile

Scripts in this section are for viewing the profile or converting profile data into formats used by external UIs. For recommended UIs, see is a wrapper of the report command on the host. It accepts all options of the report command.

# Report call graph
$ ./ -g

# Report call graph in a GUI window implemented by Python Tk.
$ ./ -g --gui generates report.html based on the profiling data. Then the report.html can show the profiling result without depending on other files. So it can be shown in local browsers or passed to other machines. Depending on which command-line options are used, the content of the report.html can include: chart statistics, sample table, flamegraphs, annotated source code for each function, annotated disassembly for each function.

# Generate chart statistics, sample table and flamegraphs, based on
$ ./

# Add source code.
$ ./ --add_source_code --source_dirs path_of_SimpleperfExampleCpp

# Add disassembly.
$ ./ --add_disassembly

# Adding disassembly for all binaries can cost a lot of time. So we can choose to only add
# disassembly for selected binaries.
$ ./ --add_disassembly --binary_filter
# Add disassembly and source code for binaries belonging to an app with package name
# com.example.myapp.
$ ./ --add_source_code --add_disassembly --binary_filter com.example.myapp

# accepts more than one recording data file.
$ ./ -i

Below is an example of generating html profiling results for SimpleperfExampleCpp.

$ ./ -p simpleperf.example.cpp
$ ./ --add_source_code --source_dirs path_of_SimpleperfExampleCpp \

After opening the generated report.html in a browser, there are several tabs:

The first tab is “Chart Statistics”. You can click the pie chart to show the time consumed by each process, thread, library and function.

The second tab is “Sample Table”. It shows the time taken by each function. By clicking one row in the table, we can jump to a new tab called “Function”.

The third tab is “Flamegraph”. It shows the graphs generated by inferno.

The fourth tab is “Function”. It only appears when users click a row in the “Sample Table” tab. It shows information of a function, including:

  1. A flamegraph showing functions called by that function.
  2. A flamegraph showing functions calling that function.
  3. Annotated source code of that function. It only appears when there are source code files for that function.
  4. Annotated disassembly of that function. It only appears when there are binaries containing that function.


inferno is a tool used to generate flamegraph in a html file.

# Generate flamegraph based on
# On Windows, use inferno.bat instead of ./
$ ./ -sc --record_file

# Record a native program and generate flamegraph.
$ ./ -np surfaceflinger


purgatorio is a visualization tool to show samples in time order.

It converts a profiling data file into pprof.proto, a format used by pprof.

# Convert in the current directory to pprof.proto format.
$ ./
# Show report in pdf format.
$ pprof -pdf pprof.profile

# Show report in html format. To show disassembly, add --tools option like:
#  --tools=objdump:<ndk_path>/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin
# To show annotated source or disassembly, select `top` in the view menu, click a function and
# select `source` or `disassemble` in the view menu.
$ pprof -http=:8080 pprof.profile

Converts to Gecko Profile Format, the format read by

Firefox Profiler is a powerful general-purpose profiler UI which runs locally in any browser (not just Firefox), with:

  • Per-thread tracks
  • Flamegraphs
  • Search, focus for specific stacks
  • A time series view for seeing your samples in timestamp order
  • Filtering by thread and duration


# Record a profile of your application
$ ./ -p simpleperf.example.cpp

# Convert and gzip.
$ ./ -i | gzip > gecko-profile.json.gz

Then open gecko-profile.json.gz in converts a profiling data file into the perf script text format output by linux-perf-tool.

This format can be imported into:

# Record a profile to
$ ./ <args>

# Convert in the current directory to a format used by FlameGraph.
$ ./ --symfs binary_cache >out.perf

$ git clone
$ FlameGraph/ out.perf >out.folded
$ FlameGraph/ out.folded >a.svg converts a profiling data file ( to Brendan Gregg's “Folded Stacks” format.

Folded Stacks are lines of semicolon-delimited stack frames, root to leaf, followed by a count of events sampled in that stack, e.g.:

BusyThread;__start_thread;__pthread_start(void*); 17889729

All similar stacks are aggregated and sample timestamps are unused.

Folded Stacks format is readable by:


# Record a profile to
$ ./ <args>

# Convert to Folded Stacks format
$ ./ --kernel --jit | gzip > profile.folded.gz

# Visualise with FlameGraph with Java Stacks and nanosecond times
$ git clone
$ gunzip -c profile.folded.gz \
    | FlameGraph/ --color=java --countname=ns \
    > profile.svg is a Python library used to parse profiling data files generated by the record command. Internally, it uses to do the work. Generally, for each profiling data file, we create an instance of ReportLib, pass it the file path (via SetRecordFile). Then we can read all samples through GetNextSample(). For each sample, we can read its event info (via GetEventOfCurrentSample), symbol info (via GetSymbolOfCurrentSample) and call chain info (via GetCallChainOfCurrentSample). We can also get some global information, like record options (via GetRecordCmd), the arch of the device (via GetArch) and meta strings (via MetaInfo).

Examples of using are in,, and inferno/

ipc.pycaptures the instructions per cycle (IPC) of the system during a specified duration.


./ 2 20          # Set interval to 2 secs and total duration to 20 secs
./ -p 284 -C 4   # Only profile the PID 284 while running on core 4
./ -c 'sleep 5'  # Only profile the command to run

The results look like:

36840      14138       0.38
70701      27743       0.39
104562     41350       0.40
138264     54916       0.40 generates sample filter files as documented in A filter file can be passed in --filter-file when running report scripts.

For example, it can be used to split a large recording file into several report files.

$ -i --split-time-range 2 -o sample_filter
$ -i --filter-file sample_filter_part1 \
    | gzip >profile-part1.json.gz
$ -i --filter-file sample_filter_part2 \
    | gzip >profile-part2.json.gz