{"record":{"id":"0ae1299a1fc82d9c","repo":"golang/go","slug":"failed-to-generate-pprof-v","errorCode":null,"errorMessage":"failed to generate pprof: %v\n","messagePattern":"failed to generate pprof: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/trace/main.go","lineNumber":130,"sourceCode":"\t\tif err != nil {\n\t\t\tlogAndDie(err)\n\t\t}\n\t\tvar f traceviewer.ProfileFunc\n\t\tswitch *pprofFlag {\n\t\tcase \"net\":\n\t\t\tf = pprofByGoroutine(computePprofIO(), parsed)\n\t\tcase \"sync\":\n\t\t\tf = pprofByGoroutine(computePprofBlock(), parsed)\n\t\tcase \"syscall\":\n\t\t\tf = pprofByGoroutine(computePprofSyscall(), parsed)\n\t\tcase \"sched\":\n\t\t\tf = pprofByGoroutine(computePprofSched(), parsed)\n\t\tdefault:\n\t\t\tlogAndDie(fmt.Errorf(\"unknown pprof type %s\\n\", *pprofFlag))\n\t\t}\n\t\trecords, err := f(&http.Request{})\n\t\tif err != nil {\n\t\t\tlogAndDie(fmt.Errorf(\"failed to generate pprof: %v\\n\", err))\n\t\t}\n\t\tif err := traceviewer.BuildProfile(records).Write(os.Stdout); err != nil {\n\t\t\tlogAndDie(fmt.Errorf(\"failed to generate pprof: %v\\n\", err))\n\t\t}\n\t\tlogAndDie(nil)\n\t}\n\n\t// Debug flags.\n\tif *debugFlag != \"\" {\n\t\tswitch *debugFlag {\n\t\tcase \"parsed\":\n\t\t\tlogAndDie(debugProcessedEvents(tracef))\n\t\tcase \"wire\":\n\t\t\tlogAndDie(debugRawEvents(tracef))\n\t\tcase \"footprint\":\n\t\t\tlogAndDie(debugEventsFootprint(tracef))\n\t\tdefault:\n\t\t\tlogAndDie(fmt.Errorf(\"invalid debug mode %s, want one of: parsed, wire, footprint\", *debugFlag))","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/trace/main.go#L112-L148","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check the full error message (wrapped after 'failed to generate pprof:') for the specific failure reason.","Ensure the trace was generated and processed with the same Go version: `go version` on both the tracing program and the trace tool.","Regenerate the trace file: run the program again with `runtime/trace` and a fresh trace file.","Try a different pprof type (net, sync, syscall, sched) — the issue may be specific to one profile computation.","Open the trace in the web UI (`go tool trace trace.out` without `-pprof`) to verify the trace itself is valid."],"exampleFix":"# Before: mismatched Go versions between trace generation and analysis\n# (trace generated with Go 1.20, analyzed with Go 1.22)\ngo tool trace -pprof=net trace.out  # fails\n\n# After: use consistent Go versions\ngo1.22 test -trace -run TestWorkload ./...\ngo1.22 tool trace -pprof=net trace.out","handlingStrategy":"try-catch","validationCode":"// Ensure trace was generated with the same Go version before analysis\n// Check trace version header before running pprof extraction:\n// (This is internal to go tool trace; user-level validation is version matching)\ngoVersion := runtime.Version()\nfmt.Printf(\"Analyzing with %s. Ensure trace was generated with the same version.\\n\", goVersion)","typeGuard":null,"tryCatchPattern":"// If wrapping trace analysis in a script:\n//   err := runTracePprof(traceFile, pprofType)\n//   if err != nil {\n//       if strings.Contains(err.Error(), \"failed to generate pprof\") {\n//           // Try different pprof type or regenerate trace\n//           log.Printf(\"Profile generation failed; try regenerating trace\")\n//       }\n//   }","preventionTips":["Always use the same Go version for trace generation and analysis.","Regenerate traces if they are from an old Go version.","Try different -pprof types to determine if the issue is type-specific.","Open the trace in the web UI first to validate overall trace integrity."],"tags":["trace","pprof","runtime-trace","trace-parsing","version-mismatch"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}