在中断的情况下覆盖 golang 配置文件停止
Override golang profile stop in case of interrupt
当我 kill -SIGINT pid
在我的 Golang 服务上时,我在调用 profile.Stop
的地方正常关闭,但在调用它之前我收到了这条消息:profile: caught interrupt, stopping profiles
我什至无法调用 profile.Stop,因为它触发得更快,但是 grpc 监听和 couchbase 连接关闭工作正常。
有什么方法可以覆盖这个故障配置文件停止吗?
有一个 profile.NoShutdownHook
函数控制分析包是否应该挂钩 SIGINT,在其上干净地编写分析文件。
如果您想禁用此行为,您可以使用/将上述功能作为选项传递给 profile.Start()
:
profile.Start(profile.NoShutdownHook)
最好通过 deferred 来启动和停止函数内的分析,例如:
// disable the automatic shutdown hook.
defer profile.Start(profile.NoShutdownHook).Stop()
如果禁用自动关闭挂钩,请确保在关闭处理程序中正确地手动调用 Stop()
。
当我 kill -SIGINT pid
在我的 Golang 服务上时,我在调用 profile.Stop
的地方正常关闭,但在调用它之前我收到了这条消息:profile: caught interrupt, stopping profiles
我什至无法调用 profile.Stop,因为它触发得更快,但是 grpc 监听和 couchbase 连接关闭工作正常。
有什么方法可以覆盖这个故障配置文件停止吗?
有一个 profile.NoShutdownHook
函数控制分析包是否应该挂钩 SIGINT,在其上干净地编写分析文件。
如果您想禁用此行为,您可以使用/将上述功能作为选项传递给 profile.Start()
:
profile.Start(profile.NoShutdownHook)
最好通过 deferred 来启动和停止函数内的分析,例如:
// disable the automatic shutdown hook.
defer profile.Start(profile.NoShutdownHook).Stop()
如果禁用自动关闭挂钩,请确保在关闭处理程序中正确地手动调用 Stop()
。