Start / Stop
f, _ := os.Create("cpu.pprof")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
// ... workload ...
runtime/pprofWrite CPU, heap, block, mutex, goroutine profiles. Analyze with `go tool pprof`.
f, _ := os.Create("cpu.pprof")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
// ... workload ...
f, _ := os.Create("heap.pprof")
pprof.Lookup("heap").WriteTo(f, 0)
// others: "goroutine", "allocs", "block", "mutex", "threadcreate"
pprof.Do(ctx, pprof.Labels("endpoint", "/users"), func(ctx context.Context) {
serve(ctx)
})
go tool pprof cpu.pprof
(pprof) top
(pprof) web
(pprof) list funcName