Skip to main content

CLI tool for Perfetto trace analysis - ANR, frame, CPU, memory, binder profiling

Project description

perfetto-cli

A CLI tool for Android Perfetto trace analysis — ANR detection, frame jank, CPU profiling, memory leak detection, binder transactions, and raw SQL queries, all from the terminal.

CI PyPI License: MIT

English | 中文


Installation

pip install perfetto-cli

Or run directly without installation via uvx:

uvx perfetto-cli --help

Quick Start

# Detect ANR events
perfetto-cli -t trace.perfetto-trace -p com.example.app anr detect

# Detect frame jank
perfetto-cli -t trace.perfetto-trace -p com.example.app frame jank

# View CPU utilization
perfetto-cli -t trace.perfetto-trace -p com.example.app cpu utilization

# Capture trace from device (requires adb)
perfetto-cli trace start
perfetto-cli trace stop

Global Options

Option Description
-t, --trace <path> Trace file path (required)
-p, --process <name> Process name filter
-f, --format <type> Output format: json / table / text (default: text)
-v, --verbose Verbose output
--tp-path <path> Custom trace_processor binary path
--version Show version

Commands

ANR Analysis

Detect ANR (Application Not Responding) events and identify root causes.

# Detect ANR events with severity classification
perfetto-cli -t trace.perfetto-trace -p com.example.app anr detect

# Filter by minimum duration
perfetto-cli -t trace.perfetto-trace -p com.example.app anr detect --min-duration 3000

# Multi-signal root cause analysis (requires ANR timestamp)
perfetto-cli -t trace.perfetto-trace -p com.example.app anr root-cause --anr-timestamp 5000

Frame Performance

Analyze frame rendering performance and detect jank.

# Detect janky frames (SMOOTH / JANK / BIG_JANK / HUGE_JANK)
perfetto-cli -t trace.perfetto-trace -p com.example.app frame jank

# Custom jank threshold (default: 16ms)
perfetto-cli -t trace.perfetto-trace -p com.example.app frame jank --threshold 16

# Frame performance summary with rating
perfetto-cli -t trace.perfetto-trace -p com.example.app frame summary

CPU Analysis

Thread-level CPU utilization, hotspot detection, and contention analysis.

# Per-thread CPU utilization
perfetto-cli -t trace.perfetto-trace -p com.example.app cpu utilization

# Include CPU frequency (DVFS) info
perfetto-cli -t trace.perfetto-trace -p com.example.app cpu utilization --include-frequency

# Main thread hotspot slices (top-N)
perfetto-cli -t trace.perfetto-trace -p com.example.app cpu hotspots --limit 30

# Thread contention analysis
perfetto-cli -t trace.perfetto-trace -p com.example.app cpu contention

Memory Analysis

Memory leak detection and heap analysis.

# Detect memory leaks via RSS growth trend
perfetto-cli -t trace.perfetto-trace -p com.example.app memory leak

# Custom growth threshold (default: 5 MB/min)
perfetto-cli -t trace.perfetto-trace -p com.example.app memory leak --growth-threshold 10

# Heap dominator tree analysis
perfetto-cli -t trace.perfetto-trace -p com.example.app memory heap

Binder Analysis

Binder IPC transaction performance profiling.

# Binder transaction analysis
perfetto-cli -t trace.perfetto-trace -p com.example.app binder profile

# Filter by minimum latency (default: 10ms)
perfetto-cli -t trace.perfetto-trace -p com.example.app binder profile --min-latency 20

# Group by AIDL interface
perfetto-cli -t trace.perfetto-trace -p com.example.app binder profile --group-by aidl

SQL Queries

Execute raw PerfettoSQL queries and search trace data.

# Execute SQL query
perfetto-cli -t trace.perfetto-trace query sql --query "SELECT * FROM slice LIMIT 10"

# Execute SQL from file
perfetto-cli -t trace.perfetto-trace query sql --file query.sql

# Search slices (supports contains/exact/glob)
perfetto-cli -t trace.perfetto-trace query find-slices --pattern "Choreographer"

Trace Capture

Capture Perfetto traces from device via adb.

# Start capture with default config (10s)
perfetto-cli trace start

# Custom duration
perfetto-cli trace start --duration 30s

# Custom buffer size (default: 32MB)
perfetto-cli trace start --buffer-size 64mb

# Stop capture and pull trace file
perfetto-cli trace stop

# One-shot capture (start → wait → stop → pull)
perfetto-cli trace run --duration 15s -o ./traces

Output Formats

Use -f, --format to specify output format:

  • text (default): Human-friendly colorized terminal output via Rich
  • table: ASCII table output, suitable for aligned data viewing
  • json: Machine-readable JSON for scripting and piping

Command Reference

Domain Command Description
anr detect ANR event detection with severity
anr root-cause Multi-signal ANR root cause analysis
frame jank Frame jank detection
frame summary Frame performance summary & rating
cpu utilization Thread-level CPU utilization
cpu hotspots Main thread hotspot slices
cpu contention Thread contention analysis
memory leak RSS-based memory leak detection
memory heap Heap dominator tree analysis
binder profile Binder transaction profiling
query sql Execute raw PerfettoSQL
query find-slices Search slices by pattern
query slice-info Get slice details
trace start Start device trace capture
trace stop Stop capture and pull trace
trace run One-shot capture

Development

# Clone the repo
git clone https://github.com/SYKernel/perfetto-cli.git
cd perfetto-cli

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linter
ruff check .

Dependencies

  • Python >= 3.10
  • click >= 8.0 — CLI framework
  • rich >= 13.0 — Rich terminal output
  • perfetto >= 0.14.0 — Trace processing (includes trace_processor)
  • adb — Required only for trace commands, must be in PATH

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perfetto_cli-0.2.0.tar.gz (39.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perfetto_cli-0.2.0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file perfetto_cli-0.2.0.tar.gz.

File metadata

  • Download URL: perfetto_cli-0.2.0.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for perfetto_cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 78e26687488435fdc6f8659354be5e45d6814ecf4eadfc14c073dfa2a59b3b2b
MD5 ecead64c356da6d61038a0f15023b88a
BLAKE2b-256 c679b233f7accdb20fed9e4c06f947900a517c14007594c0da094c263f8c8ef5

See more details on using hashes here.

Provenance

The following attestation bundles were made for perfetto_cli-0.2.0.tar.gz:

Publisher: ci.yml on SYKernel/perfetto-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file perfetto_cli-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: perfetto_cli-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for perfetto_cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daed09d20ecf53d346a4d884590584ca6e3a7eafa4d92143376e14d1c94ef1f9
MD5 5e56bfdbbeb489a71dc8e83786e6af19
BLAKE2b-256 b231e1b06e9bc177125739536d8b8865c1a648d850e5f71f013a92fb995c0310

See more details on using hashes here.

Provenance

The following attestation bundles were made for perfetto_cli-0.2.0-py3-none-any.whl:

Publisher: ci.yml on SYKernel/perfetto-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page