Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Go profiling "always on"?

Tags:

profiling

go

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?

like image 390
dschultz Avatar asked Dec 25 '22 22:12

dschultz


1 Answers

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/

like image 65
JimB Avatar answered Jan 10 '23 11:01

JimB