Created
June 13, 2021 09:29
-
-
Save nclv/e52516a904b936ea0aa10109f6ce5ad9 to your computer and use it in GitHub Desktop.
Golang profiling with pprof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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