Add -pprof flag.
authorTom Clegg <tom@tomclegg.ca>
Thu, 30 Jan 2020 21:04:02 +0000 (16:04 -0500)
committerTom Clegg <tom@tomclegg.ca>
Thu, 30 Jan 2020 21:04:02 +0000 (16:04 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

gvcf2numpy.go

index 5a0258461883d2b6c627beaf11abd5f20987c235..922e96c3f6cac25311d438fc8c19cb6278b2de5f 100644 (file)
@@ -7,6 +7,8 @@ import (
        "fmt"
        "io"
        "log"
+       "net/http"
+       _ "net/http/pprof"
        "os"
        "os/exec"
        "path/filepath"
@@ -37,6 +39,7 @@ func (cmd *gvcf2numpy) RunCommand(prog string, args []string, stdin io.Reader, s
        flags.SetOutput(stderr)
        flags.StringVar(&cmd.tagLibraryFile, "tag-library", "", "tag library fasta `file`")
        flags.StringVar(&cmd.refFile, "ref", "", "reference fasta `file`")
+       pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
        err = flags.Parse(args)
        if err == flag.ErrHelp {
                err = nil
@@ -52,6 +55,12 @@ func (cmd *gvcf2numpy) RunCommand(prog string, args []string, stdin io.Reader, s
        }
        cmd.output = stdout
 
+       if *pprof != "" {
+               go func() {
+                       log.Println(http.ListenAndServe(*pprof, nil))
+               }()
+       }
+
        infiles, err := listInputFiles(flags.Args())
        if err != nil {
                return 1