如何识别Go程序的CPU使用热点?

huangapple go评论84阅读模式
英文:

How to identify Go program CPU usage hot spots?

问题

如何识别Go程序的CPU使用热点?

换句话说...

有哪些工具/方法可用于分析Go程序的CPU使用情况?

英文:

How to identify Go program CPU usage hot spots?

In another word...

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

答案1

得分: 11

检查pprof包以编程方式获取性能分析数据。

另一个选项是自动对包的测试进行性能分析:

$ go help testflag
...
    -cpuprofile cpu.out
        在退出之前将CPU分析数据写入指定的文件。

可以使用以下命令来检查性能分析数据:

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

要了解pprof工具的许多选项,请在没有参数的情况下运行它:

$ go tool pprof

要了解pprof的许多命令,请输入'help':

(pprof) help

我建议在浏览器中使用svg选项。它是交互式的,并且突出显示了瓶颈路径以便于检测。使用'list'命令可以查看详细信息,该命令显示函数/方法的源代码以及每行的数据。

推荐阅读:Profiling Go Programs

英文:

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

huangapple
  • 本文由 发表于 2013年6月19日 19:15:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/17189744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定