Table of Contents |
---|
Pre-Requisite
Install Graphviz
Mac:
Code Block |
---|
brew install graphviz |
...
We can add in a benchmark test which will allow us to profile a section of code.
Creating Profiles from Benchmark
...
Test
Code Block |
---|
go test -bench=. -run=x -benchmem -memprofile mem.prof -cpuprofile cpu.prof -benchtime=5s10s > 0.bench |
After running the benchmark we can use the outputted profiles with pprof.
...
Code Block |
---|
go tool pprof heap.out |
Profiling with Pprof
...
CPU Profiling
Code Block |
---|
$ go tool pprof cpu.prof Type: cpu Time: Jul 15, 2022 at 1:25pm (EDT) Duration: 7.34s, Total samples = 7.45s (101.51%) Entering interactive mode (type "help" for commands, "o" for options) (pprof) |
...