X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=main.go;h=927a15193d539c9a74b063adddcad3836e75aa24;hb=da7982a6dc5c0387d4aadc996cfe5dc53dafbd45;hp=3981b1b3b0280f566028a3c716745c7f53e90775;hpb=8758bf08ad224f97598c0424b7c51db9c80f0642;p=pstop.git diff --git a/main.go b/main.go index 3981b1b..927a151 100644 --- a/main.go +++ b/main.go @@ -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 @@ -187,15 +189,11 @@ func main() { } 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 +214,5 @@ func main() { } } state.Cleanup() - ticker.Stop() lib.Logger.Println("Terminating " + lib.MyName()) }