How to identify Go program CPU usage hot spots?
In another word...
Which tools/methods are available for profiling Go program CPU usage?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.