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

4
如何获取类似于点击次数的计数:
(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

不要使用类似以下的时间长度:

(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

环境:我使用的是golang1.4版本,添加了以下代码。

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 对其进行可视化。它会显示函数调用次数。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接