所有Go程序默认启用性能分析吗?

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

Is profiling enabled by default for all go programs?

问题

导入net/http/pprof包就足以在程序中启用Golang分析器,我的问题是,是否所有的Golang程序默认都启用了分析器,并且导入该包只是暴露了度量指标的端点?如果是这样的话,我该如何禁用分析器以消除性能开销?

英文:

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?

答案1

得分: 3

默认情况下,所有的Go程序都没有启用性能分析器。

默认情况下,所有的Golang程序都没有启用性能分析器,导入该包只是暴露了度量指标的端点。

如果是这种情况,我该如何禁用性能分析器以消除性能开销?

不,情况并非如此。

英文:

> 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.

答案2

得分: 2

如果你查看pprof.go文件的源代码,你会发现在它的处理程序中,只有在对其任何端点进行GET请求时,才会运行分析、跟踪等操作。

如果你指定一个时间,例如:http://localhost:6060/debug/pprof/trace?seconds=10,服务器将花费10秒钟来响应跟踪数据。因此,只有在调用端点时才会进行分析。

你可以在pprof.go文件的第一个注释块中找到一些示例。

英文:

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.

huangapple
  • 本文由 发表于 2022年4月7日 04:01:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/71772943.html
匿名

发表评论

匿名网友

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

确定