add profile option

master
Jordan Orelli 10 years ago
parent c7924c9e40
commit 2dedb985de

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"runtime/pprof"
) )
var options struct { var options struct {
@ -13,6 +14,7 @@ var options struct {
password string password string
buffer int buffer int
pipe bool pipe bool
profile string
} }
func usage(status int) { func usage(status int) {
@ -43,6 +45,16 @@ func main() {
} }
} }
if options.profile != "" {
f, err := os.Create(options.profile)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
var infile *os.File var infile *os.File
if options.pipe { if options.pipe {
@ -109,6 +121,7 @@ func init() {
flag.StringVar(&options.password, "a", "", "password") flag.StringVar(&options.password, "a", "", "password")
flag.IntVar(&options.buffer, "buffer", 0, "number of outstanding statements allowed before throttling") flag.IntVar(&options.buffer, "buffer", 0, "number of outstanding statements allowed before throttling")
flag.BoolVar(&options.pipe, "pipe", false, "transfers input from stdin to server") flag.BoolVar(&options.pipe, "pipe", false, "transfers input from stdin to server")
flag.StringVar(&options.profile, "profile", "", "pprof file output for performance debugging")
} }
/* /*

Loading…
Cancel
Save