tree: b22b4e5be7253b536f89fbb3c9603468eb4f5623
  1. bin/
  2. inferno/
  3. purgatorio/
  4. test/
  5. .gitignore
  6. __init__.py
  7. Android.bp
  8. annotate.py
  9. api_profiler.py
  10. app_profiler.py
  11. binary_cache_builder.py
  12. CONTRIBUTING.md
  13. debug_unwind_reporter.py
  14. etm_types.py
  15. gecko_profile_generator.py
  16. inferno.bat
  17. inferno.sh
  18. ipc.py
  19. pprof_proto_generator.py
  20. profile_pb2.py
  21. pylintrc
  22. README.md
  23. report.py
  24. report_etm.py
  25. report_fuchsia.py
  26. report_html.js
  27. report_html.py
  28. report_sample.py
  29. report_sample_pb2.py
  30. run_simpleperf_on_device.py
  31. run_simpleperf_without_usb_connection.py
  32. sample_filter.py
  33. sample_filter_for_perfetto_trace.py
  34. simpleperf_report_lib.py
  35. simpleperf_utils.py
  36. stackcollapse.py
  37. update.py
simpleperf/scripts/README.md

Simpleperf Python Scripts

This directory contains Python scripts for processing simpleperf data, generating reports, and converting profiles to formats like pprof.

Setup

The scripts depend on the Python protobuf library, and assume it's been installed.

pip install protobuf

Alternatively, you can use a virtual environment and include the necessary paths from the Android source tree.

# Create a virtual environment
python3 -m venv venv
source venv/bin/activate

# Add protobuf and simpleperf scripts to PYTHONPATH
export PYTHONPATH=$PYTHONPATH:$(pwd)/external/protobuf/python
export PYTHONPATH=$PYTHONPATH:$(pwd)/system/extras/simpleperf/scripts

Capturing Kernel Symbols

To ensure kernel symbols are captured in your profiles, you must disable certain security restrictions on the device before running simpleperf:

adb root
adb shell setprop security.perf_harden 0
adb shell "echo 0 > /proc/sys/kernel/kptr_restrict"

Generating Symbolized pprof Profiles

To generate a pprof profile with symbols from your local build, use the pprof tool and provide the path to unstripped binaries via PPROF_BINARY_PATH.

# Example: Generate a flamegraph URL from perf.data
PPROF_BINARY_PATH=out/target/product/<device>/symbols/system/lib64:out/target/product/<device>/symbols/apex/com.android.runtime/lib64/bionic \
pprof -flame perf.data

Note: Ensure that the perf.data was collected from a build that matches the symbols in your out/ directory (matching Build IDs).

Automated Symbol Collection

You can use binary_cache_builder.py to automatically pull relevant binaries and kallsyms from the device into a local binary_cache directory for easier reporting.

python3 binary_cache_builder.py -lib out/target/product/<device>/symbols -i perf.data