Skip to content

Instantly share code, notes, and snippets.

@brancz

brancz/pgofix.go Secret

Last active February 3, 2023 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brancz/9e56f8a302d6e196f57c4953156595b5 to your computer and use it in GitHub Desktop.
Save brancz/9e56f8a302d6e196f57c4953156595b5 to your computer and use it in GitHub Desktop.
Adapt pprof profile data downloaded from Parca to be on index position 1. This is needed because in the Go 1.20 release the compiler hard-codes this position. See: https://github.com/golang/go/issues/58292
package main
import (
"log"
"os"
"github.com/google/pprof/profile"
)
func main() {
filename := os.Args[1]
f, err := os.Open(filename)
if err != nil {
log.Fatal("open:", err)
}
p, err := profile.Parse(f)
if err != nil {
log.Fatal("could not parse profile: ", err)
}
p.SampleType = []*profile.ValueType{
&profile.ValueType{
Type: "fake",
Unit: "fake",
},
p.SampleType[0],
}
for _, s := range p.Sample {
s.Value = []int64{0, s.Value[0]}
}
f, err = os.Create(filename + ".out")
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close()
if err := p.Write(f); err != nil {
log.Fatal("could not write profile: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment