1 // p_s - library routines for pstop.
3 // This file contains the library routines for managing the
4 // table_io_waits_by_table table.
5 package table_io_waits_summary_by_table
12 "github.com/sjmudd/pstop/lib"
13 "github.com/sjmudd/pstop/p_s"
17 type Table_io_waits_summary_by_table struct {
21 initial table_io_waits_summary_by_table_rows // initial data for relative values
22 current table_io_waits_summary_by_table_rows // last loaded values
23 results table_io_waits_summary_by_table_rows // results (maybe with subtraction)
24 totals table_io_waits_summary_by_table_row // totals of results
27 func (t *Table_io_waits_summary_by_table) SetWantsLatency(want_latency bool) {
28 t.want_latency = want_latency
31 func (t Table_io_waits_summary_by_table) WantsLatency() bool {
35 // Collect() collects data from the db, updating initial
36 // values if needed, and then subtracting initial values if we want
37 // relative values, after which it stores totals.
38 func (t *Table_io_waits_summary_by_table) Collect(dbh *sql.DB) {
40 // lib.Logger.Println("Table_io_waits_summary_by_table.Collect() BEGIN")
41 t.current = select_tiwsbt_rows(dbh)
42 lib.Logger.Println("t.current collected", len(t.current), "row(s) from SELECT")
44 if len(t.initial) == 0 && len(t.current) > 0 {
45 lib.Logger.Println("t.initial: copying from t.current (initial setup)")
46 t.initial = make(table_io_waits_summary_by_table_rows, len(t.current))
47 copy(t.initial, t.current)
50 // check for reload initial characteristics
51 if t.initial.needs_refresh(t.current) {
52 lib.Logger.Println("t.initial: copying from t.current (data needs refreshing)")
53 t.initial = make(table_io_waits_summary_by_table_rows, len(t.current))
54 copy(t.initial, t.current)
59 // lib.Logger.Println( "t.initial:", t.initial )
60 // lib.Logger.Println( "t.current:", t.current )
61 lib.Logger.Println("t.initial.totals():", t.initial.totals())
62 lib.Logger.Println("t.current.totals():", t.current.totals())
63 // lib.Logger.Println("t.results:", t.results)
64 // lib.Logger.Println("t.totals:", t.totals)
65 lib.Logger.Println("Table_io_waits_summary_by_table.Collect() END, took:", time.Duration(time.Since(start)).String())
68 func (t *Table_io_waits_summary_by_table) make_results() {
69 // lib.Logger.Println( "- t.results set from t.current" )
70 t.results = make(table_io_waits_summary_by_table_rows, len(t.current))
71 copy(t.results, t.current)
72 if t.WantRelativeStats() {
73 // lib.Logger.Println( "- subtracting t.initial from t.results as WantRelativeStats()" )
74 t.results.subtract(t.initial)
77 // lib.Logger.Println( "- sorting t.results" )
78 t.results.Sort(t.want_latency)
79 // lib.Logger.Println( "- collecting t.totals from t.results" )
80 t.totals = t.results.totals()
83 // reset the statistics to current values
84 func (t *Table_io_waits_summary_by_table) SyncReferenceValues() {
85 // lib.Logger.Println( "Table_io_waits_summary_by_table.SyncReferenceValues() BEGIN" )
87 t.initial = make(table_io_waits_summary_by_table_rows, len(t.current))
88 copy(t.initial, t.current)
92 // lib.Logger.Println( "Table_io_waits_summary_by_table.SyncReferenceValues() END" )
95 func (t *Table_io_waits_summary_by_table) Headings() string {
97 return t.latencyHeadings()
99 return t.opsHeadings()
103 func (t Table_io_waits_summary_by_table) RowContent(max_rows int) []string {
105 return t.latencyRowContent(max_rows)
107 return t.opsRowContent(max_rows)
111 func (t Table_io_waits_summary_by_table) EmptyRowContent() string {
113 return t.emptyLatencyRowContent()
115 return t.emptyOpsRowContent()
119 func (t Table_io_waits_summary_by_table) TotalRowContent() string {
121 return t.totalLatencyRowContent()
123 return t.totalOpsRowContent()
127 func (t Table_io_waits_summary_by_table) Description() string {
129 return t.latencyDescription()
131 return t.opsDescription()
135 func (t *Table_io_waits_summary_by_table) latencyHeadings() string {
136 var r table_io_waits_summary_by_table_row
138 return r.latency_headings()
141 func (t *Table_io_waits_summary_by_table) opsHeadings() string {
142 var r table_io_waits_summary_by_table_row
144 return r.ops_headings()
147 func (t Table_io_waits_summary_by_table) opsRowContent(max_rows int) []string {
148 rows := make([]string, 0, max_rows)
150 for i := range t.results {
152 rows = append(rows, t.results[i].ops_row_content(t.totals))
159 func (t Table_io_waits_summary_by_table) latencyRowContent(max_rows int) []string {
160 rows := make([]string, 0, max_rows)
162 for i := range t.results {
164 rows = append(rows, t.results[i].latency_row_content(t.totals))
171 func (t Table_io_waits_summary_by_table) emptyOpsRowContent() string {
172 var r table_io_waits_summary_by_table_row
174 return r.ops_row_content(r)
177 func (t Table_io_waits_summary_by_table) emptyLatencyRowContent() string {
178 var r table_io_waits_summary_by_table_row
180 return r.latency_row_content(r)
183 func (t Table_io_waits_summary_by_table) totalOpsRowContent() string {
184 return t.totals.ops_row_content(t.totals)
187 func (t Table_io_waits_summary_by_table) totalLatencyRowContent() string {
188 return t.totals.latency_row_content(t.totals)
191 func (t Table_io_waits_summary_by_table) latencyDescription() string {
192 count := t.count_rows()
193 return fmt.Sprintf("Latency by Table Name (table_io_waits_summary_by_table) %d rows", count)
196 func (t Table_io_waits_summary_by_table) opsDescription() string {
197 count := t.count_rows()
198 return fmt.Sprintf("Operations by Table Name (table_io_waits_summary_by_table) %d rows", count)
201 func (t Table_io_waits_summary_by_table) count_rows() int {
203 for row := range t.results {
204 if t.results[row].SUM_TIMER_WAIT > 0 {