提交 7510ef20 作者: Brian Tiger Chow

feat(cmd/ipfs1) add mem profiling in debug mode

TODO add memory profiling to ipfs2
上级 1e847059
...@@ -17,6 +17,8 @@ import ( ...@@ -17,6 +17,8 @@ import (
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
const heapProfile = "ipfs.mprof"
// The IPFS command tree. It is an instance of `commander.Command`. // The IPFS command tree. It is an instance of `commander.Command`.
var CmdIpfs = &commander.Command{ var CmdIpfs = &commander.Command{
UsageLine: "ipfs [<flags>] <command> [<args>]", UsageLine: "ipfs [<flags>] <command> [<args>]",
...@@ -117,6 +119,13 @@ func main() { ...@@ -117,6 +119,13 @@ func main() {
} }
os.Exit(1) os.Exit(1)
} }
if u.Debug {
err := writeHeapProfileToFile()
if err != nil {
log.Critical(err)
}
}
return return
} }
...@@ -220,3 +229,12 @@ func setupDaemon(confdir string, node *core.IpfsNode) (*daemon.DaemonListener, e ...@@ -220,3 +229,12 @@ func setupDaemon(confdir string, node *core.IpfsNode) (*daemon.DaemonListener, e
go dl.Listen() go dl.Listen()
return dl, nil return dl, nil
} }
func writeHeapProfileToFile() error {
mprof, err := os.Create(heapProfile)
if err != nil {
log.Fatal(err)
}
defer mprof.Close()
return pprof.WriteHeapProfile(mprof)
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论