@cryptotaxi247 / kubo / commits / 7510ef208

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

TODO add memory profiling to ipfs2

Brian Tiger Chow committed Oct 29, 2014 at 18:23 UTC 7510ef2081e3787e97b815e69a676bd6fc75a9cd
1 file changed +18
cmd/ipfs/ipfs.go
+18
@@ -17,6 +17,8 @@ import (
17 u "github.com/jbenet/go-ipfs/util"
18 )
19
20 +const heapProfile = "ipfs.mprof"
21 +
22 // The IPFS command tree. It is an instance of `commander.Command`.
23 var CmdIpfs = &commander.Command{
24 UsageLine: "ipfs [<flags>] <command> [<args>]",
@@ -117,6 +119,13 @@ func main() {
119 }
120 os.Exit(1)
121 }
122 +
123 + if u.Debug {
124 + err := writeHeapProfileToFile()
125 + if err != nil {
126 + log.Critical(err)
127 + }
128 + }
129 return
130 }
131
@@ -220,3 +229,12 @@ func setupDaemon(confdir string, node *core.IpfsNode) (*daemon.DaemonListener, e
229 go dl.Listen()
230 return dl, nil
231 }
232 +
233 +func writeHeapProfileToFile() error {
234 + mprof, err := os.Create(heapProfile)
235 + if err != nil {
236 + log.Fatal(err)
237 + }
238 + defer mprof.Close()
239 + return pprof.WriteHeapProfile(mprof)
240 +}