feat(ipfs2/main) port mem-profiling from previous main
was added 5 days ago in... https://github.com/jbenet/go-ipfs/commit/7510ef2081e3787e97b815e69a676bd6fc75a9cd
Brian Tiger Chow committed
Nov 4, 2014 at 04:16 UTC
96fd88e91634e02fd1f0cbb400368b2424aa925a
1 file changed
+18
cmd/ipfs2/main.go
+18
@@ -22,12 +22,21 @@ import (
22
// log is the command logger
23
var log = u.Logger("cmd/ipfs")
24
25
+const heapProfile = "ipfs.mprof"
26
+
27
func main() {
28
args := os.Args[1:]
29
req, root := createRequest(args)
30
handleOptions(req, root)
31
res := callCommand(req, root)
32
outputResponse(res)
33
+
34
+ if u.Debug {
35
+ err := writeHeapProfileToFile()
36
+ if err != nil {
37
+ log.Critical(err)
38
+ }
39
+ }
40
}
41
42
func createRequest(args []string) (cmds.Request, *cmds.Command) {
@@ -232,3 +241,12 @@ func getConfig(path string) (*config.Config, error) {
241
242
return config.Load(configFile)
243
}
244
+
245
+func writeHeapProfileToFile() error {
246
+ mprof, err := os.Create(heapProfile)
247
+ if err != nil {
248
+ log.Fatal(err)
249
+ }
250
+ defer mprof.Close()
251
+ return pprof.WriteHeapProfile(mprof)
252
+}