From a67f18670b644d854db829e71d125ae191f1dfdf Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Wed, 14 Jan 2015 23:29:08 +0100 Subject: [PATCH] Stages now seems to work ok --- .../private.go | 33 ++++++++++++++-------- .../public.go | 14 +++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/p_s/events_stages_summary_global_by_event_name/private.go b/p_s/events_stages_summary_global_by_event_name/private.go index 51028b6..5c3c090 100644 --- a/p_s/events_stages_summary_global_by_event_name/private.go +++ b/p_s/events_stages_summary_global_by_event_name/private.go @@ -19,27 +19,29 @@ Create Table: CREATE TABLE `events_stages_summary_global_by_event_name` ( `EVENT_NAME` varchar(128) NOT NULL, `COUNT_STAR` bigint(20) unsigned NOT NULL, `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL, - `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL, - `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL, - `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL + `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL, // not used + `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL, // not used + `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL // not used ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8 1 row in set (0.00 sec) **************************************************************************/ +// one row of data type table_row struct { EVENT_NAME string COUNT_STAR uint64 SUM_TIMER_WAIT uint64 } +// a table of rows type table_rows []table_row +// select the rows into table func select_rows(dbh *sql.DB) table_rows { var t table_rows lib.Logger.Println("events_stages_summary_global_by_event_name.select_rows()") - // we collect all information even if it's mainly empty as we may reference it later sql := "SELECT EVENT_NAME, COUNT_STAR, SUM_TIMER_WAIT FROM events_stages_summary_global_by_event_name WHERE SUM_TIMER_WAIT > 0" rows, err := dbh.Query(sql) @@ -76,6 +78,7 @@ func (t table_rows) needs_refresh(t2 table_rows) bool { return my_totals.SUM_TIMER_WAIT > t2_totals.SUM_TIMER_WAIT } +// generate the totals of a table func (t table_rows) totals() table_row { var totals table_row totals.EVENT_NAME = "Totals" @@ -87,18 +90,25 @@ func (t table_rows) totals() table_row { return totals } -func (this *table_row) name() string { - return this.EVENT_NAME +// return the stage name, removing any leading stage/sql/ +func (r *table_row) name() string { + if len(r.EVENT_NAME) > 10 && r.EVENT_NAME[0:10] == "stage/sql/" { + return r.EVENT_NAME[10:] + } else { + return r.EVENT_NAME + } } +// stage name limited to 40 characters func (r *table_row) pretty_name() string { s := r.name() - if len(s) > 30 { - s = s[:29] + if len(s) > 40 { + s = s[:39] } return s } +// add the values of one row to another one func (this *table_row) add(other table_row) { this.SUM_TIMER_WAIT += other.SUM_TIMER_WAIT this.COUNT_STAR += other.COUNT_STAR @@ -150,8 +160,9 @@ func (this *table_rows) subtract(initial table_rows) { } } +// stage headings func (r *table_row) headings() string { - return fmt.Sprintf("%-30s %10s %6s %6s", "Stage Name", "Latency", "%", "Count") + return fmt.Sprintf("%-40s|%10s %6s %8s|", "Stage Name", "Latency", "%", "Counter") } // generate a printable result @@ -161,7 +172,7 @@ func (r *table_row) row_content(totals table_row) string { name = "" } - return fmt.Sprintf("%-30s|%10s %6s %6s", + return fmt.Sprintf("%-40s|%10s %6s %8s|", name, lib.FormatTime(r.SUM_TIMER_WAIT), lib.FormatPct(lib.MyDivide(r.SUM_TIMER_WAIT, totals.SUM_TIMER_WAIT)), @@ -170,7 +181,7 @@ func (r *table_row) row_content(totals table_row) string { // describe a whole row func (r table_row) String() string { - return fmt.Sprintf("%-30s %10s %10s", + return fmt.Sprintf("%-40s %10s %10s", r.pretty_name(), lib.FormatTime(r.SUM_TIMER_WAIT), lib.FormatAmount(r.COUNT_STAR)) diff --git a/p_s/events_stages_summary_global_by_event_name/public.go b/p_s/events_stages_summary_global_by_event_name/public.go index 39777f3..5cbccd6 100644 --- a/p_s/events_stages_summary_global_by_event_name/public.go +++ b/p_s/events_stages_summary_global_by_event_name/public.go @@ -1,3 +1,4 @@ +// public interface to events_stages_summary_global_by_event_name package events_stages_summary_global_by_event_name import ( @@ -84,10 +85,12 @@ func (t *Object) Collect(dbh *sql.DB) { lib.Logger.Println("Table_io_waits_summary_by_table.Collect() END, took:", time.Duration(time.Since(start)).String()) } +// return the headings of the object func (t *Object) Headings() string { return t.totals.headings() } +// return a slice of strings containing the row content func (t Object) RowContent(max_rows int) []string { rows := make([]string, 0, max_rows) @@ -100,24 +103,34 @@ func (t Object) RowContent(max_rows int) []string { return rows } +// return an empty row func (t Object) EmptyRowContent() string { var e table_row return e.row_content(e) } +// return a row containing the totals func (t Object) TotalRowContent() string { return t.totals.row_content(t.totals) } +// describe the stages func (t Object) Description() string { count := t.count_rows() return fmt.Sprintf("Latency by SQL stage (events_stages_summary_global_by_event_name) %d rows", count) } +// reset the statistics to current values func (t *Object) SyncReferenceValues() { + t.SetNow() + t.initial = make(table_rows, len(t.current)) + copy(t.initial, t.current) + + t.make_results() } +// generate the results and totals and sort data func (t *Object) make_results() { // lib.Logger.Println( "- t.results set from t.current" ) t.results = make(table_rows, len(t.current)) @@ -130,6 +143,7 @@ func (t *Object) make_results() { t.totals = t.results.totals() } +// count the number of rows we have data for func (t Object) count_rows() int { var count int for row := range t.results { -- 2.7.4