Skip to content

Instantly share code, notes, and snippets.

@leetrout
Created July 9, 2020 01:14
Show Gist options
  • Select an option

  • Save leetrout/e46c67eccc54dadc732404e35cc54ca6 to your computer and use it in GitHub Desktop.

Select an option

Save leetrout/e46c67eccc54dadc732404e35cc54ca6 to your computer and use it in GitHub Desktop.
Quick drop in profiler snippet for Go
// Rename your main func to _main and drop this in
func main() {
f, err := os.Create("trace_" + time.Now().Format("20060102150405"))
if err != nil {
panic(err)
}
trace.Start(f)
_main()
trace.Stop()
f.Close()
f, err = os.Create("memprof_" + time.Now().Format("20060102150405"))
if err != nil {
panic(err)
}
pprof.WriteHeapProfile(f)
f.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment