go - 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
我试图删除所有二进制文件并重建 - 结果相同。命令list
, weblist
, 带有参数的 web 界面-http
给出相同的结果,但在源代码中缺少相同的行。
如何返回丢失的函数行?
解决方案
推荐阅读
- vb.net - 为什么Visual Studio在声明字符串数组列表时会抛出异常
- python - pandas:选择所选行的相邻行
- java - HttpServletResponse,addCookie() 未按预期运行
- python - 在 csv 中正确保存和加载 pandas 数据帧,同时保留 datetimeindex 的频率
- php - 使用 PHP 向表单元素添加属性
- php - 如何使用mysql中的内部连接获取具有空值和填充值的ID
- javascript - TypeError:state.userInfo 在 Jest 测试中不可迭代
- java - Android 如何在 Java 中使用 Kotlin-Coroutine?
- javascript - 数据表多个自定义工具栏元素
- asp.net - 如何在 ASP.NET MVC 中查找 HTML 列表项的索引