flags := flag.NewFlagSet("", flag.ContinueOnError)
flags.SetOutput(stderr)
pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
+ pprofdir := flags.String("pprof-dir", "", "write Go profile data to `directory` periodically")
runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
projectUUID := flags.String("project", "", "project `UUID` for output data")
priority := flags.Int("priority", 500, "container request priority")
log.Println(http.ListenAndServe(*pprof, nil))
}()
}
+ if *pprofdir != "" {
+ go writeProfilesPeriodically(*pprofdir)
+ }
if !*runlocal {
if *outputFilename != "-" {
*outputBed = "/mnt/output/" + *outputBed
}
runner.Args = []string{"export", "-local=true",
+ "-pprof", ":6000",
+ "-pprof-dir", "/mnt/output",
"-ref", *refname,
"-output-format", *outputFormatStr,
"-output-bed", *outputBed,
--- /dev/null
+package lightning
+
+import (
+ "os"
+ "runtime"
+ "runtime/pprof"
+ "time"
+
+ log "github.com/sirupsen/logrus"
+)
+
+func writeProfilesPeriodically(outdir string) {
+ for range time.NewTicker(time.Minute).C {
+ writeMemProfile(outdir)
+ writeCPUProfile(outdir)
+ }
+}
+
+func writeCPUProfile(outdir string) {
+ f, err := os.OpenFile(outdir+"/cpu.prof~", os.O_CREATE|os.O_WRONLY, 0666)
+ if err != nil {
+ log.Print(err)
+ return
+ }
+ defer f.Close()
+ runtime.GC()
+ if err := pprof.StartCPUProfile(f); err != nil {
+ log.Print(err)
+ return
+ }
+ time.Sleep(time.Second)
+ pprof.StopCPUProfile()
+ err = f.Close()
+ if err != nil {
+ log.Print(err)
+ return
+ }
+ err = os.Rename(outdir+"/cpu.prof~", outdir+"/cpu.prof")
+ if err != nil {
+ log.Print(err)
+ }
+ return
+}
+
+func writeMemProfile(outdir string) {
+ f, err := os.OpenFile(outdir+"/mem.prof~", os.O_CREATE|os.O_WRONLY, 0666)
+ if err != nil {
+ log.Print(err)
+ return
+ }
+ defer f.Close()
+ runtime.GC()
+ if err := pprof.WriteHeapProfile(f); err != nil {
+ log.Print(err)
+ return
+ }
+ err = f.Close()
+ if err != nil {
+ log.Print(err)
+ return
+ }
+ err = os.Rename(outdir+"/mem.prof~", outdir+"/mem.prof")
+ if err != nil {
+ log.Print(err)
+ }
+ return
+}