go - Pprof 探查器没有捕获任何东西
问题描述
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
并启动它。我有一个跟踪退出信号的程序。之后,我启动我infinitely
正在运行的函数,除非它们被使用输入中断(应用程序无限运行,除非有键盘中断)。我让应用程序运行了一段时间,希望在指定的 pprof 文件中捕获元数据,但该文件始终为空。请注意,我确实通过调用来终止分析stopCPUProfile
。
我究竟做错了什么?
提前致谢。
解决方案
我的错。在信号处理中,我们要确保在退出之前停止分析。所以我们不需要使用defer
.
推荐阅读
- python - 识别和计算数据框中前 x 个对象的统计信息
- python - 从元组列表中获取匹配项的值
- javascript - 在 Chart.js 中实现范围滑块
- powershell - 根据文件名时间戳powershell将文件移动到年/月文件夹中
- github - GitHub Pages URL 将“/”转换为“-”
- javascript - 使用移动应用程序发送和接收射频信号
- javascript - 问题比较 JavaScript 中的时刻
- python - 每天从 url 抓取不同的图像
- amazon-web-services - AWS Api Gateway - 验证传入的 XML 有效负载
- javascript - 如何创建覆盖响应状态代码但保留其余响应的 Cloudflare 工作程序?