1 // performance_schema - 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
10 // "github.com/sjmudd/pstop/lib"
11 ps "github.com/sjmudd/pstop/performance_schema"
15 CREATE TABLE `file_summary_by_instance` (
16 `FILE_NAME` varchar(512) NOT NULL,
17 `EVENT_NAME` varchar(128) NOT NULL, // not collected
18 `OBJECT_INSTANCE_BEGIN` bigint(20) unsigned NOT NULL, // not collected
19 `COUNT_STAR` bigint(20) unsigned NOT NULL,
20 `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL,
21 `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL,
22 `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL,
23 `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL,
24 `COUNT_READ` bigint(20) unsigned NOT NULL,
25 `SUM_TIMER_READ` bigint(20) unsigned NOT NULL,
26 `MIN_TIMER_READ` bigint(20) unsigned NOT NULL,
27 `AVG_TIMER_READ` bigint(20) unsigned NOT NULL,
28 `MAX_TIMER_READ` bigint(20) unsigned NOT NULL,
29 `SUM_NUMBER_OF_BYTES_READ` bigint(20) NOT NULL,
30 `COUNT_WRITE` bigint(20) unsigned NOT NULL,
31 `SUM_TIMER_WRITE` bigint(20) unsigned NOT NULL,
32 `MIN_TIMER_WRITE` bigint(20) unsigned NOT NULL,
33 `AVG_TIMER_WRITE` bigint(20) unsigned NOT NULL,
34 `MAX_TIMER_WRITE` bigint(20) unsigned NOT NULL,
35 `SUM_NUMBER_OF_BYTES_WRITE` bigint(20) NOT NULL,
36 `COUNT_MISC` bigint(20) unsigned NOT NULL,
37 `SUM_TIMER_MISC` bigint(20) unsigned NOT NULL,
38 `MIN_TIMER_MISC` bigint(20) unsigned NOT NULL,
39 `AVG_TIMER_MISC` bigint(20) unsigned NOT NULL,
40 `MAX_TIMER_MISC` bigint(20) unsigned NOT NULL
41 ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
42 1 row in set (0.00 sec)
47 type File_summary_by_instance struct {
50 initial file_summary_by_instance_rows
51 current file_summary_by_instance_rows
52 results file_summary_by_instance_rows
53 totals file_summary_by_instance_row
54 global_variables map[string]string
57 // reset the statistics to current values
58 func (t *File_summary_by_instance) UpdateInitialValues() {
60 t.initial = make(file_summary_by_instance_rows, len(t.current))
61 copy(t.initial, t.current)
63 t.results = make(file_summary_by_instance_rows, len(t.current))
64 copy(t.results, t.current)
66 if t.WantRelativeStats() {
67 t.results.subtract(t.initial) // should be 0 if relative
71 t.totals = t.results.totals()
74 // Collect data from the db, then merge it in.
75 func (t *File_summary_by_instance) Collect(dbh *sql.DB) {
76 // UPDATE current from db handle
77 t.current = merge_by_table_name(select_fsbi_rows(dbh), t.global_variables)
79 // copy in initial data if it was not there
80 if len(t.initial) == 0 && len(t.current) > 0 {
81 t.initial = make(file_summary_by_instance_rows, len(t.current))
82 copy(t.initial, t.current)
85 // check for reload initial characteristics
86 if t.initial.needs_refresh(t.current) {
87 t.initial = make(file_summary_by_instance_rows, len(t.current))
88 copy(t.initial, t.current)
91 // update results to current value
92 t.results = make(file_summary_by_instance_rows, len(t.current))
93 copy(t.results, t.current)
95 // make relative if need be
96 if t.WantRelativeStats() {
97 t.results.subtract(t.initial)
104 t.totals = t.results.totals()
107 // return the headings for a table
108 func (t File_summary_by_instance) Headings() string {
109 var r file_summary_by_instance_row
114 // return the rows we need for displaying
115 func (t File_summary_by_instance) RowContent(max_rows int) []string {
116 rows := make([]string, 0, max_rows)
118 for i := range t.results {
120 rows = append(rows, t.results[i].row_content(t.totals))
127 // return all the totals
128 func (t File_summary_by_instance) TotalRowContent() string {
129 return t.totals.row_content(t.totals)
132 // return an empty string of data (for filling in)
133 func (t File_summary_by_instance) EmptyRowContent() string {
134 var emtpy file_summary_by_instance_row
135 return emtpy.row_content(emtpy)
138 func (t File_summary_by_instance) Description() string {
139 return "File I/O by filename (file_summary_by_instance)"
142 // create a new structure and include various variable values:
143 // - datadir, relay_log
144 // There's no checking that these are actually provided!
145 func NewFileSummaryByInstance(global_variables map[string]string) *File_summary_by_instance {
146 n := new(File_summary_by_instance)
148 n.global_variables = global_variables