diff --git a/cmd/ipfs2/main.go b/cmd/ipfs2/main.go
index <HASH>..<HASH> 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)
+}
feat(ipfs2/main) port mem-profiling from previous main

was added 5 days ago in...

<URL>