Collect only the data as we need it
[pstop.git] / state / state.go
index 824d9fb..4df68d2 100644 (file)
@@ -75,20 +75,35 @@ 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.Collect()
+       // collect all initial values on startup / reset
+       state.fsbi.Collect(state.dbh)
+       state.tlwsbt.Collect(state.dbh)
+       state.tiwsbt.Collect(state.dbh)
+
        state.UpdateInitialValues()
 }
 
 func (state *State) UpdateInitialValues() {
+       start := time.Now()
        state.fsbi.UpdateInitialValues()
        state.tlwsbt.UpdateInitialValues()
        state.tiwsbt.UpdateInitialValues()
+       lib.Logger.Println("state.UpdateInitialValues() took", time.Duration(time.Since(start)).String())
 }
 
+// Only collect the data we are looking at.
 func (state *State) Collect() {
-       state.fsbi.Collect(state.dbh)
-       state.tlwsbt.Collect(state.dbh)
-       state.tiwsbt.Collect(state.dbh)
+       start := time.Now()
+
+       switch state.show {
+       case showLatency, showOps:
+               state.tiwsbt.Collect(state.dbh)
+       case showIO:
+               state.fsbi.Collect(state.dbh)
+       case showLocks:
+               state.tlwsbt.Collect(state.dbh)
+       }
+       lib.Logger.Println("state.Collect() took", time.Duration(time.Since(start)).String())
 }
 
 func (state State) MySQLVersion() string {