Skip to content

Instantly share code, notes, and snippets.

@mettledrum
Last active April 24, 2018 06:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mettledrum/a6107e0de98140b42222 to your computer and use it in GitHub Desktop.
Save mettledrum/a6107e0de98140b42222 to your computer and use it in GitHub Desktop.
example of using pprof
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