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