X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=main.go;h=708a77aa0a7e37211d435731dd87844c555d9e97;hb=2e1a0892e2e2240a1f2ab31ff9cacfa9b9243a74;hp=b7a66923b5776ff7f5b6d52c982e2115001d1ab7;hpb=4fced0ba29c6711135bebb24f8a55c2ab6f60dbf;p=pstop.git diff --git a/main.go b/main.go index b7a6692..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) } @@ -110,6 +122,7 @@ func main() { fmt.Println("Caught a signal", sig) done <- struct{}{} case <-ticker.C: + state.Collect() state.Display() case event := <-termboxChan: // switch on event type @@ -120,6 +133,7 @@ func main() { finished = true case termbox.KeyTab: // tab - change display modes state.DisplayNext() + state.Display() } switch event.Ch { case '-': // decrease the interval if > 1 @@ -138,11 +152,14 @@ func main() { finished = true case 't': // toggle between absolute/relative statistics state.SetWantRelativeStats(!state.WantRelativeStats()) + state.Display() case 'z': // reset the statistics to now by taking a query of current values state.ResetDBStatistics() + state.Display() } case termbox.EventResize: // set sizes state.ScreenSetSize(event.Width, event.Height) + state.Display() case termbox.EventError: // quit log.Fatalf("Quitting because of termbox error: \n%s\n", event.Err) }