Added a memprofile dump flag and mechanism

This commit is contained in:
Stephen McQuay 2014-03-08 15:29:08 -08:00
parent 6fd4138740
commit a932d24683
2 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"runtime/pprof"
"strings"
)
@ -202,6 +203,16 @@ func killServer(w http.ResponseWriter, req *http.Request) {
pprof.StopCPUProfile()
log.Print("stopped cpu profile")
}
if *mprofile != "" {
log.Print("trying to dump memory profile")
f, err := os.Create(*mprofile)
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()
log.Print("stopped memory profile dump")
}
log.Fatal("shit got fucked up")
}

View File

@ -15,7 +15,8 @@ import (
var addr = flag.String("addr", ":8666", "http service address")
var profile = flag.String("pprof", "", "if specified will run with pprof")
var netprofile = flag.Bool("netprof", false, "if specified will run with net/http/pprof")
var mprofile = flag.String("mprof", "", "if specified will dump a memory profile")
var netprofile = flag.Bool("netprof", false, "if specified will run with net/http/pprof on :8667")
var verbose = flag.Bool("verbose", false, "")
var config = flag.String("config", "~/.config/hackerbots/config.json", "location of config file")