17657: Allow ssh port forwarding to container ports.
[arvados.git] / lib / mount / command.go
index da3f97b467b6302f8e6e5263886ea71d3ccb15d8..e92af24075f1b824c741f6f35b4de53e2346b7ed 100644 (file)
@@ -8,6 +8,9 @@ import (
        "flag"
        "io"
        "log"
+       "net/http"
+       // pprof is only imported to register its HTTP handlers
+       _ "net/http/pprof"
        "os"
 
        "git.arvados.org/arvados.git/sdk/go/arvados"
@@ -24,7 +27,7 @@ type cmd struct {
        // not be called more than once, or when ready is already
        // closed.
        ready chan struct{}
-       // It is safe to call Unmount ounly after ready has been
+       // It is safe to call Unmount only after ready has been
        // closed.
        Unmount func() (ok bool)
 }
@@ -39,6 +42,7 @@ func (c *cmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, st
        ro := flags.Bool("ro", false, "read-only")
        experimental := flags.Bool("experimental", false, "acknowledge this is an experimental command, and should not be used in production (required)")
        blockCache := flags.Int("block-cache", 4, "read cache size (number of 64MiB blocks)")
+       pprof := flags.String("pprof", "", "serve Go profile data at `[addr]:port`")
        err := flags.Parse(args)
        if err != nil {
                logger.Print(err)
@@ -48,6 +52,11 @@ func (c *cmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, st
                logger.Printf("error: experimental command %q used without --experimental flag", prog)
                return 2
        }
+       if *pprof != "" {
+               go func() {
+                       log.Println(http.ListenAndServe(*pprof, nil))
+               }()
+       }
 
        client := arvados.NewClientFromEnv()
        ac, err := arvadosclient.New(client)