From bba62c7e1fa806db54a4bb0e898b1cc5e952b2c8 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Sat, 15 Nov 2014 13:24:48 +0100 Subject: [PATCH] Be able to collect some usage metrics --- BUGS | 8 ++++++++ .../file_summary_by_instance/file_summary_by_instance.go | 5 ++++- .../file_summary_by_instance_row.go | 5 +++++ .../table_io_waits_summary_by_table.go | 4 +++- .../table_lock_waits_summary_by_table.go | 5 ++++- state/state.go | 4 ++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/BUGS b/BUGS index 316c001..2556f67 100644 --- a/BUGS +++ b/BUGS @@ -9,3 +9,11 @@ hard-coded stuff which matches personal usage. 2. Only tested on MySQL 5.6 and MariaDB 10.0. It should be possible to make this work on MySQL 5.7 but that has not been tested yet. + +3. Latency issues over slow connections. Perhaps should use compressed +connection to speed things up? + +4. Inefficient collection of data. I'm calculating stuff for the +things I'm not actually displaying, so I should split this so that +the display part does the calculations when needed and only the raw +values are collected. diff --git a/performance_schema/file_summary_by_instance/file_summary_by_instance.go b/performance_schema/file_summary_by_instance/file_summary_by_instance.go index 5340ed7..f71f1d6 100644 --- a/performance_schema/file_summary_by_instance/file_summary_by_instance.go +++ b/performance_schema/file_summary_by_instance/file_summary_by_instance.go @@ -6,8 +6,9 @@ package file_summary_by_instance import ( "database/sql" + "time" - // "github.com/sjmudd/pstop/lib" + "github.com/sjmudd/pstop/lib" ps "github.com/sjmudd/pstop/performance_schema" ) @@ -73,6 +74,7 @@ func (t *File_summary_by_instance) UpdateInitialValues() { // Collect data from the db, then merge it in. func (t *File_summary_by_instance) Collect(dbh *sql.DB) { + start := time.Now() // UPDATE current from db handle t.current = merge_by_table_name(select_fsbi_rows(dbh), t.global_variables) @@ -102,6 +104,7 @@ func (t *File_summary_by_instance) Collect(dbh *sql.DB) { // setup the totals t.totals = t.results.totals() + lib.Logger.Println("File_summary_by_instance.Collect() took:", time.Duration(time.Since(start)).String()) } // return the headings for a table diff --git a/performance_schema/file_summary_by_instance/file_summary_by_instance_row.go b/performance_schema/file_summary_by_instance/file_summary_by_instance_row.go index 64dd145..2488647 100644 --- a/performance_schema/file_summary_by_instance/file_summary_by_instance_row.go +++ b/performance_schema/file_summary_by_instance/file_summary_by_instance_row.go @@ -8,6 +8,7 @@ import ( "log" "regexp" "sort" + "time" "github.com/sjmudd/pstop/lib" ) @@ -276,6 +277,7 @@ func (t file_summary_by_instance_row) simple_name(global_variables map[string]st // Convert the imported "table" to a merged one with merged data. // Combine all entries with the same "FILE_NAME" by adding their values. func merge_by_table_name(orig file_summary_by_instance_rows, global_variables map[string]string) file_summary_by_instance_rows { + start := time.Now() t := make(file_summary_by_instance_rows, 0, len(orig)) m := make(map[string]file_summary_by_instance_row) @@ -305,6 +307,7 @@ func merge_by_table_name(orig file_summary_by_instance_rows, global_variables ma t = append(t, row) } + lib.Logger.Println("merge_by_table_name() took:", time.Duration(time.Since(start)).String()) return t } @@ -314,6 +317,7 @@ func merge_by_table_name(orig file_summary_by_instance_rows, global_variables ma // - change FILE_NAME into a more descriptive value. func select_fsbi_rows(dbh *sql.DB) file_summary_by_instance_rows { var t file_summary_by_instance_rows + start := time.Now() sql := "SELECT FILE_NAME, COUNT_STAR, SUM_TIMER_WAIT, COUNT_READ, SUM_TIMER_READ, SUM_NUMBER_OF_BYTES_READ, COUNT_WRITE, SUM_TIMER_WRITE, SUM_NUMBER_OF_BYTES_WRITE, COUNT_MISC, SUM_TIMER_MISC FROM file_summary_by_instance" @@ -334,6 +338,7 @@ func select_fsbi_rows(dbh *sql.DB) file_summary_by_instance_rows { if err := rows.Err(); err != nil { log.Fatal(err) } + lib.Logger.Println("select_fsbi_rows() took:", time.Duration(time.Since(start)).String()) return t } diff --git a/performance_schema/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go b/performance_schema/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go index 0ef79dc..ab1166b 100644 --- a/performance_schema/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go +++ b/performance_schema/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go @@ -7,6 +7,7 @@ package table_io_waits_summary_by_table import ( "database/sql" "fmt" + "time" "github.com/sjmudd/pstop/lib" ps "github.com/sjmudd/pstop/performance_schema" @@ -35,6 +36,7 @@ func (t Table_io_waits_summary_by_table) WantsLatency() bool { // 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) { + start := time.Now() lib.Logger.Println("Table_io_waits_summary_by_table.Collect() BEGIN") t.current = select_tiwsbt_rows(dbh) lib.Logger.Println("- t.current set from", len(t.current), "collected row(s) from SELECT") @@ -58,7 +60,7 @@ func (t *Table_io_waits_summary_by_table) Collect(dbh *sql.DB) { // lib.Logger.Println( "t.current:", t.current ) 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") + lib.Logger.Println("Table_io_waits_summary_by_table.Collect() END, took:", time.Duration(time.Since(start)).String()) } func (t *Table_io_waits_summary_by_table) make_results() { diff --git a/performance_schema/table_lock_waits_summary_by_table/table_lock_waits_summary_by_table.go b/performance_schema/table_lock_waits_summary_by_table/table_lock_waits_summary_by_table.go index 2977298..294d7c0 100644 --- a/performance_schema/table_lock_waits_summary_by_table/table_lock_waits_summary_by_table.go +++ b/performance_schema/table_lock_waits_summary_by_table/table_lock_waits_summary_by_table.go @@ -5,8 +5,9 @@ package table_lock_waits_summary_by_table import ( "database/sql" _ "github.com/go-sql-driver/mysql" + "time" - // "github.com/sjmudd/pstop/lib" + "github.com/sjmudd/pstop/lib" ps "github.com/sjmudd/pstop/performance_schema" ) @@ -22,6 +23,7 @@ type Table_lock_waits_summary_by_table struct { // Collect data from the db, then merge it in. func (t *Table_lock_waits_summary_by_table) Collect(dbh *sql.DB) { + start := time.Now() t.current = select_tlwsbt_rows(dbh) if len(t.initial) == 0 && len(t.current) > 0 { @@ -36,6 +38,7 @@ func (t *Table_lock_waits_summary_by_table) Collect(dbh *sql.DB) { } t.make_results() + lib.Logger.Println("Table_lock_waits_summary_by_table.Collect() took:", time.Duration(time.Since(start)).String()) } func (t *Table_lock_waits_summary_by_table) make_results() { diff --git a/state/state.go b/state/state.go index 824d9fb..8898331 100644 --- a/state/state.go +++ b/state/state.go @@ -80,15 +80,19 @@ func (state *State) ResetDBStatistics() { } func (state *State) UpdateInitialValues() { + start := time.Now() state.fsbi.UpdateInitialValues() state.tlwsbt.UpdateInitialValues() state.tiwsbt.UpdateInitialValues() + lib.Logger.Println("state.UpdateInitialValues() took", time.Duration(time.Since(start)).String()) } func (state *State) Collect() { + start := time.Now() state.fsbi.Collect(state.dbh) state.tlwsbt.Collect(state.dbh) state.tiwsbt.Collect(state.dbh) + lib.Logger.Println("state.Collect() took", time.Duration(time.Since(start)).String()) } func (state State) MySQLVersion() string { -- 2.20.1