英文:
Go CPU profile is lacking function call information
问题
我一直在尝试深入了解Go(golang)性能分析,基于像https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs这样的文章。
然而,在实际的分析程序中,生成的CPU分析文件几乎没有信息。go工具要么告诉我分析文件是空的,要么没有关于任何函数调用的信息。这在OS X和Linux上都发生了。
我生成了一个最小化的示例来说明这种情况 - 我以类似的方式收集分析文件,并在实际程序中遇到了相同的问题。
下面是miniprofile/main.go
的源代码:
package main
import (
"fmt"
"os"
"runtime/pprof"
)
func do_something(prev string, limit int) {
if len(prev) < limit {
do_something(prev+"a", limit)
}
}
func main() {
f, err := os.Create("./prof")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
do_something("", 100000)
}
我期望看到一个CPU分析文件,告诉我几乎所有的时间都花在了对do_something的不同递归调用上。
然而,实际情况是这样的(上面的最小应用程序被称为miniprofile)- 不是很有用:
$ go version
go version go1.6.2 darwin/amd64
$ go install .
$ miniprofile
$ go tool pprof --text prof
1.91s of 1.91s total ( 100%)
flat flat% sum% cum cum%
1.91s 100% 100% 1.91s 100%
我是不是以非常错误的方式做了什么?
英文:
I have been trying to dive in to Go (golang) performance analysis, based on articles like https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs .
However, in the actual profiled programs, the generated CPU profiles have very little information. The go tool either tells that the profile is empty or it has no information about any function calls. This happens on both OS X and Linux.
I generated a minimal example of this situation - I am gathering the profile in a similar manner and facing the same issues in actual programs, too.
Here's the source code for miniprofile/main.go
:
package main
import (
"fmt"
"os"
"runtime/pprof"
)
func do_something(prev string, limit int) {
if len(prev) < limit {
do_something(prev+"a", limit)
}
}
func main() {
f, err := os.Create("./prof")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
do_something("", 100000)
}
I am expecting to see a CPU profile that tells that almost all the time has been spent on different recursive calls to do_something.
However, this happens (the minimal app above is called miniprofile) - not very useful:
$ go version
go version go1.6.2 darwin/amd64
$ go install .
$ miniprofile
$ go tool pprof --text prof
1.91s of 1.91s total ( 100%)
flat flat% sum% cum cum%
1.91s 100% 100% 1.91s 100%
Am I doing something in a horribly wrong way?
答案1
得分: 1
你忘记了向pprof传递二进制参数:
go tool pprof --text miniprofile prof
英文:
You're missing the binary argument to pprof:
go tool pprof --text miniprofile prof
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论