编辑:当我将可执行文件添加到 pprof 调用时工作
我正在尝试使用来自https://github.com/pkg/profile的分析器来分析一个简单的程序:并使用工具 pprof。
package main
import "github.com/pkg/profile"
func main() {
defer profile.Start().Stop()
t1()
t2()
}
func t1() {
for i := 0; i < 9000000000; i++ {
x := i * 2
x += x
}
}
func t2() {
for i := 0; i < 1000000000; i++ {
x := i * 2
x += x
}
}
这些示例显示了一个很好的表格,其中包含已调用的所有函数以及每个函数花费了多长时间,但我只看到几秒钟的 100% 使用率,没有更多信息
我该怎么做才能使其输出功能?它与代码完成时输出的“cpu profiling disabled”行有什么关系吗?
这是我用来生成输出的:
./test
2016/12/16 11:04:39 profile: cpu profiling enabled, /tmp/profile176930291/cpu.pprof
2016/12/16 11:04:44 profile: cpu profiling disabled, /tmp/profile176930291/cpu.pprof
martin@martin-laptop:~/work/bin$ go tool pprof -text /tmp/profile176930291/cpu.pprof
4.90s of 4.90s total ( 100%)
flat flat% sum% cum cum%
4.90s 100% 100% 4.90s 100%