*/
-type table_lock_waits_summary_by_table_row struct {
+type table_row struct {
OBJECT_TYPE string // in theory redundant but keep anyway
OBJECT_SCHEMA string // in theory redundant but keep anyway
OBJECT_NAME string // in theory redundant but keep anyway
SUM_TIMER_WRITE_EXTERNAL uint64
}
-type table_lock_waits_summary_by_table_rows []table_lock_waits_summary_by_table_row
+type table_rows []table_row
// return the table name from the columns as '<schema>.<table>'
-func (r *table_lock_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
return n
}
-func (r *table_lock_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]
// Table Name Latency %| Read Write|S.Lock High NoIns Normal Extrnl|AlloWr CncIns WrtDly Low Normal Extrnl|
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1234567890 100.0%|xxxxx% xxxxx%|xxxxx% xxxxx% xxxxx% xxxxx% xxxxx%|xxxxx% xxxxx% xxxxx% xxxxx% xxxxx% xxxxx%|
-func (r *table_lock_waits_summary_by_table_row) headings() string {
+func (r *table_row) headings() string {
return fmt.Sprintf("%-30s %10s %6s|%6s %6s|%6s %6s %6s %6s %6s|%6s %6s %6s %6s %6s",
"Table Name", "Latency", "%",
"Read", "Write",
}
// generate a printable result
-func (r *table_lock_waits_summary_by_table_row) row_content(totals table_lock_waits_summary_by_table_row) string {
+func (r *table_row) row_content(totals table_row) string {
// assume the data is empty so hide it.
name := r.pretty_name()
lib.FormatPct(lib.MyDivide(r.SUM_TIMER_WRITE_EXTERNAL, r.SUM_TIMER_WAIT)))
}
-func (this *table_lock_waits_summary_by_table_row) add(other table_lock_waits_summary_by_table_row) {
+func (this *table_row) add(other table_row) {
this.COUNT_STAR += other.COUNT_STAR
this.SUM_TIMER_WAIT += other.SUM_TIMER_WAIT
this.SUM_TIMER_READ += other.SUM_TIMER_READ
this.SUM_TIMER_WRITE_EXTERNAL += other.SUM_TIMER_WRITE_EXTERNAL
}
-func (this *table_lock_waits_summary_by_table_row) subtract(other table_lock_waits_summary_by_table_row) {
+func (this *table_row) subtract(other table_row) {
this.COUNT_STAR -= other.COUNT_STAR
this.SUM_TIMER_WAIT -= other.SUM_TIMER_WAIT
this.SUM_TIMER_READ -= other.SUM_TIMER_READ
}
// return the totals of a slice of rows
-func (t table_lock_waits_summary_by_table_rows) totals() table_lock_waits_summary_by_table_row {
- var totals table_lock_waits_summary_by_table_row
+func (t table_rows) totals() table_row {
+ var totals table_row
totals.OBJECT_SCHEMA = "Totals"
for i := range t {
// - filter out empty values
// - merge rows with the same name into a single row
// - change FILE_NAME into a more descriptive value.
-func select_tlwsbt_rows(dbh *sql.DB) table_lock_waits_summary_by_table_rows {
- var t table_lock_waits_summary_by_table_rows
+func select_tlwsbt_rows(dbh *sql.DB) table_rows {
+ var t table_rows
sql := "SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COUNT_STAR, SUM_TIMER_WAIT, SUM_TIMER_READ, SUM_TIMER_WRITE, SUM_TIMER_READ_WITH_SHARED_LOCKS, SUM_TIMER_READ_HIGH_PRIORITY, SUM_TIMER_READ_NO_INSERT, SUM_TIMER_READ_NORMAL, SUM_TIMER_READ_EXTERNAL, SUM_TIMER_WRITE_ALLOW_WRITE, SUM_TIMER_WRITE_CONCURRENT_INSERT, SUM_TIMER_WRITE_LOW_PRIORITY, SUM_TIMER_WRITE_NORMAL, SUM_TIMER_WRITE_EXTERNAL FROM table_lock_waits_summary_by_table WHERE COUNT_STAR > 0"
defer rows.Close()
for rows.Next() {
- var r table_lock_waits_summary_by_table_row
+ var r table_row
if err := rows.Scan(
&r.OBJECT_TYPE,
&r.OBJECT_SCHEMA,
return t
}
-func (t table_lock_waits_summary_by_table_rows) Len() int { return len(t) }
-func (t table_lock_waits_summary_by_table_rows) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
-func (t table_lock_waits_summary_by_table_rows) Less(i, j int) bool {
+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] }
+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) &&
}
// sort the data
-func (t *table_lock_waits_summary_by_table_rows) sort() {
+func (t *table_rows) sort() {
sort.Sort(t)
}
// 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_lock_waits_summary_by_table_rows) subtract(initial table_lock_waits_summary_by_table_rows) {
+func (this *table_rows) subtract(initial table_rows) {
i_by_name := make(map[string]int)
// iterate over rows by name
// if the data in t2 is "newer", "has more values" than t then it needs refreshing.
// check this by comparing totals.
-func (t table_lock_waits_summary_by_table_rows) needs_refresh(t2 table_lock_waits_summary_by_table_rows) bool {
+func (t table_rows) needs_refresh(t2 table_rows) bool {
my_totals := t.totals()
t2_totals := t2.totals()
}
// describe a whole row
-func (r table_lock_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",
r.pretty_name(),
lib.FormatTime(r.SUM_TIMER_WAIT),
}
// describe a whole table
-func (t table_lock_waits_summary_by_table_rows) String() string {
+func (t table_rows) String() string {
s := make([]string, len(t))
for i := range t {
)
// a table of rows
-type Table_lock_waits_summary_by_table struct {
+type Object struct {
p_s.RelativeStats
p_s.InitialTime
- initial table_lock_waits_summary_by_table_rows // initial data for relative values
- current table_lock_waits_summary_by_table_rows // last loaded values
- results table_lock_waits_summary_by_table_rows // results (maybe with subtraction)
- totals table_lock_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
}
// Collect data from the db, then merge it in.
-func (t *Table_lock_waits_summary_by_table) Collect(dbh *sql.DB) {
+func (t *Object) Collect(dbh *sql.DB) {
start := time.Now()
t.current = select_tlwsbt_rows(dbh)
if len(t.initial) == 0 && len(t.current) > 0 {
- t.initial = make(table_lock_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) {
- t.initial = make(table_lock_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_lock_waits_summary_by_table.Collect() took:", time.Duration(time.Since(start)).String())
+ lib.Logger.Println("Object.Collect() took:", time.Duration(time.Since(start)).String())
}
-func (t *Table_lock_waits_summary_by_table) make_results() {
+func (t *Object) make_results() {
// lib.Logger.Println( "- t.results set from t.current" )
- t.results = make(table_lock_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()" )
}
// reset the statistics to current values
-func (t *Table_lock_waits_summary_by_table) SyncReferenceValues() {
+func (t *Object) SyncReferenceValues() {
t.SetNow()
- t.initial = make(table_lock_waits_summary_by_table_rows, len(t.current))
+ t.initial = make(table_rows, len(t.current))
copy(t.initial, t.current)
t.make_results()
}
// return the headings for a table
-func (t Table_lock_waits_summary_by_table) Headings() string {
- var r table_lock_waits_summary_by_table_row
+func (t Object) Headings() string {
+ var r table_row
return r.headings()
}
// return the rows we need for displaying
-func (t Table_lock_waits_summary_by_table) RowContent(max_rows int) []string {
+func (t Object) RowContent(max_rows int) []string {
rows := make([]string, 0, max_rows)
for i := range t.results {
}
// return all the totals
-func (t Table_lock_waits_summary_by_table) TotalRowContent() string {
+func (t Object) TotalRowContent() string {
return t.totals.row_content(t.totals)
}
// return an empty string of data (for filling in)
-func (t Table_lock_waits_summary_by_table) EmptyRowContent() string {
- var emtpy table_lock_waits_summary_by_table_row
+func (t Object) EmptyRowContent() string {
+ var emtpy table_row
return emtpy.row_content(emtpy)
}
-func (t Table_lock_waits_summary_by_table) Description() string {
+func (t Object) Description() string {
return "Locks by Table Name (table_lock_waits_summary_by_table)"
}