1 // p_s - library routines for pstop.
3 // This file contains the library routines for managing the
4 // file_summary_by_instance table.
5 package file_summary_by_instance
12 "github.com/sjmudd/pstop/lib"
13 "github.com/sjmudd/pstop/p_s"
24 global_variables map[string]string
27 // reset the statistics to current values
28 func (t *Object) SyncReferenceValues() {
30 t.initial = make(table_rows, len(t.current))
31 copy(t.initial, t.current)
33 t.results = make(table_rows, len(t.current))
34 copy(t.results, t.current)
36 if t.WantRelativeStats() {
37 t.results.subtract(t.initial) // should be 0 if relative
41 t.totals = t.results.totals()
44 // Collect data from the db, then merge it in.
45 func (t *Object) Collect(dbh *sql.DB) {
47 // UPDATE current from db handle
48 t.current = merge_by_table_name(select_rows(dbh), t.global_variables)
50 // copy in initial data if it was not there
51 if len(t.initial) == 0 && len(t.current) > 0 {
52 t.initial = make(table_rows, len(t.current))
53 copy(t.initial, t.current)
56 // check for reload initial characteristics
57 if t.initial.needs_refresh(t.current) {
58 t.initial = make(table_rows, len(t.current))
59 copy(t.initial, t.current)
62 // update results to current value
63 t.results = make(table_rows, len(t.current))
64 copy(t.results, t.current)
66 // make relative if need be
67 if t.WantRelativeStats() {
68 t.results.subtract(t.initial)
75 t.totals = t.results.totals()
76 lib.Logger.Println("Object.Collect() took:", time.Duration(time.Since(start)).String())
79 // return the headings for a table
80 func (t Object) Headings() string {
86 // return the rows we need for displaying
87 func (t Object) RowContent(max_rows int) []string {
88 rows := make([]string, 0, max_rows)
90 for i := range t.results {
92 rows = append(rows, t.results[i].row_content(t.totals))
99 // return all the totals
100 func (t Object) TotalRowContent() string {
101 return t.totals.row_content(t.totals)
104 // return an empty string of data (for filling in)
105 func (t Object) EmptyRowContent() string {
107 return emtpy.row_content(emtpy)
110 func (t Object) Description() string {
111 count := t.count_rows()
112 return fmt.Sprintf("I/O Latency by File (file_summary_by_instance) %4d row(s) ", count)
115 // create a new structure and include various variable values:
116 // - datadir, relay_log
117 // There's no checking that these are actually provided!
118 func NewFileSummaryByInstance(global_variables map[string]string) *Object {
121 n.global_variables = global_variables
126 func (t Object) count_rows() int {
128 for row := range t.results {
129 if t.results[row].SUM_TIMER_WAIT > 0 {