func main() {
runtime.SetCPUProfileRate(500)
cpuProfiler := "profile.prof"
f, _ := os.Create(cpuProfiler)
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
onKill := func(c chan os.Signal) {
select {
case <-c:
defer f.Close()
defer pprof.StopCPUProfile()
defer os.Exit(0)
}
}
go onKill(c)
streamCAN, streamIMU, done := mainfunctions.DialUpConnection(logger, configread.GetString("library.development.grpctarget"))
rawCANData := mainfunctions.GetCANDataFromStream(logger, done, streamCAN)
rawIMUData := mainfunctions.GetIMUDataFromStream(logger, done, streamIMU)
moduleData := mainfunctions.DistributeDataFromStream(logger, done, rawCANData, rawIMUData)
log.Debug(moduleData)
mainfunctions.DistributeDataFromStream(logger, done, rawCANData, rawIMUData)
channelOut := mainfunctions.RunAlgos(logger, done, moduleData)
log.Debug(channelOut)
mainfunctions.ReturnDataToStream(logger, done, channelOut)
// subscribe to system signals
}我有一个go-app,我必须在其中比较pprof的输出。为此,我在main函数中创建了一个cpuProfiler并启动它。我有一个go程序来跟踪退出的信号。在那之后,我启动我的infinitely运行函数,除非它们使用输入中断(应用程序无限运行,除非有键盘中断)。我让应用程序运行了一段时间,希望在指定的pprof文件中捕获meta,但该文件总是空的。请注意,我是通过调用stopCPUProfile来终止分析的。
我做错了什么?
提前谢谢。
发布于 2020-11-25 14:14:51
是我的错。在信号处理中,我们希望确保在退出之前停止分析。所以我们不需要使用defer。
https://stackoverflow.com/questions/64999144
复制相似问题