Skip to content

ANR Detection

Detect ANR (Application Not Responding) events and identify root causes through multi-signal analysis.

Overview

ANR occurs when an application's main thread is blocked for too long (typically 5+ seconds). perfetto-cli detects ANR events from Perfetto traces and classifies their severity.

Commands

anr detect

Detect ANR events with severity classification.

perfetto-cli -t trace.perfetto-trace -p com.example.app anr detect

Options:

Option Description Default
--min-duration <ms> Minimum ANR duration to report None

Example output:

ANR Events (2 found)
┌──────────┬──────────┬──────────────┬──────────┐
│ Time     │ Duration │ Thread       │ Severity │
├──────────┼──────────┼──────────────┼──────────┤
│ 5.234s   │ 6.1s    │ main         │ CRITICAL │
│ 12.001s  │ 5.3s    │ main         │ HIGH     │
└──────────┴──────────┴──────────────┴──────────┘

anr root-cause

Multi-signal root cause analysis. Correlates ANR events with CPU, lock contention, binder, and I/O signals to identify the most likely cause.

perfetto-cli -t trace.perfetto-trace -p com.example.app anr root-cause --anr-timestamp 5000

Options:

Option Description Required
--anr-timestamp <ms> Timestamp of the ANR event to analyze Yes

Workflow

  1. Run anr detect to find ANR events and their timestamps
  2. Pick a specific ANR timestamp
  3. Run anr root-cause --anr-timestamp <ts> for detailed root cause analysis

Tips

  • Use --min-duration to filter out borderline cases and focus on severe ANRs
  • Combine with cpu contention to see if lock contention contributed to the ANR
  • Use -f json to integrate ANR detection into CI pipelines