X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=performance_schema%2Freplication_workload%2Freplication_workload_row.go;fp=performance_schema%2Freplication_workload%2Freplication_workload_row.go;h=0000000000000000000000000000000000000000;hb=4e7de0a29bb9c5534e68e7d67392288b5028fc5b;hp=caf70a9206d31a47a1459fcd5d10c39c7bac4e9f;hpb=bc0b803e1869e15d6ac1f63aa51c576c84567341;p=pstop.git diff --git a/performance_schema/replication_workload/replication_workload_row.go b/performance_schema/replication_workload/replication_workload_row.go deleted file mode 100644 index caf70a9..0000000 --- a/performance_schema/replication_workload/replication_workload_row.go +++ /dev/null @@ -1,82 +0,0 @@ -package replication_workload - -import ( - "database/sql" - "fmt" - "log" - "sort" - "strings" - - "github.com/sjmudd/pstop/lib" -) - -type replication_workload_row struct { - NAME string - EVENT_NAME string - OBJECT_NAME string - OPERATION string - SUM_TIMER_WAIT int - SUM_SPINS int - SUM_NUMBER_OF_BYTES int -} - -type replication_workload_rows []replication_workload_row - -func select_rep_workload_rows(dbh *sql.DB) replication_workload_rows { - var t replication_workload_rows - - 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" - - rows, err := dbh.Query(sql) - if err != nil { - log.Fatal(err) - } - defer rows.Close() - - for rows.Next() { - var r replication_workload_row - - 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 { - log.Fatal(err) - } - t = append(t, r) - } - if err := rows.Err(); err != nil { - log.Fatal(err) - } - - return t -} - -func (this *replication_workload_row) add(other replication_workload_row) { - this.SUM_TIMER_WAIT += other.SUM_TIMER_WAIT - this.SUM_SPINS += other.SUM_SPINS - this.SUM_NUMBER_OF_BYTES += other.SUM_NUMBER_OF_BYTES -} - -func (this *replication_workload_row) subtract(other replication_workload_row) { - this.SUM_TIMER_WAIT -= other.SUM_TIMER_WAIT - this.SUM_SPINS -= other.SUM_SPINS - this.SUM_NUMBER_OF_BYTES -= other.SUM_NUMBER_OF_BYTES -} - -func (t replication_workload_rows) Len() int { return len(t) } -func (t replication_workload_rows) Swap(i, j int) { t[i], t[j] = t[j], t[i] } -// may need to adjust ordering here.!!! -func (t replication_workload_rows) Less(i, j int) bool { - return t[i].SUM_TIMER_WAIT > t[j].SUM_TIMER_WAIT -} - -func (t *replication_workload_rows) sort() { - sort.Sort(t) -} - -// if the data in t2 is "newer", "has more values" than t then it needs refreshing. -// check this by comparing totals. -func (t replication_workload_rows) needs_refresh(t2 replication_workload_rows) bool { - my_totals := t.totals() - t2_totals := t2.totals() - - return my_totals.SUM_TIMER_WAIT > t2_totals.SUM_TIMER_WAIT -} -