# go error: go tool pprof - profile contains no samples - how to fix

## TL;DR

An empty profile means the profiler never got to sample: the process exited before sampling started, signals are blocked, or the profile window captured nothing. Keep the process alive through the whole window, make sure SIGPROF is not blocked, and give it at least 30 seconds of real work to sample.

```text
go tool pprof - profile contains no samples
```

## Steps

1. Make sure the process outlives the profile window: run the profile for 30s against a process that stays up and does work the whole time.
   Expected: A longer-lived process produces samples.

2. Check SIGPROF is not blocked or ignored by the app or its container runtime. Some sandboxes swallow profiling signals.
   Expected: Signals reach the process (test with a trivial CPU profile of a busy loop).

3. If profiling a short-lived command, use -cpuprofile to write the file instead of the HTTP endpoint, and verify the file is nonzero before opening it.
   Expected: The output file has real size.

4. Confirm the binary was built with the same Go version and not stripped of symbols in a way that breaks sampling (it still samples, but verify the basics first).
   Expected: pprof opens the profile and shows functions.

5. For HTTP-based profiles, hit /debug/pprof/profile?seconds=30 directly and watch for errors in the app log during the window.
   Expected: The endpoint returns a valid profile instead of an empty one.

## When to use

- go tool pprof reports no samples
- the profile file is empty or tiny
- CPU profiling a short-lived process

## When not to use

- pprof shows samples but symbols are missing (build with symbols; different issue)
- the profile is for heap or goroutines (those do not need sampling windows)
- the process is idle (an idle process legitimately has no CPU samples)

## Tool compatibility

- Go 1.19+
- runtime/pprof, net/http/pprof

## Variant phrasings

- "pprof profile contains no samples"
- "go tool pprof empty profile"
- "pprof no samples collected"

## Why it happens

CPU profiling works by interrupting the process with SIGPROF on a timer and recording the stack. If the process dies before the first tick, blocks the signal, or does no CPU work during the window, there is nothing to record and pprof reports an empty profile.

## Edge cases

- profiling inside some containers needs the SYS_PTRACE-adjacent permissions; without them the signal path can fail silently
- a program sleeping in syscalls the whole window yields no CPU samples; that is correct, not a bug
- mixing -cpuprofile output with the HTTP endpoint in one run can truncate the file; use one method per run

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_8qoTVTlzPnmbqQFxt14qbA
