diff --git a/control.go b/control.go index 2557650..9848740 100644 --- a/control.go +++ b/control.go @@ -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") } diff --git a/main.go b/main.go index ac2b931..35bc940 100644 --- a/main.go +++ b/main.go @@ -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")