Be able to collect some usage metrics
authorSimon J Mudd <sjmudd@pobox.com>
Sat, 15 Nov 2014 12:24:48 +0000 (13:24 +0100)
committerSimon J Mudd <sjmudd@pobox.com>
Sat, 15 Nov 2014 12:24:48 +0000 (13:24 +0100)
BUGS
performance_schema/file_summary_by_instance/file_summary_by_instance.go
performance_schema/file_summary_by_instance/file_summary_by_instance_row.go
performance_schema/table_io_waits_summary_by_table/table_io_waits_summary_by_table.go
performance_schema/table_lock_waits_summary_by_table/table_lock_waits_summary_by_table.go
state/state.go

diff --git a/BUGS b/BUGS
index 316c001..2556f67 100644 (file)
--- 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.
 
 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.
index 5340ed7..f71f1d6 100644 (file)
@@ -6,8 +6,9 @@ package file_summary_by_instance
 
 import (
        "database/sql"
 
 import (
        "database/sql"
+       "time"
 
 
-       //      "github.com/sjmudd/pstop/lib"
+       "github.com/sjmudd/pstop/lib"
        ps "github.com/sjmudd/pstop/performance_schema"
 )
 
        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) {
 
 // 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)
 
        // 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()
 
        // 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
 }
 
 // return the headings for a table
index 64dd145..2488647 100644 (file)
@@ -8,6 +8,7 @@ import (
        "log"
        "regexp"
        "sort"
        "log"
        "regexp"
        "sort"
+       "time"
 
        "github.com/sjmudd/pstop/lib"
 )
 
        "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 {
 // 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)
        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)
        }
 
                t = append(t, row)
        }
 
+       lib.Logger.Println("merge_by_table_name() took:", time.Duration(time.Since(start)).String())
        return t
 }
 
        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
 // - 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"
 
 
        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)
        }
        if err := rows.Err(); err != nil {
                log.Fatal(err)
        }
+       lib.Logger.Println("select_fsbi_rows() took:", time.Duration(time.Since(start)).String())
 
        return t
 }
 
        return t
 }
index 0ef79dc..ab1166b 100644 (file)
@@ -7,6 +7,7 @@ package table_io_waits_summary_by_table
 import (
        "database/sql"
        "fmt"
 import (
        "database/sql"
        "fmt"
+       "time"
 
        "github.com/sjmudd/pstop/lib"
        ps "github.com/sjmudd/pstop/performance_schema"
 
        "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) {
 // 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")
        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( "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() {
 }
 
 func (t *Table_io_waits_summary_by_table) make_results() {
index 2977298..294d7c0 100644 (file)
@@ -5,8 +5,9 @@ package table_lock_waits_summary_by_table
 import (
        "database/sql"
        _ "github.com/go-sql-driver/mysql"
 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"
 )
 
        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) {
 
 // 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 {
        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()
        }
 
        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() {
 }
 
 func (t *Table_lock_waits_summary_by_table) make_results() {
index 824d9fb..8898331 100644 (file)
@@ -80,15 +80,19 @@ func (state *State) ResetDBStatistics() {
 }
 
 func (state *State) UpdateInitialValues() {
 }
 
 func (state *State) UpdateInitialValues() {
+       start := time.Now()
        state.fsbi.UpdateInitialValues()
        state.tlwsbt.UpdateInitialValues()
        state.tiwsbt.UpdateInitialValues()
        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() {
 }
 
 func (state *State) Collect() {
+       start := time.Now()
        state.fsbi.Collect(state.dbh)
        state.tlwsbt.Collect(state.dbh)
        state.tiwsbt.Collect(state.dbh)
        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 {
 }
 
 func (state State) MySQLVersion() string {