Lesson 32 of 60 · Go
Profiling Go Applications with pprof
Duration: 15 minutes
Runtime Profilers
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
The net/http/pprof package exposes profiling data over HTTP.
import _ "net/http/pprof"
func main() {
go func() { http.ListenAndServe(":6060", nil) }()
// rest of your app …
}
Visit http://localhost:6060/debug/pprof/ and click heap, goroutine, profile.
Generating a CPU profile manually
$ go test -bench=BenchmarkXYZ -benchmem -cpuprofile=cpu.out
$ go tool pprof cpu.out
(pprof) top
Visualizing with graphviz
$ go tool pprof -http=:8080 cpu.out