在分析Go程序时,是否可以增加采样率?

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

Is it possible to increase the sample rate when profiling go programs?

问题

我有一个使用Go编写的小程序,它使用Go协程并行执行大部分代码。我按照博客中描述的方法启动了CPU分析,但是当我查看数据时,只看到了3-5个样本(实际程序运行时间为几秒)。有没有办法增加采样率?我尝试过搜索,但没有找到相关信息...

英文:

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...

答案1

得分: 6

包运行时

func SetCPUProfileRate

func SetCPUProfileRate(hz int)

SetCPUProfileRate函数将CPU分析率设置为每秒hz个样本。如果hz <= 0,则SetCPUProfileRate将关闭分析。如果分析器处于打开状态,则无法在关闭之前更改速率。

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

英文:

> Package runtime
>
> func SetCPUProfileRate
>
> func SetCPUProfileRate(hz int)
>
> SetCPUProfileRate sets the CPU profiling rate to hz samples per
> second. If hz <= 0, SetCPUProfileRate turns off profiling. If the
> profiler is on, the rate cannot be changed without first turning it
> off.
>
> Most clients should use the runtime/pprof package or the testing
> package's -test.cpuprofile flag instead of calling SetCPUProfileRate
> directly.

huangapple
  • 本文由 发表于 2013年11月29日 04:17:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/20274173.html
匿名

发表评论

匿名网友

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

确定