go tool pprof list -- 漏掉的源代码行

问题描述

list 中使用 go tool pprof 命令有时会丢失一些代码行。

函数开头:

func SlowSearch(out io.Writer) {

    file,err := os.Open(filePath)
    if err != nil {
        panic(err)
    }

    fileContents,err := IoUtil.ReadAll(file)
    if err != nil {
        panic(err)
    }

    r := regexp.MustCompile("@")
    seenbrowsers := []string{}
    uniquebrowsers := 0
    foundUsers := ""

这正常工作:

go test -bench . -cpuprofile bench_cpu.pprof
go tool pprof .\hw3.test.exe .\bench_cpu.pprof

结果:

(pprof) list SlowSearch
Total: 5.12s
ROUTINE ======================== hw3.SlowSearch in C:\Egor\MyProject\learn_mail.ru\3\99_hw\common.go
         0      910ms (flat,cum) 17.77% of Total
         .          .     18:   file,err := os.Open(filePath)
         .          .     19:   if err != nil {
         .          .     20:           panic(err)
         .          .     21:   }

仅缺少函数定义行。


效果更差:

go test -bench . -benchmem -cpuprofile bench_cpu.pprof -memprofile bench_mem.pprof -memprofilerate 1

结果:

(pprof) list SlowSearch
Total: 4.40s
ROUTINE ======================== hw3.SlowSearch in C:\Egor\MyProject\learn_mail.ru\3\99_hw\common.go
         0      1.67s (flat,cum) 37.95% of Total
         .          .     28:   r := regexp.MustCompile("@")
         .          .     29:   seenbrowsers := []string{}
         .          .     30:   uniquebrowsers := 0
         .          .     31:   foundUsers := ""

遗漏了更多的源代码行。


Golang 版本:

go version go1.16.3 windows/amd64

我尝试删除所有二进制文件并重建 - 结果相同。 命令 listweblist、带有参数 -http 的 Web 界面给出相同的结果,但在源代码中遗漏了相同的行。


如何返回丢失的函数行?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)