1 package replication_workload
10 "github.com/sjmudd/pstop/lib"
13 type replication_workload_row struct {
20 SUM_NUMBER_OF_BYTES int
23 type replication_workload_rows []replication_workload_row
25 func select_rep_workload_rows(dbh *sql.DB) replication_workload_rows {
26 var t replication_workload_rows
28 sql := "SELECT t.NAME, ewc.EVENT_NAME, ewc.OBJECT_NAME, ewc.OPERATION, SUM(ewc.TIMER_WAIT) AS SUM_TIMER_WAIT, SUM(ewc.SPINS) AS SUM_SPINS, SUM(ewc.NUMBER_OF_BYTES) AS SUM_NUMBER_OF_BYTES, FROM events_waits_history ewc JOIN threads t ON (t.THREAD_ID = ewc.thread_id) WHERE t.NAME LIKE '%slave_sql%' GROUP BY t.NAME, ewc.EVENT_NAME, ewc.OBJECT_NAME, ewc.OPERATION"
30 rows, err := dbh.Query(sql)
37 var r replication_workload_row
39 if err := rows.Scan(&r.NAME, &r.EVENT_NAME, &r.OBJECT_NAME, &r.OPERATION, &r.SUM_TIMER_WAIT, &r.SUM_SPINS, &r.SUM_NUMBER_OF_BYTES); err != nil {
44 if err := rows.Err(); err != nil {
51 func (this *replication_workload_row) add(other replication_workload_row) {
52 this.SUM_TIMER_WAIT += other.SUM_TIMER_WAIT
53 this.SUM_SPINS += other.SUM_SPINS
54 this.SUM_NUMBER_OF_BYTES += other.SUM_NUMBER_OF_BYTES
57 func (this *replication_workload_row) subtract(other replication_workload_row) {
58 this.SUM_TIMER_WAIT -= other.SUM_TIMER_WAIT
59 this.SUM_SPINS -= other.SUM_SPINS
60 this.SUM_NUMBER_OF_BYTES -= other.SUM_NUMBER_OF_BYTES
63 func (t replication_workload_rows) Len() int { return len(t) }
64 func (t replication_workload_rows) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
65 // may need to adjust ordering here.!!!
66 func (t replication_workload_rows) Less(i, j int) bool {
67 return t[i].SUM_TIMER_WAIT > t[j].SUM_TIMER_WAIT
70 func (t *replication_workload_rows) sort() {
74 // if the data in t2 is "newer", "has more values" than t then it needs refreshing.
75 // check this by comparing totals.
76 func (t replication_workload_rows) needs_refresh(t2 replication_workload_rows) bool {
77 my_totals := t.totals()
78 t2_totals := t2.totals()
80 return my_totals.SUM_TIMER_WAIT > t2_totals.SUM_TIMER_WAIT