How to Capture a CPU Profile in GitHub Actions
Node can write a V8 CPU profile with --cpu-prof, and uploading the .cpuprofile lets you open a flame graph from any CI run.
Run the workload with node --cpu-prof --cpu-prof-dir, which writes a .cpuprofile you can open in Chrome DevTools or Speedscope. Upload it as an artifact for later inspection.
Steps
- Run the workload with
--cpu-prof --cpu-prof-dir=profiles. - Node writes a
.cpuprofilewhen the process exits. - Upload the directory as an artifact.
Workflow
.github/workflows/ci.yml
jobs:
cpu-profile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: node --cpu-prof --cpu-prof-dir=profiles ./scripts/workload.js
- uses: actions/upload-artifact@v4
with:
name: cpu-profile
path: profiles/Gotchas
- The profile is written on a clean exit; a crashed process may leave none.
- Open the
.cpuprofilein Chrome DevTools (Performance) or speedscope.app for a flame graph.
Related guides
How to Run a Memory Leak Check in GitHub ActionsDetect a growing heap in GitHub Actions by running a Node script under --expose-gc that takes heap snapshots…
How to Profile a Slow Build in GitHub ActionsFind where build time goes in GitHub Actions by enabling your bundler profiler, such as esbuild metafile or w…