1/* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
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 as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15
16/**
17 @file storage/perfschema/table_tlws_by_table.cc
18 Table TABLE_LOCK_WAITS_SUMMARY_BY_TABLE (implementation).
19*/
20
21#include "my_global.h"
22#include "my_pthread.h"
23#include "pfs_instr_class.h"
24#include "pfs_column_types.h"
25#include "pfs_column_values.h"
26#include "table_tlws_by_table.h"
27#include "pfs_global.h"
28#include "pfs_visitor.h"
29
30THR_LOCK table_tlws_by_table::m_table_lock;
31
32PFS_engine_table_share
33table_tlws_by_table::m_share=
34{
35 { C_STRING_WITH_LEN("table_lock_waits_summary_by_table") },
36 &pfs_truncatable_acl,
37 table_tlws_by_table::create,
38 NULL, /* write_row */
39 table_tlws_by_table::delete_all_rows,
40 NULL, /* get_row_count */
41 1000, /* records */
42 sizeof(PFS_simple_index),
43 &m_table_lock,
44 { C_STRING_WITH_LEN("CREATE TABLE table_lock_waits_summary_by_table("
45 "OBJECT_TYPE VARCHAR(64),"
46 "OBJECT_SCHEMA VARCHAR(64),"
47 "OBJECT_NAME VARCHAR(64),"
48 "COUNT_STAR BIGINT unsigned not null,"
49 "SUM_TIMER_WAIT BIGINT unsigned not null,"
50 "MIN_TIMER_WAIT BIGINT unsigned not null,"
51 "AVG_TIMER_WAIT BIGINT unsigned not null,"
52 "MAX_TIMER_WAIT BIGINT unsigned not null,"
53 "COUNT_READ BIGINT unsigned not null,"
54 "SUM_TIMER_READ BIGINT unsigned not null,"
55 "MIN_TIMER_READ BIGINT unsigned not null,"
56 "AVG_TIMER_READ BIGINT unsigned not null,"
57 "MAX_TIMER_READ BIGINT unsigned not null,"
58 "COUNT_WRITE BIGINT unsigned not null,"
59 "SUM_TIMER_WRITE BIGINT unsigned not null,"
60 "MIN_TIMER_WRITE BIGINT unsigned not null,"
61 "AVG_TIMER_WRITE BIGINT unsigned not null,"
62 "MAX_TIMER_WRITE BIGINT unsigned not null,"
63 "COUNT_READ_NORMAL BIGINT unsigned not null,"
64 "SUM_TIMER_READ_NORMAL BIGINT unsigned not null,"
65 "MIN_TIMER_READ_NORMAL BIGINT unsigned not null,"
66 "AVG_TIMER_READ_NORMAL BIGINT unsigned not null,"
67 "MAX_TIMER_READ_NORMAL BIGINT unsigned not null,"
68 "COUNT_READ_WITH_SHARED_LOCKS BIGINT unsigned not null,"
69 "SUM_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null,"
70 "MIN_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null,"
71 "AVG_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null,"
72 "MAX_TIMER_READ_WITH_SHARED_LOCKS BIGINT unsigned not null,"
73 "COUNT_READ_HIGH_PRIORITY BIGINT unsigned not null,"
74 "SUM_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null,"
75 "MIN_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null,"
76 "AVG_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null,"
77 "MAX_TIMER_READ_HIGH_PRIORITY BIGINT unsigned not null,"
78 "COUNT_READ_NO_INSERT BIGINT unsigned not null,"
79 "SUM_TIMER_READ_NO_INSERT BIGINT unsigned not null,"
80 "MIN_TIMER_READ_NO_INSERT BIGINT unsigned not null,"
81 "AVG_TIMER_READ_NO_INSERT BIGINT unsigned not null,"
82 "MAX_TIMER_READ_NO_INSERT BIGINT unsigned not null,"
83 "COUNT_READ_EXTERNAL BIGINT unsigned not null,"
84 "SUM_TIMER_READ_EXTERNAL BIGINT unsigned not null,"
85 "MIN_TIMER_READ_EXTERNAL BIGINT unsigned not null,"
86 "AVG_TIMER_READ_EXTERNAL BIGINT unsigned not null,"
87 "MAX_TIMER_READ_EXTERNAL BIGINT unsigned not null,"
88 "COUNT_WRITE_ALLOW_WRITE BIGINT unsigned not null,"
89 "SUM_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null,"
90 "MIN_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null,"
91 "AVG_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null,"
92 "MAX_TIMER_WRITE_ALLOW_WRITE BIGINT unsigned not null,"
93 "COUNT_WRITE_CONCURRENT_INSERT BIGINT unsigned not null,"
94 "SUM_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null,"
95 "MIN_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null,"
96 "AVG_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null,"
97 "MAX_TIMER_WRITE_CONCURRENT_INSERT BIGINT unsigned not null,"
98 "COUNT_WRITE_DELAYED BIGINT unsigned not null,"
99 "SUM_TIMER_WRITE_DELAYED BIGINT unsigned not null,"
100 "MIN_TIMER_WRITE_DELAYED BIGINT unsigned not null,"
101 "AVG_TIMER_WRITE_DELAYED BIGINT unsigned not null,"
102 "MAX_TIMER_WRITE_DELAYED BIGINT unsigned not null,"
103 "COUNT_WRITE_LOW_PRIORITY BIGINT unsigned not null,"
104 "SUM_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null,"
105 "MIN_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null,"
106 "AVG_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null,"
107 "MAX_TIMER_WRITE_LOW_PRIORITY BIGINT unsigned not null,"
108 "COUNT_WRITE_NORMAL BIGINT unsigned not null,"
109 "SUM_TIMER_WRITE_NORMAL BIGINT unsigned not null,"
110 "MIN_TIMER_WRITE_NORMAL BIGINT unsigned not null,"
111 "AVG_TIMER_WRITE_NORMAL BIGINT unsigned not null,"
112 "MAX_TIMER_WRITE_NORMAL BIGINT unsigned not null,"
113 "COUNT_WRITE_EXTERNAL BIGINT unsigned not null,"
114 "SUM_TIMER_WRITE_EXTERNAL BIGINT unsigned not null,"
115 "MIN_TIMER_WRITE_EXTERNAL BIGINT unsigned not null,"
116 "AVG_TIMER_WRITE_EXTERNAL BIGINT unsigned not null,"
117 "MAX_TIMER_WRITE_EXTERNAL BIGINT unsigned not null)") }
118};
119
120PFS_engine_table*
121table_tlws_by_table::create(void)
122{
123 return new table_tlws_by_table();
124}
125
126int
127table_tlws_by_table::delete_all_rows(void)
128{
129 reset_table_lock_waits_by_table_handle();
130 reset_table_lock_waits_by_table();
131 return 0;
132}
133
134table_tlws_by_table::table_tlws_by_table()
135 : PFS_engine_table(&m_share, &m_pos),
136 m_row_exists(false), m_pos(0), m_next_pos(0)
137{}
138
139void table_tlws_by_table::reset_position(void)
140{
141 m_pos.m_index= 0;
142 m_next_pos.m_index= 0;
143}
144
145int table_tlws_by_table::rnd_init(bool scan)
146{
147 m_normalizer= time_normalizer::get(wait_timer);
148 return 0;
149}
150
151int table_tlws_by_table::rnd_next(void)
152{
153 PFS_table_share *table_share;
154
155 for (m_pos.set_at(&m_next_pos);
156 m_pos.m_index < table_share_max;
157 m_pos.m_index++)
158 {
159 table_share= &table_share_array[m_pos.m_index];
160 if (table_share->m_lock.is_populated())
161 {
162 make_row(table_share);
163 m_next_pos.set_after(&m_pos);
164 return 0;
165 }
166 }
167
168 return HA_ERR_END_OF_FILE;
169}
170
171int
172table_tlws_by_table::rnd_pos(const void *pos)
173{
174 PFS_table_share *table_share;
175
176 set_position(pos);
177
178 table_share= &table_share_array[m_pos.m_index];
179 if (table_share->m_lock.is_populated())
180 {
181 make_row(table_share);
182 return 0;
183 }
184
185 return HA_ERR_RECORD_DELETED;
186}
187
188void table_tlws_by_table::make_row(PFS_table_share *share)
189{
190 pfs_lock lock;
191
192 m_row_exists= false;
193
194 share->m_lock.begin_optimistic_lock(&lock);
195
196 if (m_row.m_object.make_row(share))
197 return;
198
199 PFS_table_lock_stat_visitor visitor;
200 PFS_object_iterator::visit_tables(share, & visitor);
201
202 if (! share->m_lock.end_optimistic_lock(&lock))
203 return;
204
205 m_row_exists= true;
206 m_row.m_stat.set(m_normalizer, &visitor.m_stat);
207}
208
209int table_tlws_by_table::read_row_values(TABLE *table,
210 unsigned char *buf,
211 Field **fields,
212 bool read_all)
213{
214 Field *f;
215
216 if (unlikely(! m_row_exists))
217 return HA_ERR_RECORD_DELETED;
218
219 /* Set the null bits */
220 DBUG_ASSERT(table->s->null_bytes == 1);
221 buf[0]= 0;
222
223 for (; (f= *fields) ; fields++)
224 {
225 if (read_all || bitmap_is_set(table->read_set, f->field_index))
226 {
227 switch(f->field_index)
228 {
229 case 0: /* OBJECT_TYPE */
230 case 1: /* SCHEMA_NAME */
231 case 2: /* OBJECT_NAME */
232 m_row.m_object.set_field(f->field_index, f);
233 break;
234 case 3: /* COUNT_STAR */
235 set_field_ulonglong(f, m_row.m_stat.m_all.m_count);
236 break;
237 case 4: /* SUM_TIMER */
238 set_field_ulonglong(f, m_row.m_stat.m_all.m_sum);
239 break;
240 case 5: /* MIN_TIMER */
241 set_field_ulonglong(f, m_row.m_stat.m_all.m_min);
242 break;
243 case 6: /* AVG_TIMER */
244 set_field_ulonglong(f, m_row.m_stat.m_all.m_avg);
245 break;
246 case 7: /* MAX_TIMER */
247 set_field_ulonglong(f, m_row.m_stat.m_all.m_max);
248 break;
249 case 8: /* COUNT_READ */
250 set_field_ulonglong(f, m_row.m_stat.m_all_read.m_count);
251 break;
252 case 9: /* SUM_TIMER_READ */
253 set_field_ulonglong(f, m_row.m_stat.m_all_read.m_sum);
254 break;
255 case 10: /* MIN_TIMER_READ */
256 set_field_ulonglong(f, m_row.m_stat.m_all_read.m_min);
257 break;
258 case 11: /* AVG_TIMER_READ */
259 set_field_ulonglong(f, m_row.m_stat.m_all_read.m_avg);
260 break;
261 case 12: /* MAX_TIMER_READ */
262 set_field_ulonglong(f, m_row.m_stat.m_all_read.m_max);
263 break;
264 case 13: /* COUNT_WRITE */
265 set_field_ulonglong(f, m_row.m_stat.m_all_write.m_count);
266 break;
267 case 14: /* SUM_TIMER_WRITE */
268 set_field_ulonglong(f, m_row.m_stat.m_all_write.m_sum);
269 break;
270 case 15: /* MIN_TIMER_WRITE */
271 set_field_ulonglong(f, m_row.m_stat.m_all_write.m_min);
272 break;
273 case 16: /* AVG_TIMER_WRITE */
274 set_field_ulonglong(f, m_row.m_stat.m_all_write.m_avg);
275 break;
276 case 17: /* MAX_TIMER_WRITE */
277 set_field_ulonglong(f, m_row.m_stat.m_all_write.m_max);
278 break;
279
280 case 18: /* COUNT_READ_NORMAL */
281 set_field_ulonglong(f, m_row.m_stat.m_read_normal.m_count);
282 break;
283 case 19: /* SUM_TIMER_READ_NORMAL */
284 set_field_ulonglong(f, m_row.m_stat.m_read_normal.m_sum);
285 break;
286 case 20: /* MIN_TIMER_READ_NORMAL */
287 set_field_ulonglong(f, m_row.m_stat.m_read_normal.m_min);
288 break;
289 case 21: /* AVG_TIMER_READ_NORMAL */
290 set_field_ulonglong(f, m_row.m_stat.m_read_normal.m_avg);
291 break;
292 case 22: /* MAX_TIMER_READ_NORMAL */
293 set_field_ulonglong(f, m_row.m_stat.m_read_normal.m_max);
294 break;
295
296 case 23: /* COUNT_READ_WITH_SHARED_LOCKS */
297 set_field_ulonglong(f, m_row.m_stat.m_read_with_shared_locks.m_count);
298 break;
299 case 24: /* SUM_TIMER_READ_WITH_SHARED_LOCKS */
300 set_field_ulonglong(f, m_row.m_stat.m_read_with_shared_locks.m_sum);
301 break;
302 case 25: /* MIN_TIMER_READ_WITH_SHARED_LOCKS */
303 set_field_ulonglong(f, m_row.m_stat.m_read_with_shared_locks.m_min);
304 break;
305 case 26: /* AVG_TIMER_READ_WITH_SHARED_LOCKS */
306 set_field_ulonglong(f, m_row.m_stat.m_read_with_shared_locks.m_avg);
307 break;
308 case 27: /* MAX_TIMER_READ_WITH_SHARED_LOCKS */
309 set_field_ulonglong(f, m_row.m_stat.m_read_with_shared_locks.m_max);
310 break;
311
312 case 28: /* COUNT_READ_HIGH_PRIORITY */
313 set_field_ulonglong(f, m_row.m_stat.m_read_high_priority.m_count);
314 break;
315 case 29: /* SUM_TIMER_READ_HIGH_PRIORITY */
316 set_field_ulonglong(f, m_row.m_stat.m_read_high_priority.m_sum);
317 break;
318 case 30: /* MIN_TIMER_READ_HIGH_PRIORITY */
319 set_field_ulonglong(f, m_row.m_stat.m_read_high_priority.m_min);
320 break;
321 case 31: /* AVG_TIMER_READ_HIGH_PRIORITY */
322 set_field_ulonglong(f, m_row.m_stat.m_read_high_priority.m_avg);
323 break;
324 case 32: /* MAX_TIMER_READ_HIGH_PRIORITY */
325 set_field_ulonglong(f, m_row.m_stat.m_read_high_priority.m_max);
326 break;
327
328 case 33: /* COUNT_READ_NO_INSERT */
329 set_field_ulonglong(f, m_row.m_stat.m_read_no_insert.m_count);
330 break;
331 case 34: /* SUM_TIMER_READ_NO_INSERT */
332 set_field_ulonglong(f, m_row.m_stat.m_read_no_insert.m_sum);
333 break;
334 case 35: /* MIN_TIMER_READ_NO_INSERT */
335 set_field_ulonglong(f, m_row.m_stat.m_read_no_insert.m_min);
336 break;
337 case 36: /* AVG_TIMER_READ_NO_INSERT */
338 set_field_ulonglong(f, m_row.m_stat.m_read_no_insert.m_avg);
339 break;
340 case 37: /* MAX_TIMER_READ_NO_INSERT */
341 set_field_ulonglong(f, m_row.m_stat.m_read_no_insert.m_max);
342 break;
343
344 case 38: /* COUNT_READ_EXTERNAL */
345 set_field_ulonglong(f, m_row.m_stat.m_read_external.m_count);
346 break;
347 case 39: /* SUM_TIMER_READ_EXTERNAL */
348 set_field_ulonglong(f, m_row.m_stat.m_read_external.m_sum);
349 break;
350 case 40: /* MIN_TIMER_READ_EXTERNAL */
351 set_field_ulonglong(f, m_row.m_stat.m_read_external.m_min);
352 break;
353 case 41: /* AVG_TIMER_READ_EXTERNAL */
354 set_field_ulonglong(f, m_row.m_stat.m_read_external.m_avg);
355 break;
356 case 42: /* MAX_TIMER_READ_EXTERNAL */
357 set_field_ulonglong(f, m_row.m_stat.m_read_external.m_max);
358 break;
359
360 case 43: /* COUNT_WRITE_ALLOW_WRITE */
361 set_field_ulonglong(f, m_row.m_stat.m_write_allow_write.m_count);
362 break;
363 case 44: /* SUM_TIMER_WRITE_ALLOW_WRITE */
364 set_field_ulonglong(f, m_row.m_stat.m_write_allow_write.m_sum);
365 break;
366 case 45: /* MIN_TIMER_WRITE_ALLOW_WRITE */
367 set_field_ulonglong(f, m_row.m_stat.m_write_allow_write.m_min);
368 break;
369 case 46: /* AVG_TIMER_WRITE_ALLOW_WRITE */
370 set_field_ulonglong(f, m_row.m_stat.m_write_allow_write.m_avg);
371 break;
372 case 47: /* MAX_TIMER_WRITE_ALLOW_WRITE */
373 set_field_ulonglong(f, m_row.m_stat.m_write_allow_write.m_max);
374 break;
375
376 case 48: /* COUNT_WRITE_CONCURRENT_INSERT */
377 set_field_ulonglong(f, m_row.m_stat.m_write_concurrent_insert.m_count);
378 break;
379 case 49: /* SUM_TIMER_WRITE_CONCURRENT_INSERT */
380 set_field_ulonglong(f, m_row.m_stat.m_write_concurrent_insert.m_sum);
381 break;
382 case 50: /* MIN_TIMER_WRITE_CONCURRENT_INSERT */
383 set_field_ulonglong(f, m_row.m_stat.m_write_concurrent_insert.m_min);
384 break;
385 case 51: /* AVG_TIMER_WRITE_CONCURRENT_INSERT */
386 set_field_ulonglong(f, m_row.m_stat.m_write_concurrent_insert.m_avg);
387 break;
388 case 52: /* MAX_TIMER_WRITE_CONCURRENT_INSERT */
389 set_field_ulonglong(f, m_row.m_stat.m_write_concurrent_insert.m_max);
390 break;
391
392 case 53: /* COUNT_WRITE_DELAYED */
393 set_field_ulonglong(f, m_row.m_stat.m_write_delayed.m_count);
394 break;
395 case 54: /* SUM_TIMER_WRITE_DELAYED */
396 set_field_ulonglong(f, m_row.m_stat.m_write_delayed.m_sum);
397 break;
398 case 55: /* MIN_TIMER_WRITE_DELAYED */
399 set_field_ulonglong(f, m_row.m_stat.m_write_delayed.m_min);
400 break;
401 case 56: /* AVG_TIMER_WRITE_DELAYED */
402 set_field_ulonglong(f, m_row.m_stat.m_write_delayed.m_avg);
403 break;
404 case 57: /* MAX_TIMER_WRITE_DELAYED */
405 set_field_ulonglong(f, m_row.m_stat.m_write_delayed.m_max);
406 break;
407
408 case 58: /* COUNT_WRITE_LOW_PRIORITY */
409 set_field_ulonglong(f, m_row.m_stat.m_write_low_priority.m_count);
410 break;
411 case 59: /* SUM_TIMER_WRITE_LOW_PRIORITY */
412 set_field_ulonglong(f, m_row.m_stat.m_write_low_priority.m_sum);
413 break;
414 case 60: /* MIN_TIMER_WRITE_LOW_PRIORITY */
415 set_field_ulonglong(f, m_row.m_stat.m_write_low_priority.m_min);
416 break;
417 case 61: /* AVG_TIMER_WRITE_LOW_PRIORITY */
418 set_field_ulonglong(f, m_row.m_stat.m_write_low_priority.m_avg);
419 break;
420 case 62: /* MAX_TIMER_WRITE_LOW_PRIORITY */
421 set_field_ulonglong(f, m_row.m_stat.m_write_low_priority.m_max);
422 break;
423
424 case 63: /* COUNT_WRITE_NORMAL */
425 set_field_ulonglong(f, m_row.m_stat.m_write_normal.m_count);
426 break;
427 case 64: /* SUM_TIMER_WRITE_NORMAL */
428 set_field_ulonglong(f, m_row.m_stat.m_write_normal.m_sum);
429 break;
430 case 65: /* MIN_TIMER_WRITE_NORMAL */
431 set_field_ulonglong(f, m_row.m_stat.m_write_normal.m_min);
432 break;
433 case 66: /* AVG_TIMER_WRITE_NORMAL */
434 set_field_ulonglong(f, m_row.m_stat.m_write_normal.m_avg);
435 break;
436 case 67: /* MAX_TIMER_WRITE_NORMAL */
437 set_field_ulonglong(f, m_row.m_stat.m_write_normal.m_max);
438 break;
439
440 case 68: /* COUNT_WRITE_EXTERNAL */
441 set_field_ulonglong(f, m_row.m_stat.m_write_external.m_count);
442 break;
443 case 69: /* SUM_TIMER_WRITE_EXTERNAL */
444 set_field_ulonglong(f, m_row.m_stat.m_write_external.m_sum);
445 break;
446 case 70: /* MIN_TIMER_WRITE_EXTERNAL */
447 set_field_ulonglong(f, m_row.m_stat.m_write_external.m_min);
448 break;
449 case 71: /* AVG_TIMER_WRITE_EXTERNAL */
450 set_field_ulonglong(f, m_row.m_stat.m_write_external.m_avg);
451 break;
452 case 72: /* MAX_TIMER_WRITE_EXTERNAL */
453 set_field_ulonglong(f, m_row.m_stat.m_write_external.m_max);
454 break;
455
456 default:
457 DBUG_ASSERT(false);
458 }
459 }
460 }
461
462 return 0;
463}
464
465