Record and analyze hangs with hang_watcher.py
mainThe hang_watcher.py script (HangBuster) records and summarizes os_log hang events using two modes:
1. Session Mode (Agent-Native)
Designed for interactive debugging. It uses a detached recorder that normalizes and clusters events to provide a token-efficient summary.
Workflow:
- Start:
SID=$(python scripts/hang_watcher.py --start --min-hang-ms 200) - Interact: Perform actions in the simulator.
- Stop:
python scripts/hang_watcher.py --stop $SID(returns an L1 summary). - Drill Down:
python scripts/hang_watcher.py --get-details $SID --cluster 1(returns L2 details). - Compare:
python scripts/hang_watcher.py --diff $SID_BASELINE $SID(regression report).
2. Raw Capture Mode
Skips clustering for full-fidelity log dumping, ideal for jq exploration.
Workflow:
- Start:
SID=$(python scripts/hang_watcher.py --start --raw-capture --max-size-mb 5) - Stop:
python scripts/hang_watcher.py --stop $SID - Explore: Use
zcatandjqon the resulting.gzfile in~/.ios-simulator-skill/sessions/$SID/raw.ndjson.gz.
Key Options:
--start: Begins a new session.--stop <SESSION_ID>: Ends session and summarizes.--get-details <SESSION_ID>: Provides deeper inspection.--raw-capture: Enables raw NDJSON capture.--max-size-mb: Sets a cap on the raw capture size.--min-hang-ms: Minimum duration for a hang to be recorded.
# Summarized mode workflow
SID=$(python scripts/hang_watcher.py --start --min-hang-ms 200)
# ... interact with simulator ...
python scripts/hang_watcher.py --stop $SID
python scripts/hang_watcher.py --get-details $SID --cluster 1