MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_tiws_by_table.cc
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2011, 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 
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_tiws_by_table.h"
27 #include "pfs_global.h"
28 #include "pfs_visitor.h"
29 
30 THR_LOCK table_tiws_by_table::m_table_lock;
31 
32 static const TABLE_FIELD_TYPE field_types[]=
33 {
34  {
35  { C_STRING_WITH_LEN("OBJECT_TYPE") },
36  { C_STRING_WITH_LEN("varchar(64)") },
37  { NULL, 0}
38  },
39  {
40  { C_STRING_WITH_LEN("OBJECT_SCHEMA") },
41  { C_STRING_WITH_LEN("varchar(64)") },
42  { NULL, 0}
43  },
44  {
45  { C_STRING_WITH_LEN("OBJECT_NAME") },
46  { C_STRING_WITH_LEN("varchar(64)") },
47  { NULL, 0}
48  },
49  {
50  { C_STRING_WITH_LEN("COUNT_STAR") },
51  { C_STRING_WITH_LEN("bigint(20)") },
52  { NULL, 0}
53  },
54  {
55  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
56  { C_STRING_WITH_LEN("bigint(20)") },
57  { NULL, 0}
58  },
59  {
60  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
61  { C_STRING_WITH_LEN("bigint(20)") },
62  { NULL, 0}
63  },
64  {
65  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
66  { C_STRING_WITH_LEN("bigint(20)") },
67  { NULL, 0}
68  },
69  {
70  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
71  { C_STRING_WITH_LEN("bigint(20)") },
72  { NULL, 0}
73  },
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("COUNT_WRITE") },
101  { C_STRING_WITH_LEN("bigint(20)") },
102  { NULL, 0}
103  },
104  {
105  { C_STRING_WITH_LEN("SUM_TIMER_WRITE") },
106  { C_STRING_WITH_LEN("bigint(20)") },
107  { NULL, 0}
108  },
109  {
110  { C_STRING_WITH_LEN("MIN_TIMER_WRITE") },
111  { C_STRING_WITH_LEN("bigint(20)") },
112  { NULL, 0}
113  },
114  {
115  { C_STRING_WITH_LEN("AVG_TIMER_WRITE") },
116  { C_STRING_WITH_LEN("bigint(20)") },
117  { NULL, 0}
118  },
119  {
120  { C_STRING_WITH_LEN("MAX_TIMER_WRITE") },
121  { C_STRING_WITH_LEN("bigint(20)") },
122  { NULL, 0}
123  },
124  {
125  { C_STRING_WITH_LEN("COUNT_FETCH") },
126  { C_STRING_WITH_LEN("bigint(20)") },
127  { NULL, 0}
128  },
129  {
130  { C_STRING_WITH_LEN("SUM_TIMER_FETCH") },
131  { C_STRING_WITH_LEN("bigint(20)") },
132  { NULL, 0}
133  },
134  {
135  { C_STRING_WITH_LEN("MIN_TIMER_FETCH") },
136  { C_STRING_WITH_LEN("bigint(20)") },
137  { NULL, 0}
138  },
139  {
140  { C_STRING_WITH_LEN("AVG_TIMER_FETCH") },
141  { C_STRING_WITH_LEN("bigint(20)") },
142  { NULL, 0}
143  },
144  {
145  { C_STRING_WITH_LEN("MAX_TIMER_FETCH") },
146  { C_STRING_WITH_LEN("bigint(20)") },
147  { NULL, 0}
148  },
149  {
150  { C_STRING_WITH_LEN("COUNT_INSERT") },
151  { C_STRING_WITH_LEN("bigint(20)") },
152  { NULL, 0}
153  },
154  {
155  { C_STRING_WITH_LEN("SUM_TIMER_INSERT") },
156  { C_STRING_WITH_LEN("bigint(20)") },
157  { NULL, 0}
158  },
159  {
160  { C_STRING_WITH_LEN("MIN_TIMER_INSERT") },
161  { C_STRING_WITH_LEN("bigint(20)") },
162  { NULL, 0}
163  },
164  {
165  { C_STRING_WITH_LEN("AVG_TIMER_INSERT") },
166  { C_STRING_WITH_LEN("bigint(20)") },
167  { NULL, 0}
168  },
169  {
170  { C_STRING_WITH_LEN("MAX_TIMER_INSERT") },
171  { C_STRING_WITH_LEN("bigint(20)") },
172  { NULL, 0}
173  },
174  {
175  { C_STRING_WITH_LEN("COUNT_UPDATE") },
176  { C_STRING_WITH_LEN("bigint(20)") },
177  { NULL, 0}
178  },
179  {
180  { C_STRING_WITH_LEN("SUM_TIMER_UPDATE") },
181  { C_STRING_WITH_LEN("bigint(20)") },
182  { NULL, 0}
183  },
184  {
185  { C_STRING_WITH_LEN("MIN_TIMER_UPDATE") },
186  { C_STRING_WITH_LEN("bigint(20)") },
187  { NULL, 0}
188  },
189  {
190  { C_STRING_WITH_LEN("AVG_TIMER_UPDATE") },
191  { C_STRING_WITH_LEN("bigint(20)") },
192  { NULL, 0}
193  },
194  {
195  { C_STRING_WITH_LEN("MAX_TIMER_UPDATE") },
196  { C_STRING_WITH_LEN("bigint(20)") },
197  { NULL, 0}
198  },
199  {
200  { C_STRING_WITH_LEN("COUNT_DELETE") },
201  { C_STRING_WITH_LEN("bigint(20)") },
202  { NULL, 0}
203  },
204  {
205  { C_STRING_WITH_LEN("SUM_TIMER_DELETE") },
206  { C_STRING_WITH_LEN("bigint(20)") },
207  { NULL, 0}
208  },
209  {
210  { C_STRING_WITH_LEN("MIN_TIMER_DELETE") },
211  { C_STRING_WITH_LEN("bigint(20)") },
212  { NULL, 0}
213  },
214  {
215  { C_STRING_WITH_LEN("AVG_TIMER_DELETE") },
216  { C_STRING_WITH_LEN("bigint(20)") },
217  { NULL, 0}
218  },
219  {
220  { C_STRING_WITH_LEN("MAX_TIMER_DELETE") },
221  { C_STRING_WITH_LEN("bigint(20)") },
222  { NULL, 0}
223  }
224 };
225 
227 table_tiws_by_table::m_field_def=
228 { 38, field_types };
229 
232 {
233  { C_STRING_WITH_LEN("table_io_waits_summary_by_table") },
235  table_tiws_by_table::create,
236  NULL, /* write_row */
237  table_tiws_by_table::delete_all_rows,
238  NULL, /* get_row_count */
239  1000, /* records */
240  sizeof(PFS_simple_index),
241  &m_table_lock,
242  &m_field_def,
243  false /* checked */
244 };
245 
247 table_tiws_by_table::create(void)
248 {
249  return new table_tiws_by_table();
250 }
251 
252 int
253 table_tiws_by_table::delete_all_rows(void)
254 {
255  reset_table_io_waits_by_table_handle();
256  reset_table_io_waits_by_table();
257  return 0;
258 }
259 
260 table_tiws_by_table::table_tiws_by_table()
261  : PFS_engine_table(&m_share, &m_pos),
262  m_row_exists(false), m_pos(0), m_next_pos(0)
263 {}
264 
266 {
267  m_pos.m_index= 0;
268  m_next_pos.m_index= 0;
269 }
270 
272 {
274  return 0;
275 }
276 
278 {
279  PFS_table_share *table_share;
280 
281  for (m_pos.set_at(&m_next_pos);
282  m_pos.m_index < table_share_max;
283  m_pos.m_index++)
284  {
285  table_share= &table_share_array[m_pos.m_index];
286  if (table_share->m_lock.is_populated())
287  {
288  make_row(table_share);
289  m_next_pos.set_after(&m_pos);
290  return 0;
291  }
292  }
293 
294  return HA_ERR_END_OF_FILE;
295 }
296 
297 int
299 {
300  PFS_table_share *table_share;
301 
302  set_position(pos);
303 
304  table_share= &table_share_array[m_pos.m_index];
305  if (table_share->m_lock.is_populated())
306  {
307  make_row(table_share);
308  return 0;
309  }
310 
311  return HA_ERR_RECORD_DELETED;
312 }
313 
314 void table_tiws_by_table::make_row(PFS_table_share *share)
315 {
316  pfs_lock lock;
317 
318  m_row_exists= false;
319 
320  share->m_lock.begin_optimistic_lock(&lock);
321 
322  if (m_row.m_object.make_row(share))
323  return;
324 
326  PFS_object_iterator::visit_tables(share, & visitor);
327 
328  if (! share->m_lock.end_optimistic_lock(&lock))
329  return;
330 
331  m_row_exists= true;
332  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
333 }
334 
336  unsigned char *buf,
337  Field **fields,
338  bool read_all)
339 {
340  Field *f;
341 
342  if (unlikely(! m_row_exists))
343  return HA_ERR_RECORD_DELETED;
344 
345  /* Set the null bits */
346  DBUG_ASSERT(table->s->null_bytes == 1);
347  buf[0]= 0;
348 
349  for (; (f= *fields) ; fields++)
350  {
351  if (read_all || bitmap_is_set(table->read_set, f->field_index))
352  {
353  switch(f->field_index)
354  {
355  case 0: /* OBJECT_TYPE */
356  case 1: /* SCHEMA_NAME */
357  case 2: /* OBJECT_NAME */
358  m_row.m_object.set_field(f->field_index, f);
359  break;
360  case 3: /* COUNT_STAR */
361  set_field_ulonglong(f, m_row.m_stat.m_all.m_count);
362  break;
363  case 4: /* SUM */
364  set_field_ulonglong(f, m_row.m_stat.m_all.m_sum);
365  break;
366  case 5: /* MIN */
367  set_field_ulonglong(f, m_row.m_stat.m_all.m_min);
368  break;
369  case 6: /* AVG */
370  set_field_ulonglong(f, m_row.m_stat.m_all.m_avg);
371  break;
372  case 7: /* MAX */
373  set_field_ulonglong(f, m_row.m_stat.m_all.m_max);
374  break;
375  case 8: /* COUNT_READ */
376  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_count);
377  break;
378  case 9: /* SUM_READ */
379  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_sum);
380  break;
381  case 10: /* MIN_READ */
382  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_min);
383  break;
384  case 11: /* AVG_READ */
385  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_avg);
386  break;
387  case 12: /* MAX_READ */
388  set_field_ulonglong(f, m_row.m_stat.m_all_read.m_max);
389  break;
390  case 13: /* COUNT_WRITE */
391  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_count);
392  break;
393  case 14: /* SUM_WRITE */
394  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_sum);
395  break;
396  case 15: /* MIN_WRITE */
397  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_min);
398  break;
399  case 16: /* AVG_WRITE */
400  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_avg);
401  break;
402  case 17: /* MAX_WRITE */
403  set_field_ulonglong(f, m_row.m_stat.m_all_write.m_max);
404  break;
405  case 18: /* COUNT_FETCH */
406  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_count);
407  break;
408  case 19: /* SUM_FETCH */
409  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_sum);
410  break;
411  case 20: /* MIN_FETCH */
412  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_min);
413  break;
414  case 21: /* AVG_FETCH */
415  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_avg);
416  break;
417  case 22: /* MAX_FETCH */
418  set_field_ulonglong(f, m_row.m_stat.m_fetch.m_max);
419  break;
420  case 23: /* COUNT_INSERT */
421  set_field_ulonglong(f, m_row.m_stat.m_insert.m_count);
422  break;
423  case 24: /* SUM_INSERT */
424  set_field_ulonglong(f, m_row.m_stat.m_insert.m_sum);
425  break;
426  case 25: /* MIN_INSERT */
427  set_field_ulonglong(f, m_row.m_stat.m_insert.m_min);
428  break;
429  case 26: /* AVG_INSERT */
430  set_field_ulonglong(f, m_row.m_stat.m_insert.m_avg);
431  break;
432  case 27: /* MAX_INSERT */
433  set_field_ulonglong(f, m_row.m_stat.m_insert.m_max);
434  break;
435  case 28: /* COUNT_UPDATE */
436  set_field_ulonglong(f, m_row.m_stat.m_update.m_count);
437  break;
438  case 29: /* SUM_UPDATE */
439  set_field_ulonglong(f, m_row.m_stat.m_update.m_sum);
440  break;
441  case 30: /* MIN_UPDATE */
442  set_field_ulonglong(f, m_row.m_stat.m_update.m_min);
443  break;
444  case 31: /* AVG_UPDATE */
445  set_field_ulonglong(f, m_row.m_stat.m_update.m_avg);
446  break;
447  case 32: /* MAX_UPDATE */
448  set_field_ulonglong(f, m_row.m_stat.m_update.m_max);
449  break;
450  case 33: /* COUNT_DELETE */
451  set_field_ulonglong(f, m_row.m_stat.m_delete.m_count);
452  break;
453  case 34: /* SUM_DELETE */
454  set_field_ulonglong(f, m_row.m_stat.m_delete.m_sum);
455  break;
456  case 35: /* MIN_DELETE */
457  set_field_ulonglong(f, m_row.m_stat.m_delete.m_min);
458  break;
459  case 36: /* AVG_DELETE */
460  set_field_ulonglong(f, m_row.m_stat.m_delete.m_avg);
461  break;
462  case 37: /* MAX_DELETE */
463  set_field_ulonglong(f, m_row.m_stat.m_delete.m_max);
464  break;
465  default:
466  DBUG_ASSERT(false);
467  }
468  }
469  }
470 
471  return 0;
472 }
473