Skip to content
Latchkey

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 .cpuprofile when 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 .cpuprofile in Chrome DevTools (Performance) or speedscope.app for a flame graph.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →