From 7a83b8c7acba48f12c42dfb201bdfe3276173f44 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Thu, 15 Jan 2015 00:05:08 +0100 Subject: [PATCH] rename files/objects to simplify a bit --- ...io_waits_summary_by_table_row.go => private.go} | 50 +++++++------- ...able_io_waits_summary_by_table.go => public.go} | 78 +++++++++++----------- state/state.go | 2 +- 3 files changed, 65 insertions(+), 65 deletions(-) rename p_s/table_io_waits_summary_by_table/{table_io_waits_summary_by_table_row.go => private.go} (79%) rename p_s/table_io_waits_summary_by_table/{table_io_waits_summary_by_table.go => public.go} (55%) diff --git a/p_s/table_io_waits_summary_by_table/table_io_waits_summary_by_table_row.go b/p_s/table_io_waits_summary_by_table/private.go similarity index 79% rename from p_s/table_io_waits_summary_by_table/table_io_waits_summary_by_table_row.go rename to p_s/table_io_waits_summary_by_table/private.go index 5d52b60..92195e1 100644 --- a/p_s/table_io_waits_summary_by_table/table_io_waits_summary_by_table_row.go +++ b/p_s/table_io_waits_summary_by_table/private.go @@ -13,7 +13,7 @@ import ( ) // a row from performance_schema.table_io_waits_summary_by_table -type table_io_waits_summary_by_table_row struct { +type table_row struct { // Note: upper case names to match the performance_schema column names // This type is _not_ exported. @@ -37,10 +37,10 @@ type table_io_waits_summary_by_table_row struct { COUNT_UPDATE uint64 COUNT_DELETE uint64 } -type table_io_waits_summary_by_table_rows []table_io_waits_summary_by_table_row +type table_rows []table_row // // return the table name from the columns as '.' -func (r *table_io_waits_summary_by_table_row) name() string { +func (r *table_row) name() string { var n string if len(r.OBJECT_SCHEMA) > 0 { n += r.OBJECT_SCHEMA @@ -57,7 +57,7 @@ func (r *table_io_waits_summary_by_table_row) name() string { return n } -func (r *table_io_waits_summary_by_table_row) pretty_name() string { +func (r *table_row) pretty_name() string { s := r.name() if len(s) > 30 { s = s[:29] @@ -65,15 +65,15 @@ func (r *table_io_waits_summary_by_table_row) pretty_name() string { return s } -func (r *table_io_waits_summary_by_table_row) latency_headings() string { +func (r *table_row) latency_headings() string { return fmt.Sprintf("%-30s %10s %6s|%6s %6s %6s %6s", "Table Name", "Latency", "%", "Fetch", "Insert", "Update", "Delete") } -func (r *table_io_waits_summary_by_table_row) ops_headings() string { +func (r *table_row) ops_headings() string { return fmt.Sprintf("%-30s %10s %6s|%6s %6s %6s %6s", "Table Name", "Ops", "%", "Fetch", "Insert", "Update", "Delete") } // generate a printable result -func (r *table_io_waits_summary_by_table_row) latency_row_content(totals table_io_waits_summary_by_table_row) string { +func (r *table_row) latency_row_content(totals table_row) string { // assume the data is empty so hide it. name := r.pretty_name() if r.COUNT_STAR == 0 && name != "Totals" { @@ -91,7 +91,7 @@ func (r *table_io_waits_summary_by_table_row) latency_row_content(totals table_i } // generate a printable result for ops -func (r *table_io_waits_summary_by_table_row) ops_row_content(totals table_io_waits_summary_by_table_row) string { +func (r *table_row) ops_row_content(totals table_row) string { // assume the data is empty so hide it. name := r.pretty_name() if r.COUNT_STAR == 0 && name != "Totals" { @@ -108,7 +108,7 @@ func (r *table_io_waits_summary_by_table_row) ops_row_content(totals table_io_wa lib.FormatPct(lib.MyDivide(r.COUNT_DELETE, r.COUNT_STAR))) } -func (this *table_io_waits_summary_by_table_row) add(other table_io_waits_summary_by_table_row) { +func (this *table_row) add(other table_row) { this.SUM_TIMER_WAIT += other.SUM_TIMER_WAIT this.SUM_TIMER_FETCH += other.SUM_TIMER_FETCH this.SUM_TIMER_INSERT += other.SUM_TIMER_INSERT @@ -127,7 +127,7 @@ func (this *table_io_waits_summary_by_table_row) add(other table_io_waits_summar } // subtract the countable values in one row from another -func (this *table_io_waits_summary_by_table_row) subtract(other table_io_waits_summary_by_table_row) { +func (this *table_row) subtract(other table_row) { // check for issues here (we have a bug) and log it // - this situation should not happen so there's a logic bug somewhere else if this.SUM_TIMER_WAIT >= other.SUM_TIMER_WAIT { @@ -147,14 +147,14 @@ func (this *table_io_waits_summary_by_table_row) subtract(other table_io_waits_s this.COUNT_READ -= other.COUNT_READ this.COUNT_WRITE -= other.COUNT_WRITE } else { - lib.Logger.Println("WARNING: table_io_waits_summary_by_table_row.subtract() - subtraction problem! (not subtracting)") + lib.Logger.Println("WARNING: table_row.subtract() - subtraction problem! (not subtracting)") lib.Logger.Println("this=", this) lib.Logger.Println("other=", other) } } -func (t table_io_waits_summary_by_table_rows) totals() table_io_waits_summary_by_table_row { - var totals table_io_waits_summary_by_table_row +func (t table_rows) totals() table_row { + var totals table_row totals.OBJECT_SCHEMA = "Totals" for i := range t { @@ -164,8 +164,8 @@ func (t table_io_waits_summary_by_table_rows) totals() table_io_waits_summary_by return totals } -func select_tiwsbt_rows(dbh *sql.DB) table_io_waits_summary_by_table_rows { - var t table_io_waits_summary_by_table_rows +func select_rows(dbh *sql.DB) table_rows { + var t table_rows // we collect all information even if it's mainly empty as we may reference it later sql := "SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, SUM_TIMER_WAIT, COUNT_READ, SUM_TIMER_READ, COUNT_WRITE, SUM_TIMER_WRITE, COUNT_FETCH, SUM_TIMER_FETCH, COUNT_INSERT, SUM_TIMER_INSERT, COUNT_UPDATE, SUM_TIMER_UPDATE, COUNT_DELETE, SUM_TIMER_DELETE FROM table_io_waits_summary_by_table WHERE SUM_TIMER_WAIT > 0" @@ -177,7 +177,7 @@ func select_tiwsbt_rows(dbh *sql.DB) table_io_waits_summary_by_table_rows { defer rows.Close() for rows.Next() { - var r table_io_waits_summary_by_table_row + var r table_row if err := rows.Scan( &r.OBJECT_TYPE, &r.OBJECT_SCHEMA, @@ -208,11 +208,11 @@ func select_tiwsbt_rows(dbh *sql.DB) table_io_waits_summary_by_table_rows { return t } -func (t table_io_waits_summary_by_table_rows) Len() int { return len(t) } -func (t table_io_waits_summary_by_table_rows) Swap(i, j int) { t[i], t[j] = t[j], t[i] } +func (t table_rows) Len() int { return len(t) } +func (t table_rows) Swap(i, j int) { t[i], t[j] = t[j], t[i] } // sort by value (descending) but also by "name" (ascending) if the values are the same -func (t table_io_waits_summary_by_table_rows) Less(i, j int) bool { +func (t table_rows) Less(i, j int) bool { return (t[i].SUM_TIMER_WAIT > t[j].SUM_TIMER_WAIT) || ((t[i].SUM_TIMER_WAIT == t[j].SUM_TIMER_WAIT) && (t[i].OBJECT_SCHEMA < t[j].OBJECT_SCHEMA) && @@ -220,7 +220,7 @@ func (t table_io_waits_summary_by_table_rows) Less(i, j int) bool { } // for sorting -type ByOps table_io_waits_summary_by_table_rows +type ByOps table_rows func (t ByOps) Len() int { return len(t) } func (t ByOps) Swap(i, j int) { t[i], t[j] = t[j], t[i] } @@ -231,7 +231,7 @@ func (t ByOps) Less(i, j int) bool { (t[i].OBJECT_NAME < t[j].OBJECT_NAME)) } -func (t table_io_waits_summary_by_table_rows) Sort(want_latency bool) { +func (t table_rows) Sort(want_latency bool) { if want_latency { sort.Sort(t) } else { @@ -241,7 +241,7 @@ func (t table_io_waits_summary_by_table_rows) Sort(want_latency bool) { // remove the initial values from those rows where there's a match // - if we find a row we can't match ignore it -func (this *table_io_waits_summary_by_table_rows) subtract(initial table_io_waits_summary_by_table_rows) { +func (this *table_rows) subtract(initial table_rows) { initial_by_name := make(map[string]int) // iterate over rows by name @@ -260,7 +260,7 @@ func (this *table_io_waits_summary_by_table_rows) subtract(initial table_io_wait // if the data in t2 is "newer", "has more values" than t then it needs refreshing. // check this by comparing totals. -func (t table_io_waits_summary_by_table_rows) needs_refresh(t2 table_io_waits_summary_by_table_rows) bool { +func (t table_rows) needs_refresh(t2 table_rows) bool { my_totals := t.totals() t2_totals := t2.totals() @@ -268,7 +268,7 @@ func (t table_io_waits_summary_by_table_rows) needs_refresh(t2 table_io_waits_su } // describe a whole row -func (r table_io_waits_summary_by_table_row) String() string { +func (r table_row) String() string { return fmt.Sprintf("%-30s|%10s %10s %10s %10s %10s|%10s %10s|%10s %10s %10s %10s %10s|%10s %10s", r.pretty_name(), lib.FormatTime(r.SUM_TIMER_WAIT), @@ -291,7 +291,7 @@ func (r table_io_waits_summary_by_table_row) String() string { } // describe a whole table -func (t table_io_waits_summary_by_table_rows) String() string { +func (t table_rows) String() string { s := make([]string, len(t)) for i := range t { diff --git a/p_s/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go b/p_s/table_io_waits_summary_by_table/public.go similarity index 55% rename from p_s/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go rename to p_s/table_io_waits_summary_by_table/public.go index 00baecc..c125211 100644 --- a/p_s/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go +++ b/p_s/table_io_waits_summary_by_table/public.go @@ -14,43 +14,43 @@ import ( ) // a table of rows -type Table_io_waits_summary_by_table struct { +type Object struct { p_s.RelativeStats p_s.InitialTime want_latency bool - initial table_io_waits_summary_by_table_rows // initial data for relative values - current table_io_waits_summary_by_table_rows // last loaded values - results table_io_waits_summary_by_table_rows // results (maybe with subtraction) - totals table_io_waits_summary_by_table_row // totals of results + initial table_rows // initial data for relative values + current table_rows // last loaded values + results table_rows // results (maybe with subtraction) + totals table_row // totals of results } -func (t *Table_io_waits_summary_by_table) SetWantsLatency(want_latency bool) { +func (t *Object) SetWantsLatency(want_latency bool) { t.want_latency = want_latency } -func (t Table_io_waits_summary_by_table) WantsLatency() bool { +func (t Object) WantsLatency() bool { return t.want_latency } // Collect() collects data from the db, updating initial // values if needed, and then subtracting initial values if we want // relative values, after which it stores totals. -func (t *Table_io_waits_summary_by_table) Collect(dbh *sql.DB) { +func (t *Object) Collect(dbh *sql.DB) { start := time.Now() - // lib.Logger.Println("Table_io_waits_summary_by_table.Collect() BEGIN") - t.current = select_tiwsbt_rows(dbh) + // lib.Logger.Println("Object.Collect() BEGIN") + t.current = select_rows(dbh) lib.Logger.Println("t.current collected", len(t.current), "row(s) from SELECT") if len(t.initial) == 0 && len(t.current) > 0 { lib.Logger.Println("t.initial: copying from t.current (initial setup)") - t.initial = make(table_io_waits_summary_by_table_rows, len(t.current)) + t.initial = make(table_rows, len(t.current)) copy(t.initial, t.current) } // check for reload initial characteristics if t.initial.needs_refresh(t.current) { lib.Logger.Println("t.initial: copying from t.current (data needs refreshing)") - t.initial = make(table_io_waits_summary_by_table_rows, len(t.current)) + t.initial = make(table_rows, len(t.current)) copy(t.initial, t.current) } @@ -62,12 +62,12 @@ func (t *Table_io_waits_summary_by_table) Collect(dbh *sql.DB) { lib.Logger.Println("t.current.totals():", t.current.totals()) // lib.Logger.Println("t.results:", t.results) // lib.Logger.Println("t.totals:", t.totals) - lib.Logger.Println("Table_io_waits_summary_by_table.Collect() END, took:", time.Duration(time.Since(start)).String()) + lib.Logger.Println("Object.Collect() END, took:", time.Duration(time.Since(start)).String()) } -func (t *Table_io_waits_summary_by_table) make_results() { +func (t *Object) make_results() { // lib.Logger.Println( "- t.results set from t.current" ) - t.results = make(table_io_waits_summary_by_table_rows, len(t.current)) + t.results = make(table_rows, len(t.current)) copy(t.results, t.current) if t.WantRelativeStats() { // lib.Logger.Println( "- subtracting t.initial from t.results as WantRelativeStats()" ) @@ -81,19 +81,19 @@ func (t *Table_io_waits_summary_by_table) make_results() { } // reset the statistics to current values -func (t *Table_io_waits_summary_by_table) SyncReferenceValues() { - // lib.Logger.Println( "Table_io_waits_summary_by_table.SyncReferenceValues() BEGIN" ) +func (t *Object) SyncReferenceValues() { + // lib.Logger.Println( "Object.SyncReferenceValues() BEGIN" ) t.SetNow() - t.initial = make(table_io_waits_summary_by_table_rows, len(t.current)) + t.initial = make(table_rows, len(t.current)) copy(t.initial, t.current) t.make_results() - // lib.Logger.Println( "Table_io_waits_summary_by_table.SyncReferenceValues() END" ) + // lib.Logger.Println( "Object.SyncReferenceValues() END" ) } -func (t *Table_io_waits_summary_by_table) Headings() string { +func (t *Object) Headings() string { if t.want_latency { return t.latencyHeadings() } else { @@ -101,7 +101,7 @@ func (t *Table_io_waits_summary_by_table) Headings() string { } } -func (t Table_io_waits_summary_by_table) RowContent(max_rows int) []string { +func (t Object) RowContent(max_rows int) []string { if t.want_latency { return t.latencyRowContent(max_rows) } else { @@ -109,7 +109,7 @@ func (t Table_io_waits_summary_by_table) RowContent(max_rows int) []string { } } -func (t Table_io_waits_summary_by_table) EmptyRowContent() string { +func (t Object) EmptyRowContent() string { if t.want_latency { return t.emptyLatencyRowContent() } else { @@ -117,7 +117,7 @@ func (t Table_io_waits_summary_by_table) EmptyRowContent() string { } } -func (t Table_io_waits_summary_by_table) TotalRowContent() string { +func (t Object) TotalRowContent() string { if t.want_latency { return t.totalLatencyRowContent() } else { @@ -125,7 +125,7 @@ func (t Table_io_waits_summary_by_table) TotalRowContent() string { } } -func (t Table_io_waits_summary_by_table) Description() string { +func (t Object) Description() string { if t.want_latency { return t.latencyDescription() } else { @@ -133,19 +133,19 @@ func (t Table_io_waits_summary_by_table) Description() string { } } -func (t *Table_io_waits_summary_by_table) latencyHeadings() string { - var r table_io_waits_summary_by_table_row +func (t *Object) latencyHeadings() string { + var r table_row return r.latency_headings() } -func (t *Table_io_waits_summary_by_table) opsHeadings() string { - var r table_io_waits_summary_by_table_row +func (t *Object) opsHeadings() string { + var r table_row return r.ops_headings() } -func (t Table_io_waits_summary_by_table) opsRowContent(max_rows int) []string { +func (t Object) opsRowContent(max_rows int) []string { rows := make([]string, 0, max_rows) for i := range t.results { @@ -157,7 +157,7 @@ func (t Table_io_waits_summary_by_table) opsRowContent(max_rows int) []string { return rows } -func (t Table_io_waits_summary_by_table) latencyRowContent(max_rows int) []string { +func (t Object) latencyRowContent(max_rows int) []string { rows := make([]string, 0, max_rows) for i := range t.results { @@ -169,37 +169,37 @@ func (t Table_io_waits_summary_by_table) latencyRowContent(max_rows int) []strin return rows } -func (t Table_io_waits_summary_by_table) emptyOpsRowContent() string { - var r table_io_waits_summary_by_table_row +func (t Object) emptyOpsRowContent() string { + var r table_row return r.ops_row_content(r) } -func (t Table_io_waits_summary_by_table) emptyLatencyRowContent() string { - var r table_io_waits_summary_by_table_row +func (t Object) emptyLatencyRowContent() string { + var r table_row return r.latency_row_content(r) } -func (t Table_io_waits_summary_by_table) totalOpsRowContent() string { +func (t Object) totalOpsRowContent() string { return t.totals.ops_row_content(t.totals) } -func (t Table_io_waits_summary_by_table) totalLatencyRowContent() string { +func (t Object) totalLatencyRowContent() string { return t.totals.latency_row_content(t.totals) } -func (t Table_io_waits_summary_by_table) latencyDescription() string { +func (t Object) latencyDescription() string { count := t.count_rows() return fmt.Sprintf("Latency by Table Name (table_io_waits_summary_by_table) %d rows", count) } -func (t Table_io_waits_summary_by_table) opsDescription() string { +func (t Object) opsDescription() string { count := t.count_rows() return fmt.Sprintf("Operations by Table Name (table_io_waits_summary_by_table) %d rows", count) } -func (t Table_io_waits_summary_by_table) count_rows() int { +func (t Object) count_rows() int { var count int for row := range t.results { if t.results[row].SUM_TIMER_WAIT > 0 { diff --git a/state/state.go b/state/state.go index d3677c1..4815359 100644 --- a/state/state.go +++ b/state/state.go @@ -43,7 +43,7 @@ type State struct { help bool hostname string fsbi ps_table.Tabler // ufsbi.File_summary_by_instance - tiwsbt tiwsbt.Table_io_waits_summary_by_table + tiwsbt tiwsbt.Object tlwsbt ps_table.Tabler // tlwsbt.Table_lock_waits_summary_by_table ewsgben ps_table.Tabler // ewsgben.Events_waits_summary_global_by_event_name essgben ps_table.Tabler // essgben.Events_stages_summary_global_by_event_name -- 2.7.4