From 586d58db4a534800775426446503428a629044fe Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Wed, 14 Jan 2015 23:52:02 +0100 Subject: [PATCH] Update setup_instruments to all monitoring of stages --- p_s/setup_instruments/setup_instruments.go | 32 ++++++++++++++++++++++++------ state/state.go | 4 +++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/p_s/setup_instruments/setup_instruments.go b/p_s/setup_instruments/setup_instruments.go index 34c30fe..285c86e 100644 --- a/p_s/setup_instruments/setup_instruments.go +++ b/p_s/setup_instruments/setup_instruments.go @@ -7,6 +7,7 @@ import ( "github.com/sjmudd/pstop/lib" ) +// We only match on the error number // Error 1142: UPDATE command denied to user // Error 1290: The MySQL server is running with the --read-only option so it cannot execute this statement var EXPECTED_UPDATE_ERRORS = []string { "Error 1142", "Error 1290" } @@ -22,14 +23,32 @@ type SetupInstruments struct { rows []setup_instruments_row } +// Change settings to monitor stage/sql/% +func (si *SetupInstruments) EnableStageMonitoring(dbh *sql.DB) { + sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'stage/sql/%' AND ( enabled <> 'YES' OR timed <> 'YES' )" + collecting := "Collecting p_s.setup_instruments stage/sql configuration settings" + updating := "Updating p_s.setup_instruments to allow stage/sql configuration" + + si.ConfigureSetupInstruments(dbh, sql, collecting, updating) +} + // Change settings to monitor wait/synch/mutex/% func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) { - si.rows = make([]setup_instruments_row, 0, 100) - - // populate the rows which are not set sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'wait/synch/mutex/%' AND ( enabled <> 'YES' OR timed <> 'YES' )" + collecting := "Collecting p_s.setup_instruments wait/synch/mutex configuration settings" + updating := "Updating p_s.setup_instruments to allow wait/synch/mutex configuration" - lib.Logger.Println("Collecting p_s.setup_instruments wait/synch/mutex configuration settings") + si.ConfigureSetupInstruments(dbh, sql, collecting, updating) +} + +// generic routine (now) to update some rows in setup instruments +func (si *SetupInstruments) ConfigureSetupInstruments(dbh *sql.DB, sql string, collecting, updating string) { + // setup the old values in case they're not set + if si.rows == nil { + si.rows = make([]setup_instruments_row, 0, 500) + } + + lib.Logger.Println(collecting) rows, err := dbh.Query(sql) if err != nil { @@ -56,7 +75,7 @@ func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) { lib.Logger.Println("- found", count, "rows whose configuration need changing") // update the rows which need to be set - do multiple updates but I don't care - lib.Logger.Println("Updating p_s.setup_instruments to allow wait/synch/mutex configuration") + lib.Logger.Println(updating) count = 0 for i := range si.rows { @@ -84,8 +103,9 @@ func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) { } } + // restore any changed rows back to their original state -func (si *SetupInstruments) Restore(dbh *sql.DB) { +func (si *SetupInstruments) RestoreConfiguration(dbh *sql.DB) { // If the previous update didn't work then don't try to restore if ! si.update_succeeded { lib.Logger.Println("Not restoring p_s.setup_instruments to its original settings as previous UPDATE had failed") diff --git a/state/state.go b/state/state.go index 33a86ea..362ec10 100644 --- a/state/state.go +++ b/state/state.go @@ -63,6 +63,8 @@ func (state *State) Setup(dbh *sql.DB) { state.screen.Initialise() state.setup_instruments.EnableMutexMonitoring(dbh) + state.setup_instruments.EnableStageMonitoring(dbh) + _, variables := lib.SelectAllGlobalVariablesByVariableName(state.dbh) // setup to their initial types/values state.fsbi = fsbi.NewFileSummaryByInstance(variables) @@ -481,7 +483,7 @@ func (state *State) ScreenSetSize(width, height int) { func (state *State) Cleanup() { state.screen.Close() if state.dbh != nil { - state.setup_instruments.Restore(state.dbh) + state.setup_instruments.RestoreConfiguration(state.dbh) _ = state.dbh.Close() } } -- 2.7.4