From 5a5305422c2a4651e28e0bb29b778d77f7cf05f5 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Sat, 15 Nov 2014 12:25:59 +0100 Subject: [PATCH] Isolate display from collection of data --- BUGS | 4 ++-- main.go | 5 +++++ state/state.go | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/BUGS b/BUGS index a42c40a..316c001 100644 --- a/BUGS +++ b/BUGS @@ -7,5 +7,5 @@ See also NEW_FEATURES for things which probably need adding soon. by looking at the pattern defined in the server. Currently I'm using hard-coded stuff which matches personal usage. -2. Only tested on MySQL 5.6. It should be possible to make this work -on MySQL 5.7 and also MariaDB 10.0 but that has not been tested yet. +2. Only tested on MySQL 5.6 and MariaDB 10.0. It should be possible +to make this work on MySQL 5.7 but that has not been tested yet. diff --git a/main.go b/main.go index b7a6692..5a7e87b 100644 --- a/main.go +++ b/main.go @@ -110,6 +110,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 +121,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 +140,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) } diff --git a/state/state.go b/state/state.go index 03d9938..824d9fb 100644 --- a/state/state.go +++ b/state/state.go @@ -75,14 +75,20 @@ func (state *State) Setup(dbh *sql.DB) { // do a fresh collection of data and then update the initial values based on that. func (state *State) ResetDBStatistics() { - state.fsbi.Collect(state.dbh) - state.fsbi.UpdateInitialValues() + state.Collect() + state.UpdateInitialValues() +} - state.tlwsbt.Collect(state.dbh) +func (state *State) UpdateInitialValues() { + state.fsbi.UpdateInitialValues() state.tlwsbt.UpdateInitialValues() + state.tiwsbt.UpdateInitialValues() +} +func (state *State) Collect() { + state.fsbi.Collect(state.dbh) + state.tlwsbt.Collect(state.dbh) state.tiwsbt.Collect(state.dbh) - state.tiwsbt.UpdateInitialValues() } func (state State) MySQLVersion() string { @@ -198,8 +204,6 @@ func (state State) displayLine1() { } func (state *State) displayOpsOrLatency() { - state.tiwsbt.Collect(state.dbh) - state.screen.PrintAt(0, 2, state.tiwsbt.Headings()) max_rows := state.screen.Height() - 3 @@ -224,8 +228,6 @@ func (state *State) displayOpsOrLatency() { // show actual I/O latency values func (state State) displayIO() { - state.fsbi.Collect(state.dbh) - state.screen.PrintAt(0, 2, state.fsbi.Headings()) // print out the data @@ -250,8 +252,6 @@ func (state State) displayIO() { } func (state *State) displayLocks() { - state.tlwsbt.Collect(state.dbh) - state.screen.PrintAt(0, 2, state.tlwsbt.Headings()) // print out the data -- 2.7.4