feat(ipfs2/main) port mem-profiling from previous main

was added 5 days ago in...

7510ef2081
This commit is contained in:
Brian Tiger Chow 2014-11-04 04:16:34 -08:00 committed by Juan Batiz-Benet
parent 46f1afbe08
commit 96fd88e916

View File

@ -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)
}