{"record":{"id":"79d564c194853f34","repo":"golang/go","slug":"profile-does-not-contain-a-sample-index-with-value","errorCode":null,"errorMessage":"profile does not contain a sample index with value/type \"samples/count\" or cpu/nanoseconds\"","messagePattern":"profile does not contain a sample index with value/type \"samples/count\" or cpu/nanoseconds\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/pgo/pprof.go","lineNumber":46,"sourceCode":"\n\tif len(p.Sample) == 0 {\n\t\t// We accept empty profiles, but there is nothing to do.\n\t\treturn emptyProfile(), nil\n\t}\n\n\tvalueIndex := -1\n\tfor i, s := range p.SampleType {\n\t\t// Samples count is the raw data collected, and CPU nanoseconds is just\n\t\t// a scaled version of it, so either one we can find is fine.\n\t\tif (s.Type == \"samples\" && s.Unit == \"count\") ||\n\t\t\t(s.Type == \"cpu\" && s.Unit == \"nanoseconds\") {\n\t\t\tvalueIndex = i\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif valueIndex == -1 {\n\t\treturn nil, fmt.Errorf(`profile does not contain a sample index with value/type \"samples/count\" or cpu/nanoseconds\"`)\n\t}\n\n\tg := profile.NewGraph(p, &profile.Options{\n\t\tSampleValue: func(v []int64) int64 { return v[valueIndex] },\n\t})\n\n\tif len(g.Nodes) == 0 {\n\t\t// If all sample values are 0, the graph will have no nodes.\n\t\t// In this case, treat it as an empty profile.\n\t\treturn emptyProfile(), nil\n\t}\n\n\tnamedEdgeMap, totalWeight, err := createNamedEdgeMap(g)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif totalWeight == 0 {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/pgo/pprof.go#L28-L64","documentation":"Thrown when the pprof profile's SampleType list contains no entry matching \"samples\"/\"count\" or \"cpu\"/\"nanoseconds\". The deserializer iterates p.SampleType looking for either of these two recognized sample type/unit pairs to determine which value index to use for edge weights. If neither is found, valueIndex stays -1 and the error fires.","triggerScenarios":"The pprof profile's SampleType array only contains entries with different type/unit combinations (e.g. \"inclusions\"/\"samples\", \"allocations\"/\"bytes\", or custom sample types from a third-party profiler). Neither the \"samples/count\" nor \"cpu/nanoseconds\" pair is present.","commonSituations":"Using a profile from a non-CPU profiler (heap, goroutine, block, mutex profiles) as a PGO input. Also happens with profiles generated by third-party profilers (e.g. Java perf, Python cProfile exported to pprof) that use different sample type naming. Custom runtime/pprof profiles with custom SampleType names also trigger this.","solutions":["Ensure the profile is a CPU profile with SampleType entries of either \"samples\"/\"count\" or \"cpu\"/\"nanoseconds\".","Use Go's built-in CPU profiling (go test -cpuprofile or runtime/pprof.StartCPUProfile) which emits the correct sample types.","Verify the profile type with `go tool pprof -top <file>` and confirm the sample types listed in the header.","Do not feed heap, goroutine, or other non-CPU profiles as PGO input."],"exampleFix":"// Correct: generate a CPU profile\n// f, _ := os.Create(\"cpu.prof\")\n// pprof.StartCPUProfile(f)\n// ... run workload ...\n// pprof.StopCPUProfile()\n\n// Wrong: this produces a heap profile (wrong sample type)\n// pprof.WriteHeapProfile(f)","handlingStrategy":"validation","validationCode":"// Check sample types before converting to PGO Profile:\nfunc hasValidSampleType(p *profile.Profile) bool {\n    for _, st := range p.SampleType {\n        if (st.Type == \"samples\" && st.Unit == \"count\") ||\n           (st.Type == \"cpu\" && st.Unit == \"nanoseconds\") {\n            return true\n        }\n    }\n    return false\n}\n\n// Usage:\n// if !hasValidSampleType(pprofProfile) {\n//     return errors.New(\"profile must contain samples/count or cpu/nanoseconds sample type\")\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use CPU profiles for PGO — never heap, goroutine, block, or mutex profiles.","Verify sample types with `go tool pprof -top <file>` and check the header.","Use Go's built-in CPU profiling to guarantee correct sample type naming."],"tags":["pgo","pprof","sample-type","cpu-profile","go-compiler-internal"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}