英文:
How to make go trace show every func call?
问题
我正在尝试使用go tool trace
获取一个调用树,但它只显示前80个函数,并且似乎不支持pprof的标志,如--nodecount
等。我该如何使跟踪显示所有节点?如果trace
不是为此设计的,那么我如何获取完整的调用树,而不考虑函数的执行时间,因为如果pprof运行时间不够长,它可能会错过一些信息。
英文:
I'm trying to get a call tree with go tool trace
, but it shows only top 80 functions and doesn't seem to support pprof's flags like --nodecount
, etc. How can I make the traces show all nodes? And if trace
isn't designed for that, how can I get a full call tree regardless of function's execution time, since pprof can miss it if it doens't run long enough?
答案1
得分: 1
go-callvis可以被检查,因为它提供了一个非常高级的概述,使用调用图和它与包和类型的关系的数据。
通常它运行一个指针分析来构建程序的调用图,并使用数据生成dot格式的输出,可以使用Graphviz工具渲染。高级概述如下。
参考:https://github.com/ofabry/go-callvis
英文:
go-callvis can be checked as it provides a very high level overview of the Go program using data from call graph and its relations with packages and types.
Typically it runs a pointer analysis to construct the call graph of the program and uses the data to generate output in dot format, which can be rendered with Graphviz tools. High level overview shall be as below.
Reference : https://github.com/ofabry/go-callvis
答案2
得分: 0
要显示每个函数调用,您需要向代码中添加插桩。
https://github.com/jbardin/gotrace 可以自动完成这个过程。
files := []string{}
e = filepath.Walk(copysrcdir, func(path string, info os.FileInfo, err error) error {
if mioutil.IsRegularFile(path) && filepath.Ext(path) == ".go" {
files = append(files, path)
}
return nil
})
errs.PanicOnError(e)
var wg sync.WaitGroup
for _, file := range files {
wg.Add(1)
go func(file string) {
defer wg.Done()
log.Println("adding trace to " + file)
cmd := exec.Command("gotrace", "-w", "-timing", "-returns", file)
e = cmd.Run()
errs.PanicOnError(e)
}(file)
}
wg.Wait()
然后,您使用插桩后的二进制文件编译代码。
英文:
to show every function call, you have to add instrumentation to your code.
https://github.com/jbardin/gotrace does this automatically.
files := []string{}
e = filepath.Walk(copysrcdir, func(path string, info os.FileInfo, err error) error {
if mioutil.IsRegularFile(path) && filepath.Ext(path) == ".go" {
files = append(files, path)
}
return nil
})
errs.PanicOnError(e)
var wg sync.WaitGroup
for _, file := range files {
wg.Add(1)
go func(file string) {
defer wg.Done()
log.Println("adding trace to " + file)
cmd := exec.Command("gotrace", "-w", "-timing", "-returns", file)
e = cmd.Run()
errs.PanicOnError(e)
}(file)
}
wg.Wait()
You then compile the code with instrumentation and use that binary.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论