Go profiling是否“始终开启”?

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

Is Go profiling "always on"?

问题

我想给我的Go程序添加命令行标志,以启用/禁用CPU和内存分析。使用pprof.StartCPUProfile()可以显式启用CPU分析。但是内存分析没有显式启用。只需在退出时调用pprof.WriteHeapProfile()。如果我从未调用这些函数,这两种分析方式是否会有运行时成本?如果没有,那是否意味着内存分析基本上始终处于开启状态?

英文:

I'd like to add command line flags to my Go program to enable/disable cpu and memory profiling. CPU profiling is enabled explicitly with pprof.StartCPUProfile(). But memory profiling is not explicitly enabled. You just call pprof.WriteHeapProfile() at exit. Is there a runtime cost associated with either form of profiling if I never make those calls? And if not, does that mean that the memory profiling is basically always on?

答案1

得分: 10

MemProfileRate默认情况下是非零的,但它设置的速率足够低,不应该影响大多数程序。它默认开启,这样如果程序的内存开始膨胀,就会有一些数据可以在不重新编译的情况下找到问题。

在go1.5中,将会有一个新的GODEBUG标志memprofilerate,因此可以通过环境变量进行更改。将memprofilerate=0设置为禁用内存分析。http://tip.golang.org/pkg/runtime/

英文:

MemProfileRate is nonzero by default, but it's set to a rate that's low enough that it shouldn't affect most programs. It's on by default so that if a program's memory starts to balloon, there would be some data to find the problem without recompiling.

In go1.5 there will be a new GODEBUG flag memprofilerate, so it can be changed via an environment variable. Setting memprofilerate=0 will disable memory profiling. http://tip.golang.org/pkg/runtime/

huangapple
  • 本文由 发表于 2015年2月27日 05:53:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/28753480.html
匿名

发表评论

匿名网友

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

确定