使用pprof进行Golang性能分析时,如何获取命中次数而不是持续时间?

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

golang profile with pprof, how to get hit count not duration?

问题

如何获取类似以下的命中次数:

(pprof) top
总计:2525个样本
     298  11.8%  11.8%      345  13.7% runtime.mapaccess1_fast64
     268  10.6%  22.4%     2124  84.1% main.FindLoops

而不是持续时间,如下所示:

(pprof) top
总计3080ms中的2220ms (72.08%)
丢弃了72个节点 (累计时间 ≤ 15.40ms)
显示111个节点中的前10个 (累计时间 ≥ 60ms)
      flat  flat%   sum%        cum   cum%
    1340ms 43.51% 43.51%     1410ms 45.78%  runtime.cgocall_errno

环境:我正在使用golang1.4,添加以下代码。

defer pprof.StopCPUProfile()
f, err := os.Create("innercpu.pprof")
if err != nil {
	fmt.Println("错误:", err)
}
pprof.StartCPUProfile(f)
英文:

how to get hit count like:

(pprof) top
Total: 2525 samples
     298  11.8%  11.8%      345  13.7% runtime.mapaccess1_fast64
     268  10.6%  22.4%     2124  84.1% main.FindLoops

not, durations like:

(pprof) top
2220ms of 3080ms total (72.08%)
Dropped 72 nodes (cum <= 15.40ms)
Showing top 10 nodes out of 111 (cum >= 60ms)
      flat  flat%   sum%        cum   cum%
    1340ms 43.51% 43.51%     1410ms 45.78%  runtime.cgocall_errno

env: I using golang1.4, add below codes.

defer pprof.StopCPUProfile()
f, err := os.Create("innercpu.pprof")
if err != nil {
	fmt.Println("Error: ", err)
}
pprof.StartCPUProfile(f)

答案1

得分: 6

你可以使用go tool pprof -callgrind -output callgrind.out innercpu.pprof将收集到的性能分析数据生成callgrind数据。然后你可以使用qcachegrind/kcachegrind来可视化这些数据。它将显示调用次数。

英文:

You can use go tool pprof -callgrind -output callgrind.out innercpu.pprof to generate callgrind data out of your collected profiling data. Which you can then visualise with qcachegrind/kcachegrind. It'll display call counts.

huangapple
  • 本文由 发表于 2015年3月8日 16:34:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/28924550.html
匿名

发表评论

匿名网友

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

确定