分析Go程序

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

Profiling go programs

问题

我试图对我的Go库进行性能分析,但是我卡在了以下输出上:

(pprof) top10
总共:884个样本
     884 100.0% 100.0%      884 100.0% runtime.mach_semaphore_wait
       0   0.0% 100.0%      884 100.0% System

这并没有提供太多帮助。我的库读取一个zip文件并解析其中的XML文件(xlsx格式)。当我将性能分析函数移到库的最底层(实际的XML解码位置)时,输出结果也没有太大改善:

(pprof) top10   
总共:884个样本
     884 100.0% 100.0%      884 100.0% fmt.(*fmt).formatFloat
       0   0.0% 100.0%      884 100.0% runtime.schedtrace

我知道这是一个非常模糊的问题,但也许有一些有用的提示,而不必提供整个源代码?

我从golang博客文章中获取了性能分析器的调用,并在构建main.go后使用go tool pprof main profile调用性能分析器。

f, err := os.Create("profile")
if err != nil {
	log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
    ... 这里是我的源代码
英文:

I try to profile my go library, but I am stuck with the following output:

(pprof) top10
Total: 884 samples
     884 100.0% 100.0%      884 100.0% runtime.mach_semaphore_wait
       0   0.0% 100.0%      884 100.0% System

Which is not really helpful. My library reads a zip-file and parses the enclosed XML files (xlsx). When I move the profiling functions inside the lowest part of my library (where the actual xml decoding takes place), the output is not much 'better':

(pprof) top10   
Total: 884 samples
     884 100.0% 100.0%      884 100.0% fmt.(*fmt).formatFloat
       0   0.0% 100.0%      884 100.0% runtime.schedtrace

I know that this is a very vague question, but perhaps there are some helpful hints without having to provide the whole source code?

I have taken the profiler call from the golang blog entry and call the profiler with go tool pprof main profile after building main.go.

f, err := os.Create("profile")
if err != nil {
	log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
    ... my source code here

答案1

得分: 6

这是一个已知的问题,即在Mac OS X上无法进行性能分析。https://code.google.com/p/go/issues/detail?id=6047

这个问题出现在Mac OS X内核中,Russ Cox有一个修补程序,详细描述在这里:http://godoc.org/code.google.com/p/rsc/cmd/pprof_mac_fix,但是这个修补程序会对你的机器造成严重影响,因此有着严重的警告。特别是,在Mavericks下已知存在与修补程序相关的问题。

英文:

It's a known bug that profiling doesn't work on Mac OS X. https://code.google.com/p/go/issues/detail?id=6047

The bug is in the Mac OS X kernel, and Russ Cox has a patch, described here: http://godoc.org/code.google.com/p/rsc/cmd/pprof_mac_fix , but that comes with dire warnings about screwing up your machine. In particular, there's known problems with the patch under Mavericks.

huangapple
  • 本文由 发表于 2014年6月2日 21:03:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/23995229.html
匿名

发表评论

匿名网友

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

确定