【发布时间】:2017-11-06 11:08:44
【问题描述】:
鉴于以下玩具代码,我希望能够运行
go tool pprof cpu.prof
并获得有关waster1和waster2的有用信息,但是当我在pprof中运行top时,我得到的只是:
Showing nodes accounting for 0, 0% of 0 total
flat flat% sum% cum cum%
问题可能是我使用 WSL 在 Windows 10 上运行 Ubuntu。
这是我正在使用的代码:
package main
import (
"fmt"
"log"
"os"
"runtime/pprof"
)
func waster2() int {
j := 0;
for i := 0; i < 100; i++ {
j += waster1()
}
return j
}
func waster1() int {
j := 0;
for i := 0; i < 10000; i++ {
j++
}
return j
}
func main() {
f, err := os.Create("cpu.prof")
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
j := waster2()
fmt.Println(j)
}
【问题讨论】:
-
看起来它在自己运行的 Debian 上做同样的事情,所以 Windows 10 的事情是红鲱鱼。
-
首先您需要将二进制文件作为参数提供给
pprof。你的程序运行多长时间?您可能没有足够的样本来制作有意义的个人资料。 -
@JimB 为函数添加睡眠(现在超过 10 秒运行时间)和工具命令的二进制文件,仍然没有输出。
-
SIGPROF 可能在 WSL 中不起作用,我不确定如何在 Windows 上跟踪它。
标签: ubuntu go windows-10 profiling windows-subsystem-for-linux