From: Simon J Mudd Date: Fri, 21 Nov 2014 21:37:27 +0000 (+0100) Subject: Add support for profiling X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=2e1a0892e2e2240a1f2ab31ff9cacfa9b9243a74;p=pstop.git Add support for profiling --- diff --git a/main.go b/main.go index 5a7e87b..708a77a 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "os" "os/signal" + "runtime/pprof" "syscall" "time" @@ -26,6 +27,11 @@ const ( db = "performance_schema" ) +var flag_version = flag.Bool("version", false, "Show the version of "+lib.MyName()) +var flag_debug = flag.Bool("debug", false, "Enabling debug logging") +var flag_help = flag.Bool("help", false, "Provide some help for "+lib.MyName()) +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + func get_db_handle() *sql.DB { var err error var dbh *sql.DB @@ -67,12 +73,18 @@ func usage() { } func main() { - var flag_version = flag.Bool("version", false, "Show the version of "+lib.MyName()) - var flag_debug = flag.Bool("debug", false, "Enabling debug logging") - var flag_help = flag.Bool("help", false, "Provide some help for "+lib.MyName()) flag.Parse() // clean me up + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } + if *flag_debug { lib.Logger.EnableLogging(true) }