Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify Go program CPU usage hot spots?

Tags:

go

How to identify Go program CPU usage hot spots?

In another word...

Which tools/methods are available for profiling Go program CPU usage?


1 Answers

Check the pprof package for programmatically acquiring profiling data.

Another option is to automatically profile package tests:

$ go help testflag
...
    -cpuprofile cpu.out
        Write a CPU profile to the specified file before exiting.

The profiling data can be inspected using:

$ go tool pprof your-binary your-profiling-data

For help with the many options of the pprof tool run it without arguments:

$ go tool pprof

For help with the many commands of pprof, enter 'help':

(pprof) help

I suggest to use the svg option in the browser. It's interactive and the bottleneck paths are emphasized for easy detection. Details are available using the 'list' command, which shows the source code for a function/method together with the per-line data.

Recommended reading: Profiling Go Programs

like image 116
zzzz Avatar answered Sep 23 '25 14:09

zzzz