argent-native-profiler
software-mansion/argent
Native profiling for iOS and Android: CPU hotspots, UI hangs, memory leaks via xctrace and Perfetto.
What is argent-native-profiler?
Diagnose native-level performance issues on iOS (via xctrace) and Android (via Perfetto). Start recording on a running app, stop to export trace data, analyze bottlenecks, and drill into call stacks to identify CPU hotspots, UI hangs, and memory leaks.
- Start and stop native profiling on booted iOS simulators or Android devices
- Export and parse trace data into structured bottleneck reports (CPU, hangs, leaks)
- Query parsed traces by hang stacks, function callers, thread breakdown, and leak details
- Reload and re-investigate previous trace sessions from disk
- Capture malloc stack logging for attributed memory leak backtraces on iOS
How to install argent-native-profiler
npx skills add https://github.com/software-mansion/argent --skill argent-native-profiler- Xcode command-line tools installed and on PATH (iOS)
- Target app running on a booted iOS simulator or connected Android device
- Android app must be debuggable or include `<profileable android:shell="true"/>` in manifest for CPU callstacks
- adb available on PATH (Android)
How to use argent-native-profiler
- 1.Ensure the target app is running on the device or simulator
- 2.Call `native-profiler-start` with device_id to begin recording
- 3.Interact with the app or drive the scenario to profile
- 4.Call `native-profiler-stop` with device_id to halt recording and export trace data
- 5.Call `native-profiler-analyze` with device_id to generate a bottleneck report
- 6.Review findings and decide whether to drill deeper, implement fixes, or stop
- 7.Use `profiler-stack-query` to investigate specific bottlenecks (hang stacks, function callers, leak details)
- 8.After applying fixes, re-profile the same scenario and use `profiler-load` to compare against the baseline
Use cases
- Identify which native functions consume excessive CPU time during app interaction
- Detect main-thread blocks causing UI jank and find the responsible native call chains
- Locate memory leaks with allocation backtraces and responsible frame attribution
- Compare before/after profiling after applying performance fixes to confirm improvement
- Investigate per-thread CPU distribution and GC overlap on Android
- iOS and Android app developers optimizing native performance
- Performance engineers diagnosing production-like jank or memory pressure
- QA teams reproducing and validating performance regressions
- Teams using Xcode Instruments (iOS) or Perfetto (Android) workflows
argent-native-profiler FAQ
CPU hotspots are native functions consuming >15% of total time (or 3–15% for YELLOW severity). UI hangs are main-thread blocks long enough to cause visible jank, often from synchronous I/O, layout, or lock contention. Both are reported separately in the analysis.
xctrace attaches to a running process without malloc-stack history, so most leaks lack a responsible frame and are reported as low-confidence YELLOW. To get attributed stacks, re-run `native-profiler-start` with `malloc_stack_logging: true`, which cold-launches the app with Malloc Stack Logging enabled (adds overhead and restarts the app).
Record the interaction sequence as a flow using `argent-create-flow` before the first profiling run. After applying fixes, replay with `flow-execute` to eliminate interaction variance, then re-profile and use `profiler-load` to reload the baseline trace for side-by-side comparison.
The tool auto-detects whichever flavor is currently running. If both are running, it will ask you to specify which one to profile. Ensure only the target flavor is running to avoid ambiguity.
xctrace instrumentation adds CPU load. If profiler overhead dominates the JS thread, those entries reflect the profiler itself, not app work. Discount them when evaluating findings and focus on consistent directional changes across multiple runs or >15% deltas.
Full instructions (SKILL.md)
Source of truth, from software-mansion/argent.
name: argent-native-profiler description: Native profiling for CPU hotspots, UI hangs, memory issues. iOS via xctrace; Android via Perfetto. Use when diagnosing native-level performance issues.
1. Tools
native-profiler-start— start profiling on a booted device. iOS: xctrace recording for CPU, hangs, and leaks.native-profiler-stop— stop the profiler and export trace data to timestamped XML files.native-profiler-analyze— parse exported trace data and return a structured bottleneck payload.profiler-stack-query— drill into parsed data: hang stacks, function callers, thread breakdown, leak details.profiler-load— list and reload previous trace sessions from disk for re-investigation.- Physical iPhone: not supported; use a simulator.
2. Platform Support
- iOS: Backend: Xcode Instruments via
xctraceon a booted simulator or connected device. Requires Xcode command-line tools on PATH. Surfaces CPU hotspots, UI hangs, and memory leaks (instrumentsLeakstable). - Android: Backend: Perfetto via
adb shell perfetto+ an in-process WASM trace-processor engine. Surfaces CPU hotspots and UI hangs, with per-hang jank reason codes, a main-thread state breakdown withblocked_functionattribution, and a GC overlap annotation. Also reports an RSS-growth signal for memory pressure; treat it as a hint to confirm manually, not a confirmed leak. The target app must be debuggable or include<profileable android:shell="true"/>in its manifest forperf_samplecallstacks to be captured.
3. Investigation Patterns
After native-profiler-analyze surfaces findings, use profiler-stack-query to drill into root causes:
- Hang detected →
profiler-stack-querymode=hang_stacksfor full native call chains → mode=function_callersfor the suspected function → read native source. - CPU hotspot →
profiler-stack-querymode=thread_breakdownfor per-thread distribution → mode=function_callersfor the dominant function. - Memory leak →
profiler-stack-querymode=leak_stacksfiltered byobject_typefor responsible frames and libraries.- iOS: if leaks come back unattributed (responsible frame
<Call stack limit reached>), re-runnative-profiler-startwithmalloc_stack_logging: true. This cold-launches the app with Malloc Stack Logging so leaks carry a real allocation backtrace (responsible frame + library). It restarts the app and adds overhead, so use it only when you need leak attribution — not for CPU/hang passes.
- iOS: if leaks come back unattributed (responsible frame
After presenting findings, ask the user whether to investigate further, implement fixes, or stop. After applying fixes, always re-profile the same scenario and compare with profiler-load. Report honestly whether the target metric improved, regressed, or stayed flat. If the fix showed no net benefit or introduced regressions elsewhere, say so and reconsider.
Tip: For reproducible before/after comparisons, record the interaction sequence as a flow using the argent-create-flow skill before the first profiling run. Replay with flow-execute on subsequent runs to eliminate interaction variance.
Note: The
argent-react-native-profilerinstructs to start native profiling automatically alongside React profiling. This skill's workflow and investigation patterns apply in both cases.
4. Workflow
Complete all steps in order — do not break mid-flow.
Step 0: Ensure the target app is running
The native-profiler-start tool auto-detects the running app on the device.
You do not need to derive app_process manually — just make sure the app is launched.
- If the app is already running on the device, skip to Step 1 (do not pass
app_process). - If the app is not running, use
launch-appwith the correct bundle ID first. - Only pass
app_processexplicitly if the tool reports multiple running user apps and you need to disambiguate.
Note: If multiple build flavors are installed (dev, staging, prod), the tool will detect whichever one is currently running. If both are running, it will ask you to specify.
Step 1: Start recording
Call native-profiler-start with device_id (iOS UDID or Android serial). The tool auto-detects the running app and saves the trace to /tmp/argent-profiler-cwd/ with a timestamped filename.
Let the user interact with the app or drive interaction via simulator tools (see argent-device-interact skill).
Step 2: Stop and export
Call native-profiler-stop with device_id. iOS sends SIGINT to xctrace, waits for trace packaging, and exports CPU, hangs, and leaks data to XML — check exportDiagnostics for any export warnings. Android sends SIGTERM to the on-device perfetto daemon, polls /proc/<pid> until it exits, then adb pulls the .pftrace to the host.
Step 3: Analyze
Call native-profiler-analyze with device_id. Returns a markdown report with bottlenecks categorized as CPU hotspots, UI hangs, or memory leaks, sorted by severity.
Step 4: Present findings and ask about next steps
Present a concise summary of the key findings. Then follow the "After analysis" guideline — ask whether to investigate further with query tools, implement fixes, or stop.
Step 5: Drill-down investigation
Use profiler-stack-query to investigate specific findings. See §3 Investigation Patterns for chaining guidance.
Step 6: Reload previous sessions
To revisit a previous trace:
- Call
profiler-loadmode=listto see available sessions. - Call
profiler-loadmode=load_nativesession_id=<timestamp>device_id=<UDID>to re-parse the XML files. - Use
profiler-stack-queryto investigate the reloaded data.
5. Understanding Results
Bottlenecks are categorized by severity:
- RED: CPU functions taking >15% of total time, all UI hangs, and attributed memory leaks (those with a resolved responsible frame). These require immediate attention.
- YELLOW: CPU functions taking 3-15% of total time, and unattributed memory leaks (
<Call stack limit reached>, no library — see the memory-leaks caveat below). Worth investigating but may be acceptable.
Each bottleneck type indicates a different class of problem:
- CPU hotspots: Native functions consuming excessive CPU time. Look for tight loops, expensive computations, or redundant work.
- UI hangs: Main thread blocked long enough to cause visible jank or unresponsiveness. Often caused by synchronous I/O, heavy layout passes, or lock contention.
- Memory leaks: Objects allocated but never freed. Common causes include retain cycles, unclosed resources, or forgotten observers. Argent records via
xctrace --attach, which has no malloc-stack history, so on the simulator most leaks come back unattributed (<Call stack limit reached>, no library) and are dominated by benign system allocations — these are reported as a low-confidence YELLOW summary, not confirmed RED leaks. For attributed stacks, capture with malloc stack logging enabled at launch.
6. Important Caveats
- Simulator vs device: Simulator profiling reflects host Mac performance, not real device hardware. Use device profiling for accurate CPU timings and memory behavior.
- xctrace availability (iOS): Requires Xcode command-line tools installed. Verify with
xcrun xctrace version. - Profiler overhead: xctrace instrumentation adds CPU load. If
JSLexer,JSONEmitter, or Hermes runtime internals dominate the JS thread in CPU hotspot results, those reflect profiler overhead — not app work. Discount those entries when evaluating findings. - Run-to-run variance: Small fluctuations in CPU percentages between runs are normal. Treat only consistent directional changes (across 2+ runs or >15% delta) as actionable signal.
- Live data variability: If the app fetches live API data, different responses between runs change rendering workload independently of code changes. Note when data-dependent screens show variance.
Related skills
More from software-mansion/argent and the wider catalog.

argent-qa-flows
Create repeatable QA regression E2E tests as Argent flows from test cases and acceptance criteria.

argent-react-native-app-workflow
Step-by-step workflows for developing and debugging React Native apps on iOS simulator or Android emulator.

argent-react-native-optimization
Profile React Native apps to find real bottlenecks, then fix mechanical issues systematically.

argent-react-native-profiler
Profile React Native Hermes apps to measure re-render and CPU performance with ranked issue reports.

argent-screen-recording
Record video of iOS simulator or Android device screens with touch visualization and automatic static-frame trimming.

argent-screenshot-diff
Compare app screenshots to detect visual regressions and UI changes pixel-by-pixel.