MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_file_summary_by_instance.cc
1 /* Copyright (c) 2008, 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 Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 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"
27 #include "pfs_global.h"
28 
29 THR_LOCK table_file_summary_by_instance::m_table_lock;
30 
31 static const TABLE_FIELD_TYPE field_types[]=
32 {
33  {
34  { C_STRING_WITH_LEN("FILE_NAME") },
35  { C_STRING_WITH_LEN("varchar(512)") },
36  { NULL, 0}
37  },
38  {
39  { C_STRING_WITH_LEN("EVENT_NAME") },
40  { C_STRING_WITH_LEN("varchar(128)") },
41  { NULL, 0}
42  },
43  {
44  { C_STRING_WITH_LEN("OBJECT_INSTANCE_BEGIN") },
45  { C_STRING_WITH_LEN("bigint(20)") },
46  { NULL, 0}
47  },
48  {
49  { C_STRING_WITH_LEN("COUNT_STAR") },
50  { C_STRING_WITH_LEN("bigint(20)") },
51  { NULL, 0}
52  },
53  {
54  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
55  { C_STRING_WITH_LEN("bigint(20)") },
56  { NULL, 0}
57  },
58  {
59  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
60  { C_STRING_WITH_LEN("bigint(20)") },
61  { NULL, 0}
62  },
63  {
64  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
65  { C_STRING_WITH_LEN("bigint(20)") },
66  { NULL, 0}
67  },
68  {
69  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
70  { C_STRING_WITH_LEN("bigint(20)") },
71  { NULL, 0}
72  },
73 
75  {
76  { C_STRING_WITH_LEN("COUNT_READ") },
77  { C_STRING_WITH_LEN("bigint(20)") },
78  { NULL, 0}
79  },
80  {
81  { C_STRING_WITH_LEN("SUM_TIMER_READ") },
82  { C_STRING_WITH_LEN("bigint(20)") },
83  { NULL, 0}
84  },
85  {
86  { C_STRING_WITH_LEN("MIN_TIMER_READ") },
87  { C_STRING_WITH_LEN("bigint(20)") },
88  { NULL, 0}
89  },
90  {
91  { C_STRING_WITH_LEN("AVG_TIMER_READ") },
92  { C_STRING_WITH_LEN("bigint(20)") },
93  { NULL, 0}
94  },
95  {
96  { C_STRING_WITH_LEN("MAX_TIMER_READ") },
97  { C_STRING_WITH_LEN("bigint(20)") },
98  { NULL, 0}
99  },
100  {
101  { C_STRING_WITH_LEN("SUM_NUMBER_OF_BYTES_READ") },
102  { C_STRING_WITH_LEN("bigint(20)") },
103  { NULL, 0}
104  },
105 
107  {
108  { C_STRING_WITH_LEN("COUNT_WRITE") },
109  { C_STRING_WITH_LEN("bigint(20)") },
110  { NULL, 0}
111  },
112  {
113  { C_STRING_WITH_LEN("SUM_TIMER_WRITE") },
114  { C_STRING_WITH_LEN("bigint(20)") },
115  { NULL, 0}
116  },
117  {
118  { C_STRING_WITH_LEN("MIN_TIMER_WRITE") },
119  { C_STRING_WITH_LEN("bigint(20)") },
120  { NULL, 0}
121  },
122  {
123  { C_STRING_WITH_LEN("AVG_TIMER_WRITE") },
124  { C_STRING_WITH_LEN("bigint(20)") },
125  { NULL, 0}
126  },
127  {
128  { C_STRING_WITH_LEN("MAX_TIMER_WRITE") },
129  { C_STRING_WITH_LEN("bigint(20)") },
130  { NULL, 0}
131  },
132  {
133  { C_STRING_WITH_LEN("SUM_NUMBER_OF_BYTES_WRITE") },
134  { C_STRING_WITH_LEN("bigint(20)") },
135  { NULL, 0}
136  },
137 
139  {
140  { C_STRING_WITH_LEN("COUNT_MISC") },
141  { C_STRING_WITH_LEN("bigint(20)") },
142  { NULL, 0}
143  },
144  {
145  { C_STRING_WITH_LEN("SUM_TIMER_MISC") },
146  { C_STRING_WITH_LEN("bigint(20)") },
147  { NULL, 0}
148  },
149  {
150  { C_STRING_WITH_LEN("MIN_TIMER_MISC") },
151  { C_STRING_WITH_LEN("bigint(20)") },
152  { NULL, 0}
153  },
154  {
155  { C_STRING_WITH_LEN("AVG_TIMER_MISC") },
156  { C_STRING_WITH_LEN("bigint(20)") },
157  { NULL, 0}
158  },
159  {
160  { C_STRING_WITH_LEN("MAX_TIMER_MISC") },
161  { C_STRING_WITH_LEN("bigint(20)") },
162  { NULL, 0}
163  }
164 };
165 
167 table_file_summary_by_instance::m_field_def=
168 { 25, field_types };
169 
172 {
173  { C_STRING_WITH_LEN("file_summary_by_instance") },
175  &table_file_summary_by_instance::create,
176  NULL, /* write_row */
177  table_file_summary_by_instance::delete_all_rows,
178  NULL, /* get_row_count */
179  1000, /* records */
180  sizeof(PFS_simple_index),
181  &m_table_lock,
182  &m_field_def,
183  false /* checked */
184 };
185 
186 PFS_engine_table* table_file_summary_by_instance::create(void)
187 {
188  return new table_file_summary_by_instance();
189 }
190 
191 int table_file_summary_by_instance::delete_all_rows(void)
192 {
194  return 0;
195 }
196 
197 table_file_summary_by_instance::table_file_summary_by_instance()
198  : PFS_engine_table(&m_share, &m_pos),
199  m_row_exists(false), m_pos(0), m_next_pos(0)
200 {}
201 
203 {
204  m_pos.m_index= 0;
205  m_next_pos.m_index= 0;
206 }
207 
209 {
210  PFS_file *pfs;
211 
212  for (m_pos.set_at(&m_next_pos);
213  m_pos.m_index < file_max;
214  m_pos.next())
215  {
216  pfs= &file_array[m_pos.m_index];
217  if (pfs->m_lock.is_populated())
218  {
219  make_row(pfs);
220  m_next_pos.set_after(&m_pos);
221  return 0;
222  }
223  }
224 
225  return HA_ERR_END_OF_FILE;
226 }
227 
229 {
230  PFS_file *pfs;
231 
232  set_position(pos);
233  DBUG_ASSERT(m_pos.m_index < file_max);
234  pfs= &file_array[m_pos.m_index];
235 
236  if (! pfs->m_lock.is_populated())
237  return HA_ERR_RECORD_DELETED;
238 
239  make_row(pfs);
240  return 0;
241 }
242 
247 void table_file_summary_by_instance::make_row(PFS_file *pfs)
248 {
249  pfs_lock lock;
250  PFS_file_class *safe_class;
251 
252  m_row_exists= false;
253 
254  /* Protect this reader against a file delete */
255  pfs->m_lock.begin_optimistic_lock(&lock);
256 
257  safe_class= sanitize_file_class(pfs->m_class);
258  if (unlikely(safe_class == NULL))
259  return;
260 
261  m_row.m_filename= pfs->m_filename;
263  m_row.m_event_name.make_row(safe_class);
264  m_row.m_identity= pfs->m_identity;
265 
267 
268  /* Collect timer and byte count stats */
269  m_row.m_io_stat.set(normalizer, &pfs->m_file_stat.m_io_stat);
270 
271  if (pfs->m_lock.end_optimistic_lock(&lock))
272  m_row_exists= true;
273 }
274 
275 int table_file_summary_by_instance::read_row_values(TABLE *table,
276  unsigned char *,
277  Field **fields,
278  bool read_all)
279 {
280  Field *f;
281 
282  if (unlikely(! m_row_exists))
283  return HA_ERR_RECORD_DELETED;
284 
285  /* Set the null bits */
286  DBUG_ASSERT(table->s->null_bytes == 0);
287 
288  for (; (f= *fields) ; fields++)
289  {
290  if (read_all || bitmap_is_set(table->read_set, f->field_index))
291  {
292  switch(f->field_index)
293  {
294  case 0: /* FILE_NAME */
296  break;
297  case 1: /* EVENT_NAME */
298  m_row.m_event_name.set_field(f);
299  break;
300  case 2: /* OBJECT_INSTANCE */
301  set_field_ulonglong(f, (ulonglong)m_row.m_identity);
302  break;
303 
304  case 3:/* COUNT_STAR */
305  set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_count);
306  break;
307  case 4:/* SUM_TIMER_WAIT */
308  set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_sum);
309  break;
310  case 5: /* MIN_TIMER_WAIT */
311  set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_min);
312  break;
313  case 6: /* AVG_TIMER_WAIT */
314  set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_avg);
315  break;
316  case 7: /* MAX_TIMER_WAIT */
317  set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_max);
318  break;
319 
320  case 8: /* COUNT_READ */
321  set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_count);
322  break;
323  case 9: /* SUM_TIMER_READ */
324  set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_sum);
325  break;
326  case 10: /* MIN_TIMER_READ */
327  set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_min);
328  break;
329  case 11: /* AVG_TIMER_READ */
330  set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_avg);
331  break;
332  case 12: /* MAX_TIMER_READ */
333  set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_max);
334  break;
335  case 13: /* SUM_NUMBER_OF_BYTES_READ */
336  set_field_ulonglong(f, m_row.m_io_stat.m_read.m_bytes);
337  break;
338 
339  case 14: /* COUNT_WRITE */
340  set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_count);
341  break;
342  case 15: /* SUM_TIMER_WRITE */
343  set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_sum);
344  break;
345  case 16: /* MIN_TIMER_WRITE */
346  set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_min);
347  break;
348  case 17: /* AVG_TIMER_WRITE */
349  set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_avg);
350  break;
351  case 18: /* MAX_TIMER_WRITE */
352  set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_max);
353  break;
354  case 19: /* SUM_NUMBER_OF_BYTES_WRITE */
355  set_field_ulonglong(f, m_row.m_io_stat.m_write.m_bytes);
356  break;
357 
358  case 20: /* COUNT_MISC */
359  set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_count);
360  break;
361  case 21: /* SUM_TIMER_MISC */
362  set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_sum);
363  break;
364  case 22: /* MIN_TIMER_MISC */
365  set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_min);
366  break;
367  case 23: /* AVG_TIMER_MISC */
368  set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_avg);
369  break;
370  case 24: /* MAX_TIMER_MISC */
371  set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_max);
372  break;
373  default:
374  DBUG_ASSERT(false);
375  }
376  }
377  }
378 
379  return 0;
380 }
381