1 package setup_instruments
7 "github.com/sjmudd/pstop/lib"
10 // Error 1142: UPDATE command denied to user
11 const UPDATE_FAILED = "Error 1142"
13 type setup_instruments_row struct {
19 type SetupInstruments struct {
21 rows []setup_instruments_row
24 // Change settings to monitor wait/synch/mutex/%
25 func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) {
26 si.rows = make([]setup_instruments_row, 0, 100)
28 // populate the rows which are not set
29 sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'wait/synch/mutex/%' AND ( enabled <> 'YES' OR timed <> 'YES' )"
31 lib.Logger.Println("Collecting p_s.setup_instruments wait/synch/mutex configuration settings")
33 rows, err := dbh.Query(sql)
43 var r setup_instruments_row
47 &r.TIMED); err != nil {
50 // we collect all information even if it's mainly empty as we may reference it later
51 si.rows = append(si.rows, r)
54 if err := rows.Err(); err != nil {
57 lib.Logger.Println("- found", count, "rows whose configuration need changing")
59 // update the rows which need to be set - do multiple updates but I don't care
60 lib.Logger.Println("Updating p_s.setup_instruments to allow wait/synch/mutex configuration")
63 for i := range si.rows {
64 sql := "UPDATE setup_instruments SET enabled = 'YES', TIMED = 'YES' WHERE NAME = '" + si.rows[i].NAME + "'"
65 if _, err := dbh.Exec(sql); err == nil {
66 si.update_succeeded = true
68 if err.Error()[0:10] != UPDATE_FAILED {
76 lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
79 // restore any changed rows back to their original state
80 func (si *SetupInstruments) Restore(dbh *sql.DB) {
81 // If the previous update didn't work then don't try to restore
82 if ! si.update_succeeded {
83 lib.Logger.Println("Not restoring p_s.setup_instruments to its original settings as previous UPDATE had failed")
86 lib.Logger.Println("Restoring p_s.setup_instruments to its original settings")
89 // update the rows which need to be set - do multiple updates but I don't care
91 for i := range si.rows {
92 sql := "UPDATE setup_instruments SET enabled = '" + si.rows[i].ENABLED + "', TIMED = '" + si.rows[i].TIMED + "' WHERE NAME = '" + si.rows[i].NAME + "'"
93 if _, err := dbh.Exec(sql); err != nil {
98 lib.Logger.Println(count, "rows changed in p_s.setup_instruments")