Home > Blockchain >  Is profiling enabled by default for all go programs?
Is profiling enabled by default for all go programs?

Time:04-07

Since importing net/http/pprof package is enough to enable the golang profiler in a program, my question is, is the profiler enabled by default for all golang programs, and importing the package just exposes the metrics endpoint? If that is the case, how could I disable the profiler to eliminate performance overhead?

CodePudding user response:

Is profiling enabled by default for all go programs?

No.

is the profiler enabled by default for all golang programs, and importing the package just exposes the metrics endpoint?

No.

If that is the case, how could I disable the profiler to eliminate performance overhead?

No, that's not the case.

CodePudding user response:

If you look at the source code of the pprof.go file, you can see in its handlers, that the profiling, tracing etc. are running only when you do a GET on any of its endpoints.

If you specify a time, for example: http://localhost:6060/debug/pprof/trace?seconds=10 the server will take 10 seconds to respond with the trace data. So the profiling is happening only if you call on an endpoint.

You can find some examples in the first comment block of the pprof.go file.

  • Related