如何可视化堆转储(heapdump)?

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

How to visualize heapdump?

问题

我们使用golang开发了一个服务器,它可以接收并处理并发请求(创建大对象-树),然后发送回复。但是这些对象没有被垃圾回收。因此,我决定分析内存中存在的对象。首先,我编写了一个简单的程序。

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"runtime/debug"
)

func main() {
	var i_am_a int = 10
	_ = i_am_a
	func() {
		f, err := os.Create("dump")
		defer f.Close()
		if err != nil {
			panic(err)
		}
		debug.WriteHeapDump(f.Fd())
	}()

	b, err := ioutil.ReadFile("dump")
	if err != nil {
		panic(err)
	}
	fmt.Print(string(b))
}

但是我无法理解这个表示(https://github.com/golang/go/wiki/heapdump13 - 这个没有帮助)。我想要的是从内存(大对象)追溯到保存对象根地址的位置(go应用代码中的变量)。这样我就可以释放引用,让垃圾回收器在其循环中收集它。是否有最新的工具可以可视化堆转储?或者是否有更好的解决这个问题的方法?

英文:

We have developed a server using golang which will receive concurrent request and process the request(creates big object - a tree) and then send back reply. But the objects are not garbage collected. So I decided to analyze the objects that live in the memory. To start with, I wrote a simple program

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"runtime/debug"
)

func main() {
	var i_am_a int = 10
	_ = i_am_a
	func() {
		f, err := os.Create("dump")
		defer f.Close()
		if err != nil {
			panic(err)
		}
		debug.WriteHeapDump(f.Fd())
	}()

	b, err := ioutil.ReadFile("dump")
	if err != nil {
		panic(err)
	}
	fmt.Print(string(b))

}

But I couldn't understand the representaion(https://github.com/golang/go/wiki/heapdump13 - this didn't help). All I wanted is to trace back from the memory(big object) to the place(variable in go app code) which holds the root address of the object. So that I can release the reference and let GC to collect it in it's cycle. Is there a latest tool to visualize heapdump? or Is there a better approach to this problem?

答案1

得分: 3

目前,对于你的问题还没有完整的解决方案。最新的堆转储格式解释了一些之前可用的信息不再被运行时跟踪。

Go Issue 16410中提供了很多关于正在进行的工作的详细信息。

一个正在进行中的工具可能会有所帮助,它就是goheapdump

英文:

There is, currently, no complete solution to your problem. The newest heap dump format explains that some information previously available is no longer tracked by the runtime.

Go Issue 16410 has lots of details and information on work in progress.

One tool - a work in progress - that may help is goheapdump

答案2

得分: -4

你可以使用net/pprof包。只需按照https://blog.golang.org/profiling-go-programs中的步骤来转储堆和CPU分析数据。

然后,你可以使用go tool pprof binary dumpfile来分析一个转储文件。在交互式分析工具中输入web,你可以在Web浏览器中看到调用图。

英文:

You can use net/pprof package. Just follow the steps in https://blog.golang.org/profiling-go-programs to dump heap/cpu profile.

And you can use go tool pprof binary dumpfile to analyse a dumpfile. Type web in the interactive analysis tool, you can see the call graph in your web browser.

huangapple
  • 本文由 发表于 2017年1月9日 15:13:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/41542775.html
匿名

发表评论

匿名网友

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

确定