6

I have a small program in go that executes most of its code in parallel using go routines. I start CPU profiling as described in the blog on profiling go programs, but when I look at the data I see only 3-5 samples (the actual runtime of the program is several seconds). Is there way to increase the sample rate? Tried googling but couldn't find a thing...

4

1 回答 1

6

包运行时

func SetCPUProfileRate

func SetCPUProfileRate(hz int)

SetCPUProfileRate 将 CPU 分析速率设置为每秒 hz 样本。如果 hz <= 0,SetCPUProfileRate 关闭分析。如果分析器处于打开状态,则必须先将其关闭,否则无法更改速率。

大多数客户端应该使用 runtime/pprof 包或测试包的 -test.cpuprofile 标志,而不是直接调用 SetCPUProfileRate。

于 2013-11-28T20:50:04.350 回答