How to visualize heapdump?

风格不统一 提交于 2019-12-10 16:35:41

问题


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:


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:


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.



来源:https://stackoverflow.com/questions/41542775/how-to-visualize-heapdump

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!