Go的CPU分析器缺乏函数调用信息。

huangapple go评论91阅读模式
英文:

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 (
	&quot;fmt&quot;
	&quot;os&quot;
	&quot;runtime/pprof&quot;
)

func do_something(prev string, limit int) {
	if len(prev) &lt; limit {
		do_something(prev+&quot;a&quot;, limit)
	}
}

func main() {
	f, err := os.Create(&quot;./prof&quot;)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()

	do_something(&quot;&quot;, 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

huangapple
  • 本文由 发表于 2016年7月20日 01:39:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/38465119.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定