Skip to content

Instantly share code, notes, and snippets.

@davewalk
Created May 3, 2016 21:14
Show Gist options
  • Save davewalk/79f632dcac13989eab9d3e6dd43a4492 to your computer and use it in GitHub Desktop.
Save davewalk/79f632dcac13989eab9d3e6dd43a4492 to your computer and use it in GitHub Desktop.
Spin up a pprof web server and print some RAM stats too
_ "net/http/pprof"
go func() {
for _ = range time.Tick(time.Duration(10) * time.Second) {
fmt.Printf("Number of goroutines: %d\n", runtime.NumGoroutine())
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("heap in use: %v\n", m.HeapInuse)
fmt.Printf("heap alloc: %v\n", m.HeapAlloc)
fmt.Printf("next GC: %v\n", m.NextGC)
}
}()
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment