Skip to content

Instantly share code, notes, and snippets.

@nclv
Created June 13, 2021 09:29
Show Gist options
  • Save nclv/e52516a904b936ea0aa10109f6ce5ad9 to your computer and use it in GitHub Desktop.
Save nclv/e52516a904b936ea0aa10109f6ce5ad9 to your computer and use it in GitHub Desktop.
Golang profiling with pprof
import "runtime/pprof"
func main() {
f, err := os.Create("cpuprofile")
if err != nil {
fmt.Fprintf(os.Stderr, "could not create CPU profile: %v\n", err)
os.Exit(1)
}
if err := pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "could not start CPU profile: %v\n", err)
os.Exit(1)
}
defer pprof.StopCPUProfile()
// run()
// go tool pprof -http=:7777 cpuprofile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment