英文:
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(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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论