在中断时覆盖 golang 配置文件停止



当我kill -SIGINT pid我的 Golang 服务时,我有一个优雅的关闭,我调用了 profile.Stop ,但在我调用它之前,我收到了以下消息:profile: caught interrupt, stopping profiles

我什至无法调用配置文件。停止,因为它会更快地触发,但是 grpc 侦听和 couchbase 连接关闭工作正常。

无论如何,我可以覆盖此故障配置文件停止吗?

有一个profile.NoShutdownHook函数,用于控制分析包是否应挂钩 SIGINT,以便在 SIGINT 上干净地写入配置文件。

您可以使用

/传递上述函数作为选项来profile.Start()是否要禁用此行为:

profile.Start(profile.NoShutdownHook)

在函数内启动和停止分析最好通过延迟来完成,例如:

// disable the automatic shutdown hook.
defer profile.Start(profile.NoShutdownHook).Stop()

如果禁用自动关机挂钩,请确保在关机处理程序中正确手动调用Stop()

最新更新