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"
21 initial table_rows // initial data for relative values
22 current table_rows // last loaded values
23 results table_rows // results (maybe with subtraction)
24 totals table_row // totals of results
27 func (t *Object) SetWantsLatency(want_latency bool) {
28 t.want_latency = want_latency
31 func (t Object) 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 *Object) Collect(dbh *sql.DB) {
40 // lib.Logger.Println("Object.Collect() BEGIN")
41 t.current = select_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_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_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("Object.Collect() END, took:", time.Duration(time.Since(start)).String())
68 func (t *Object) make_results() {
69 // lib.Logger.Println( "- t.results set from t.current" )
70 t.results = make(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 *Object) SyncReferenceValues() {
85 // lib.Logger.Println( "Object.SyncReferenceValues() BEGIN" )
88 t.initial = make(table_rows, len(t.current))
89 copy(t.initial, t.current)
93 // lib.Logger.Println( "Object.SyncReferenceValues() END" )
96 func (t *Object) Headings() string {
98 return t.latencyHeadings()
100 return t.opsHeadings()
104 func (t Object) RowContent(max_rows int) []string {
106 return t.latencyRowContent(max_rows)
108 return t.opsRowContent(max_rows)
112 func (t Object) EmptyRowContent() string {
114 return t.emptyLatencyRowContent()
116 return t.emptyOpsRowContent()
120 func (t Object) TotalRowContent() string {
122 return t.totalLatencyRowContent()
124 return t.totalOpsRowContent()
128 func (t Object) Description() string {
130 return t.latencyDescription()
132 return t.opsDescription()
136 func (t *Object) latencyHeadings() string {
139 return r.latency_headings()
142 func (t *Object) opsHeadings() string {
145 return r.ops_headings()
148 func (t Object) opsRowContent(max_rows int) []string {
149 rows := make([]string, 0, max_rows)
151 for i := range t.results {
153 rows = append(rows, t.results[i].ops_row_content(t.totals))
160 func (t Object) latencyRowContent(max_rows int) []string {
161 rows := make([]string, 0, max_rows)
163 for i := range t.results {
165 rows = append(rows, t.results[i].latency_row_content(t.totals))
172 func (t Object) emptyOpsRowContent() string {
175 return r.ops_row_content(r)
178 func (t Object) emptyLatencyRowContent() string {
181 return r.latency_row_content(r)
184 func (t Object) totalOpsRowContent() string {
185 return t.totals.ops_row_content(t.totals)
188 func (t Object) totalLatencyRowContent() string {
189 return t.totals.latency_row_content(t.totals)
192 func (t Object) latencyDescription() string {
193 count := t.count_rows()
194 return fmt.Sprintf("Latency by Table Name (table_io_waits_summary_by_table) %d rows", count)
197 func (t Object) opsDescription() string {
198 count := t.count_rows()
199 return fmt.Sprintf("Operations by Table Name (table_io_waits_summary_by_table) %d rows", count)
202 func (t Object) count_rows() int {
204 for row := range t.results {
205 if t.results[row].SUM_TIMER_WAIT > 0 {