diff --git a/cmd/ipfs2/main.go b/cmd/ipfs2/main.go index e7ea3fa36..d156a3296 100644 --- a/cmd/ipfs2/main.go +++ b/cmd/ipfs2/main.go @@ -22,12 +22,21 @@ import ( // log is the command logger var log = u.Logger("cmd/ipfs") +const heapProfile = "ipfs.mprof" + func main() { args := os.Args[1:] req, root := createRequest(args) handleOptions(req, root) res := callCommand(req, root) outputResponse(res) + + if u.Debug { + err := writeHeapProfileToFile() + if err != nil { + log.Critical(err) + } + } } func createRequest(args []string) (cmds.Request, *cmds.Command) { @@ -232,3 +241,12 @@ func getConfig(path string) (*config.Config, error) { return config.Load(configFile) } + +func writeHeapProfileToFile() error { + mprof, err := os.Create(heapProfile) + if err != nil { + log.Fatal(err) + } + defer mprof.Close() + return pprof.WriteHeapProfile(mprof) +}