Browse Source

Added a memprofile dump flag and mechanism

master
Stephen McQuay 6 years ago
parent
commit
a932d24683
2 changed files with 13 additions and 1 deletions
  1. +11
    -0
      control.go
  2. +2
    -1
      main.go

+ 11
- 0
control.go 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")
}

+ 2
- 1
main.go 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")

Loading…
Cancel
Save