X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=main.go;h=545170c83fe9932cd5937e5ef6dcc0269f22cece;hb=6e1a36f58c73ec770b55701bd8ae26d06ef4f8a5;hp=3981b1b3b0280f566028a3c716745c7f53e90775;hpb=8758bf08ad224f97598c0424b7c51db9c80f0642;p=pstop.git diff --git a/main.go b/main.go index 3981b1b..545170c 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Top like progream which collects information from MySQL's +// pstop - Top like progream which collects information from MySQL's // performance_schema database. package main @@ -22,6 +22,7 @@ import ( "github.com/sjmudd/pstop/lib" "github.com/sjmudd/pstop/state" "github.com/sjmudd/pstop/version" + "github.com/sjmudd/pstop/wait_info" ) const ( @@ -150,7 +151,9 @@ func main() { } var state state.State - interval := time.Second + var wi wait_info.WaitInfo + wi.SetWaitInterval(time.Second) + sigChan := make(chan os.Signal, 1) done := make(chan struct{}) defer close(done) @@ -158,8 +161,6 @@ func main() { signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) - ticker := time.NewTicker(interval) // generate a periodic signal - state.Setup(dbh) finished := false @@ -171,8 +172,9 @@ func main() { case sig := <-sigChan: fmt.Println("Caught a signal", sig) done <- struct{}{} - case <-ticker.C: + case <-wi.WaitNextPeriod(): state.Collect() + wi.CollectedNow() state.Display() case event := <-termboxChan: // switch on event type @@ -181,21 +183,20 @@ func main() { switch event.Key { case termbox.KeyCtrlZ, termbox.KeyCtrlC, termbox.KeyEsc: finished = true - case termbox.KeyTab: // tab - change display modes + case termbox.KeyArrowLeft: // left arrow change to previous display mode + state.DisplayPrevious() + state.Display() + case termbox.KeyTab, termbox.KeyArrowRight: // tab or right arrow - change to next display mode state.DisplayNext() state.Display() } switch event.Ch { case '-': // decrease the interval if > 1 - if interval > time.Second { - ticker.Stop() - interval -= time.Second - ticker = time.NewTicker(interval) + if wi.WaitInterval() > time.Second { + wi.SetWaitInterval(wi.WaitInterval() - time.Second) } case '+': // increase interval by creating a new ticker - ticker.Stop() - interval += time.Second - ticker = time.NewTicker(interval) + wi.SetWaitInterval(wi.WaitInterval() + time.Second) case 'h': // help state.SetHelp(!state.Help()) case 'q': // quit @@ -216,6 +217,5 @@ func main() { } } state.Cleanup() - ticker.Stop() lib.Logger.Println("Terminating " + lib.MyName()) }