aer
Profiling and Tracing

Profiling and Tracing

Profiling lets you understand where Apex time is spent when you run code locally with aer. Tracing records every line that executes so you can replay complex flows. Both features are available on the major entry points—test, run, and exec.

Capture CPU profiles

Use --profile to write a Go pprof CPU profile while your Apex code executes. The flag accepts the destination file; the profile is only written when the command exits successfully.

# Apex tests
aer test force-app/main/default \
  --profile tmp/test.pprof

# Run a method directly
aer run OrderService.reprice \
  --path force-app/main/default \
  --profile tmp/run.pprof

# Execute anonymous Apex
aer exec force-app/main/default \
  --exec "OrderService.reprice();" \
  --profile tmp/exec.pprof

Inspect the output with Go’s tooling:

go tool pprof tmp/test.pprof

From inside pprof you can generate flame graphs (web), call trees (top), or table views of the hottest functions.

Record execution traces

Add --trace to emit a detailed execution trace. The trace captures every Apex line and SOQL/DML statement so you can replay what happened when a test fails.

aer test force-app/main/default \
  --trace tmp/test.trace

aer run OrderService.reprice \
  --path force-app/main/default \
  --trace tmp/run.trace

aer exec force-app/main/default \
  --exec "OrderService.reprice();" \
  --trace tmp/exec.trace

Open the trace with go tool trace to replay the execution timeline, load it into Perfetto for a Chrome-like timeline view, or use editors that support Go trace files (VS Code, JetBrains).

Tips

  • Combine --profile and --trace to generate both artifacts in a single run.
  • Store trace and profile files outside of your repo (for example, in tmp/) to avoid committing large binaries.
  • Profiles and traces reflect the local runtime; rerun them whenever you update dependencies, schema, or managed packages so results stay current.
© 2012–2025 October Swimmer.