关于pprof工具的问题

package main

import (
    "os"
    "log"
    "runtime/pprof"
    "fmt"
)

func main() {
    f, err := os.OpenFile("cpu.prof", os.O_RDWR|os.O_CREATE, 0644)
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()
    pprof.StartCPUProfile(f)
    defer pprof.StopCPUProfile()

    for i := 0; i < 40; i++ {
        a := fibonacci(i)
        fmt.Println(a)
    }

}

func fibonacci(n int) (res int) {
    if n <= 1 {
        res = 1
    } else {
        res = fibonacci(n-1) + fibonacci(n-2)
    }
    return
}

我使用这段代码生成了cpu.prof文件 用工具进行分析的时候发现Total samples一直是0。使用top命令也没有分析数据。是我的写法还是理解有什么不对?还请各位前辈多指点一下。

已邀请:

singlethread - 5年老菜鸟,可以用任意语言写hello world,喜欢go

赞同来自:

额,这是我的输出

singlethread@Earth:~/test/src/prof$ pprof -top cpu.prof 
Local symbolization failed for main: stat /tmp/go-build921460045/command-line-arguments/_obj/exe/main: no such file or directory
Some binary filenames not available. Symbolization may be incomplete.
Try setting PPROF_BINARY_PATH to the search path for local binaries.
File: main
Type: cpu
Time: Nov 15, 2017 at 9:38am (AWST)
Duration: 1.10s, Total samples = 970ms (88.03%)
Showing nodes accounting for 970ms, 100% of 970ms total
      flat  flat%   sum%        cum   cum%
     970ms   100%   100%      970ms   100%  main.fibonacci
         0     0%   100%      970ms   100%  main.main
         0     0%   100%      970ms   100%  runtime.main

要回复问题请先登录注册