1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 /**
24 @file storage/perfschema/table_file_summary_by_event_name.cc
25 Table FILE_SUMMARY_BY_EVENT_NAME(implementation).
26 */
27
28 #include "my_global.h"
29 #include "my_thread.h"
30 #include "pfs_instr_class.h"
31 #include "pfs_column_types.h"
32 #include "pfs_column_values.h"
33 #include "table_file_summary_by_event_name.h"
34 #include "pfs_global.h"
35 #include "pfs_visitor.h"
36 #include "field.h"
37
38 THR_LOCK table_file_summary_by_event_name::m_table_lock;
39
40 static const TABLE_FIELD_TYPE field_types[]=
41 {
42 {
43 { C_STRING_WITH_LEN("EVENT_NAME") },
44 { C_STRING_WITH_LEN("varchar(128)") },
45 { NULL, 0}
46 },
47 {
48 { C_STRING_WITH_LEN("COUNT_STAR") },
49 { C_STRING_WITH_LEN("bigint(20)") },
50 { NULL, 0}
51 },
52 {
53 { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
54 { C_STRING_WITH_LEN("bigint(20)") },
55 { NULL, 0}
56 },
57 {
58 { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
59 { C_STRING_WITH_LEN("bigint(20)") },
60 { NULL, 0}
61 },
62 {
63 { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
64 { C_STRING_WITH_LEN("bigint(20)") },
65 { NULL, 0}
66 },
67 {
68 { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
69 { C_STRING_WITH_LEN("bigint(20)") },
70 { NULL, 0}
71 },
72
73 /** Read */
74 {
75 { C_STRING_WITH_LEN("COUNT_READ") },
76 { C_STRING_WITH_LEN("bigint(20)") },
77 { NULL, 0}
78 },
79 {
80 { C_STRING_WITH_LEN("SUM_TIMER_READ") },
81 { C_STRING_WITH_LEN("bigint(20)") },
82 { NULL, 0}
83 },
84 {
85 { C_STRING_WITH_LEN("MIN_TIMER_READ") },
86 { C_STRING_WITH_LEN("bigint(20)") },
87 { NULL, 0}
88 },
89 {
90 { C_STRING_WITH_LEN("AVG_TIMER_READ") },
91 { C_STRING_WITH_LEN("bigint(20)") },
92 { NULL, 0}
93 },
94 {
95 { C_STRING_WITH_LEN("MAX_TIMER_READ") },
96 { C_STRING_WITH_LEN("bigint(20)") },
97 { NULL, 0}
98 },
99 {
100 { C_STRING_WITH_LEN("SUM_NUMBER_OF_BYTES_READ") },
101 { C_STRING_WITH_LEN("bigint(20)") },
102 { NULL, 0}
103 },
104
105 /** Write */
106 {
107 { C_STRING_WITH_LEN("COUNT_WRITE") },
108 { C_STRING_WITH_LEN("bigint(20)") },
109 { NULL, 0}
110 },
111 {
112 { C_STRING_WITH_LEN("SUM_TIMER_WRITE") },
113 { C_STRING_WITH_LEN("bigint(20)") },
114 { NULL, 0}
115 },
116 {
117 { C_STRING_WITH_LEN("MIN_TIMER_WRITE") },
118 { C_STRING_WITH_LEN("bigint(20)") },
119 { NULL, 0}
120 },
121 {
122 { C_STRING_WITH_LEN("AVG_TIMER_WRITE") },
123 { C_STRING_WITH_LEN("bigint(20)") },
124 { NULL, 0}
125 },
126 {
127 { C_STRING_WITH_LEN("MAX_TIMER_WRITE") },
128 { C_STRING_WITH_LEN("bigint(20)") },
129 { NULL, 0}
130 },
131 {
132 { C_STRING_WITH_LEN("SUM_NUMBER_OF_BYTES_WRITE") },
133 { C_STRING_WITH_LEN("bigint(20)") },
134 { NULL, 0}
135 },
136
137 /** Misc */
138 {
139 { C_STRING_WITH_LEN("COUNT_MISC") },
140 { C_STRING_WITH_LEN("bigint(20)") },
141 { NULL, 0}
142 },
143 {
144 { C_STRING_WITH_LEN("SUM_TIMER_MISC") },
145 { C_STRING_WITH_LEN("bigint(20)") },
146 { NULL, 0}
147 },
148 {
149 { C_STRING_WITH_LEN("MIN_TIMER_MISC") },
150 { C_STRING_WITH_LEN("bigint(20)") },
151 { NULL, 0}
152 },
153 {
154 { C_STRING_WITH_LEN("AVG_TIMER_MISC") },
155 { C_STRING_WITH_LEN("bigint(20)") },
156 { NULL, 0}
157 },
158 {
159 { C_STRING_WITH_LEN("MAX_TIMER_MISC") },
160 { C_STRING_WITH_LEN("bigint(20)") },
161 { NULL, 0}
162 }
163 };
164
165 TABLE_FIELD_DEF
166 table_file_summary_by_event_name::m_field_def=
167 { 23, field_types };
168
169 PFS_engine_table_share
170 table_file_summary_by_event_name::m_share=
171 {
172 { C_STRING_WITH_LEN("file_summary_by_event_name") },
173 &pfs_truncatable_acl,
174 table_file_summary_by_event_name::create,
175 NULL, /* write_row */
176 table_file_summary_by_event_name::delete_all_rows,
177 table_file_summary_by_event_name::get_row_count,
178 sizeof(PFS_simple_index),
179 &m_table_lock,
180 &m_field_def,
181 false, /* checked */
182 false /* perpetual */
183 };
184
create(void)185 PFS_engine_table* table_file_summary_by_event_name::create(void)
186 {
187 return new table_file_summary_by_event_name();
188 }
189
delete_all_rows(void)190 int table_file_summary_by_event_name::delete_all_rows(void)
191 {
192 reset_file_instance_io();
193 reset_file_class_io();
194 return 0;
195 }
196
197 ha_rows
get_row_count(void)198 table_file_summary_by_event_name::get_row_count(void)
199 {
200 return file_class_max;
201 }
202
table_file_summary_by_event_name()203 table_file_summary_by_event_name::table_file_summary_by_event_name()
204 : PFS_engine_table(&m_share, &m_pos),
205 m_pos(1), m_next_pos(1)
206 {}
207
reset_position(void)208 void table_file_summary_by_event_name::reset_position(void)
209 {
210 m_pos.m_index= 1;
211 m_next_pos.m_index= 1;
212 }
213
rnd_next(void)214 int table_file_summary_by_event_name::rnd_next(void)
215 {
216 PFS_file_class *file_class;
217
218 m_pos.set_at(&m_next_pos);
219
220 file_class= find_file_class(m_pos.m_index);
221 if (file_class)
222 {
223 make_row(file_class);
224 m_next_pos.set_after(&m_pos);
225 return 0;
226 }
227
228 return HA_ERR_END_OF_FILE;
229 }
230
rnd_pos(const void * pos)231 int table_file_summary_by_event_name::rnd_pos(const void *pos)
232 {
233 PFS_file_class *file_class;
234
235 set_position(pos);
236
237 file_class= find_file_class(m_pos.m_index);
238 if (file_class)
239 {
240 make_row(file_class);
241 return 0;
242 }
243
244 return HA_ERR_RECORD_DELETED;
245 }
246
247 /**
248 Build a row.
249 @param file_class the file class the cursor is reading
250 */
make_row(PFS_file_class * file_class)251 void table_file_summary_by_event_name::make_row(PFS_file_class *file_class)
252 {
253 m_row.m_event_name.make_row(file_class);
254
255 PFS_instance_file_io_stat_visitor visitor;
256 PFS_instance_iterator::visit_file_instances(file_class, &visitor);
257
258 time_normalizer *normalizer= time_normalizer::get(wait_timer);
259
260 /* Collect timer and byte count stats */
261 m_row.m_io_stat.set(normalizer, &visitor.m_file_io_stat);
262 m_row_exists= true;
263
264 }
265
read_row_values(TABLE * table,unsigned char *,Field ** fields,bool read_all)266 int table_file_summary_by_event_name::read_row_values(TABLE *table,
267 unsigned char *,
268 Field **fields,
269 bool read_all)
270 {
271 Field *f;
272
273 if (unlikely(!m_row_exists))
274 return HA_ERR_RECORD_DELETED;
275
276 /* Set the null bits */
277 assert(table->s->null_bytes == 0);
278
279 for (; (f= *fields) ; fields++)
280 {
281 if (read_all || bitmap_is_set(table->read_set, f->field_index))
282 {
283 switch(f->field_index)
284 {
285 case 0: /* EVENT_NAME */
286 m_row.m_event_name.set_field(f);
287 break;
288 case 1: /* COUNT_STAR */
289 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_count);
290 break;
291 case 2: /* SUM_TIMER_WAIT */
292 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_sum);
293 break;
294 case 3: /* MIN_TIMER_WAIT */
295 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_min);
296 break;
297 case 4: /* AVG_TIMER_WAIT */
298 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_avg);
299 break;
300 case 5: /* MAX_TIMER_WAIT */
301 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_max);
302 break;
303
304 case 6: /* COUNT_READ */
305 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_count);
306 break;
307 case 7: /* SUM_TIMER_READ */
308 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_sum);
309 break;
310 case 8: /* MIN_TIMER_READ */
311 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_min);
312 break;
313 case 9: /* AVG_TIMER_READ */
314 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_avg);
315 break;
316 case 10: /* MAX_TIMER_READ */
317 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_max);
318 break;
319 case 11: /* SUM_NUMBER_OF_BYTES_READ */
320 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_bytes);
321 break;
322
323 case 12: /* COUNT_WRITE */
324 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_count);
325 break;
326 case 13: /* SUM_TIMER_WRITE */
327 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_sum);
328 break;
329 case 14: /* MIN_TIMER_WRITE */
330 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_min);
331 break;
332 case 15: /* AVG_TIMER_WRITE */
333 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_avg);
334 break;
335 case 16: /* MAX_TIMER_WRITE */
336 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_max);
337 break;
338 case 17: /* SUM_NUMBER_OF_BYTES_WRITE */
339 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_bytes);
340 break;
341
342 case 18: /* COUNT_MISC */
343 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_count);
344 break;
345 case 19: /* SUM_TIMER_MISC */
346 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_sum);
347 break;
348 case 20: /* MIN_TIMER_MISC */
349 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_min);
350 break;
351 case 21: /* AVG_TIMER_MISC */
352 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_avg);
353 break;
354 case 22: /* MAX_TIMER_MISC */
355 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_max);
356 break;
357
358 default:
359 assert(false);
360 break;
361 }
362 } // if
363 } // for
364
365 return 0;
366 }
367