Last active
April 24, 2018 06:25
-
-
Save mettledrum/a6107e0de98140b42222 to your computer and use it in GitHub Desktop.
example of using pprof
This file contains hidden or 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
package main | |
import ( | |
"runtime/pprof" | |
"fmt" | |
"net/http" | |
"os" | |
"time" | |
) | |
// might need graphviz: `brew install graphviz` | |
// make binary: `go build pprof_example.go` | |
// run binary: `./pprof_example` | |
// open that tool: `go tool pprof pprof_example my_profile.prof` | |
// make temp svg file: `web` | |
// open svg in your browser | |
// (when you exit the pprof tool, the svg temp file vanishes) | |
func main() { | |
// make the profile output file | |
f, _ := os.Create("my_profile.prof") | |
// do some hard work | |
fmt.Println("howdy there partner") | |
http.Get("http://google.com") | |
wasteTime() | |
// DON'T use defer | |
pprof.WriteHeapProfile(f) | |
f.Close() | |
} | |
func wasteTime() { | |
time.Sleep(100 * time.Millisecond) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment