golang/go · error

failed to generate pprof: %v

Error message

failed to generate pprof: %v

What it means

The `go tool trace` command with the `-pprof` flag failed to generate profile records from the parsed trace data. After selecting the profile type and constructing the profile function `f`, calling `f(&http.Request{})` returned an error. This means the trace was parsed successfully but the specific profile computation (network, sync, syscall, or sched) encountered an error during analysis.

Source

Thrown at src/cmd/trace/main.go:130

		if err != nil {
			logAndDie(err)
		}
		var f traceviewer.ProfileFunc
		switch *pprofFlag {
		case "net":
			f = pprofByGoroutine(computePprofIO(), parsed)
		case "sync":
			f = pprofByGoroutine(computePprofBlock(), parsed)
		case "syscall":
			f = pprofByGoroutine(computePprofSyscall(), parsed)
		case "sched":
			f = pprofByGoroutine(computePprofSched(), parsed)
		default:
			logAndDie(fmt.Errorf("unknown pprof type %s\n", *pprofFlag))
		}
		records, err := f(&http.Request{})
		if err != nil {
			logAndDie(fmt.Errorf("failed to generate pprof: %v\n", err))
		}
		if err := traceviewer.BuildProfile(records).Write(os.Stdout); err != nil {
			logAndDie(fmt.Errorf("failed to generate pprof: %v\n", err))
		}
		logAndDie(nil)
	}

	// Debug flags.
	if *debugFlag != "" {
		switch *debugFlag {
		case "parsed":
			logAndDie(debugProcessedEvents(tracef))
		case "wire":
			logAndDie(debugRawEvents(tracef))
		case "footprint":
			logAndDie(debugEventsFootprint(tracef))
		default:
			logAndDie(fmt.Errorf("invalid debug mode %s, want one of: parsed, wire, footprint", *debugFlag))

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Check the full error message (wrapped after 'failed to generate pprof:') for the specific failure reason.
  2. Ensure the trace was generated and processed with the same Go version: `go version` on both the tracing program and the trace tool.
  3. Regenerate the trace file: run the program again with `runtime/trace` and a fresh trace file.
  4. Try a different pprof type (net, sync, syscall, sched) — the issue may be specific to one profile computation.
  5. Open the trace in the web UI (`go tool trace trace.out` without `-pprof`) to verify the trace itself is valid.

Example fix

# Before: mismatched Go versions between trace generation and analysis
# (trace generated with Go 1.20, analyzed with Go 1.22)
go tool trace -pprof=net trace.out  # fails

# After: use consistent Go versions
go1.22 test -trace -run TestWorkload ./...
go1.22 tool trace -pprof=net trace.out
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure trace was generated with the same Go version before analysis
// Check trace version header before running pprof extraction:
// (This is internal to go tool trace; user-level validation is version matching)
goVersion := runtime.Version()
fmt.Printf("Analyzing with %s. Ensure trace was generated with the same version.\n", goVersion)

Try / catch

// If wrapping trace analysis in a script:
//   err := runTracePprof(traceFile, pprofType)
//   if err != nil {
//       if strings.Contains(err.Error(), "failed to generate pprof") {
//           // Try different pprof type or regenerate trace
//           log.Printf("Profile generation failed; try regenerating trace")
//       }
//   }

Prevention

When it happens

Trigger: Fires at trace/main.go:128-130 when `f(&http.Request{})` returns an error. The function `f` is one of `pprofByGoroutine(computePprofIO(), ...)`, `pprofByGoroutine(computePprofBlock(), ...)`, etc. This is the first of two 'failed to generate pprof' errors (this one is from the profile function, the second at line 132 is from writing the profile).

Common situations: The trace file is from an incompatible or much older Go version whose event format differs. The trace was corrupted or truncated, leading to incomplete event data. The trace contains events for goroutines that have no matching start/end events (inconsistent trace data). A bug in the trace analysis code for the specific profile type. Traces with version mismatches between the trace producer and the trace tool.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/0ae1299a1fc82d9c. Report an issue: GitHub.