MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_ews_global_by_event_name.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 St, 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"
27 #include "pfs_global.h"
28 #include "pfs_instr.h"
29 #include "pfs_timer.h"
30 #include "pfs_visitor.h"
31 
32 THR_LOCK table_ews_global_by_event_name::m_table_lock;
33 
34 static const TABLE_FIELD_TYPE field_types[]=
35 {
36  {
37  { C_STRING_WITH_LEN("EVENT_NAME") },
38  { C_STRING_WITH_LEN("varchar(128)") },
39  { NULL, 0}
40  },
41  {
42  { C_STRING_WITH_LEN("COUNT_STAR") },
43  { C_STRING_WITH_LEN("bigint(20)") },
44  { NULL, 0}
45  },
46  {
47  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
48  { C_STRING_WITH_LEN("bigint(20)") },
49  { NULL, 0}
50  },
51  {
52  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
53  { C_STRING_WITH_LEN("bigint(20)") },
54  { NULL, 0}
55  },
56  {
57  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
58  { C_STRING_WITH_LEN("bigint(20)") },
59  { NULL, 0}
60  },
61  {
62  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
63  { C_STRING_WITH_LEN("bigint(20)") },
64  { NULL, 0}
65  }
66 };
67 
69 table_ews_global_by_event_name::m_field_def=
70 { 6, field_types };
71 
74 {
75  { C_STRING_WITH_LEN("events_waits_summary_global_by_event_name") },
77  table_ews_global_by_event_name::create,
78  NULL, /* write_row */
79  table_ews_global_by_event_name::delete_all_rows,
80  NULL, /* get_row_count */
81  1000, /* records */
83  &m_table_lock,
84  &m_field_def,
85  false /* checked */
86 };
87 
89 table_ews_global_by_event_name::create(void)
90 {
91  return new table_ews_global_by_event_name();
92 }
93 
94 int
95 table_ews_global_by_event_name::delete_all_rows(void)
96 {
98  reset_table_waits_by_table_handle();
99  reset_table_waits_by_table();
101  return 0;
102 }
103 
104 table_ews_global_by_event_name::table_ews_global_by_event_name()
105  : PFS_engine_table(&m_share, &m_pos),
106  m_row_exists(false), m_pos(), m_next_pos()
107 {}
108 
110 {
111  m_pos.reset();
112  m_next_pos.reset();
113 }
114 
116 {
117  PFS_mutex_class *mutex_class;
118  PFS_rwlock_class *rwlock_class;
119  PFS_cond_class *cond_class;
120  PFS_file_class *file_class;
121  PFS_socket_class *socket_class;
122  PFS_instr_class *instr_class;
123 
124  for (m_pos.set_at(&m_next_pos);
125  m_pos.has_more_view();
126  m_pos.next_view())
127  {
128  switch (m_pos.m_index_1)
129  {
130  case pos_ews_global_by_event_name::VIEW_MUTEX:
131  mutex_class= find_mutex_class(m_pos.m_index_2);
132  if (mutex_class)
133  {
134  make_mutex_row(mutex_class);
135  m_next_pos.set_after(&m_pos);
136  return 0;
137  }
138  break;
139  case pos_ews_global_by_event_name::VIEW_RWLOCK:
140  rwlock_class= find_rwlock_class(m_pos.m_index_2);
141  if (rwlock_class)
142  {
143  make_rwlock_row(rwlock_class);
144  m_next_pos.set_after(&m_pos);
145  return 0;
146  }
147  break;
148  case pos_ews_global_by_event_name::VIEW_COND:
149  cond_class= find_cond_class(m_pos.m_index_2);
150  if (cond_class)
151  {
152  make_cond_row(cond_class);
153  m_next_pos.set_after(&m_pos);
154  return 0;
155  }
156  break;
157  case pos_ews_global_by_event_name::VIEW_FILE:
158  file_class= find_file_class(m_pos.m_index_2);
159  if (file_class)
160  {
161  make_file_row(file_class);
162  m_next_pos.set_after(&m_pos);
163  return 0;
164  }
165  break;
166  case pos_ews_global_by_event_name::VIEW_TABLE:
167  if (m_pos.m_index_2 == 1)
168  {
169  make_table_io_row(&global_table_io_class);
170  m_next_pos.set_after(&m_pos);
171  return 0;
172  }
173  if (m_pos.m_index_2 == 2)
174  {
175  make_table_lock_row(&global_table_lock_class);
176  m_next_pos.set_after(&m_pos);
177  return 0;
178  }
179  break;
180  case pos_ews_global_by_event_name::VIEW_SOCKET:
181  socket_class= find_socket_class(m_pos.m_index_2);
182  if (socket_class)
183  {
184  make_socket_row(socket_class);
185  m_next_pos.set_after(&m_pos);
186  return 0;
187  }
188  break;
189  case pos_ews_global_by_event_name::VIEW_IDLE:
190  instr_class= find_idle_class(m_pos.m_index_2);
191  if (instr_class)
192  {
193  make_idle_row(instr_class);
194  m_next_pos.set_after(&m_pos);
195  return 0;
196  }
197  break;
198  default:
199  break;
200  }
201  }
202 
203  return HA_ERR_END_OF_FILE;
204 }
205 
206 int
208 {
209  PFS_mutex_class *mutex_class;
210  PFS_rwlock_class *rwlock_class;
211  PFS_cond_class *cond_class;
212  PFS_file_class *file_class;
213  PFS_socket_class *socket_class;
214  PFS_instr_class *instr_class;
215 
216  set_position(pos);
217 
218  switch (m_pos.m_index_1)
219  {
220  case pos_ews_global_by_event_name::VIEW_MUTEX:
221  mutex_class= find_mutex_class(m_pos.m_index_2);
222  if (mutex_class)
223  {
224  make_mutex_row(mutex_class);
225  return 0;
226  }
227  break;
228  case pos_ews_global_by_event_name::VIEW_RWLOCK:
229  rwlock_class= find_rwlock_class(m_pos.m_index_2);
230  if (rwlock_class)
231  {
232  make_rwlock_row(rwlock_class);
233  return 0;
234  }
235  break;
236  case pos_ews_global_by_event_name::VIEW_COND:
237  cond_class= find_cond_class(m_pos.m_index_2);
238  if (cond_class)
239  {
240  make_cond_row(cond_class);
241  return 0;
242  }
243  break;
244  case pos_ews_global_by_event_name::VIEW_FILE:
245  file_class= find_file_class(m_pos.m_index_2);
246  if (file_class)
247  {
248  make_file_row(file_class);
249  return 0;
250  }
251  break;
252  case pos_ews_global_by_event_name::VIEW_TABLE:
253  DBUG_ASSERT(m_pos.m_index_2 >= 1);
254  DBUG_ASSERT(m_pos.m_index_2 <= 2);
255  if (m_pos.m_index_2 == 1)
256  make_table_io_row(&global_table_io_class);
257  else
258  make_table_lock_row(&global_table_lock_class);
259  break;
260  case pos_ews_global_by_event_name::VIEW_SOCKET:
261  socket_class= find_socket_class(m_pos.m_index_2);
262  if (socket_class)
263  {
264  make_socket_row(socket_class);
265  return 0;
266  }
267  break;
268  case pos_ews_global_by_event_name::VIEW_IDLE:
269  instr_class= find_idle_class(m_pos.m_index_2);
270  if (instr_class)
271  {
272  make_idle_row(instr_class);
273  return 0;
274  }
275  break;
276  }
277 
278  return HA_ERR_RECORD_DELETED;
279 }
280 
281 void table_ews_global_by_event_name
282 ::make_mutex_row(PFS_mutex_class *klass)
283 {
284  m_row.m_event_name.make_row(klass);
285 
288 
289  get_normalizer(klass);
290  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
291  m_row_exists= true;
292 }
293 
294 void table_ews_global_by_event_name
295 ::make_rwlock_row(PFS_rwlock_class *klass)
296 {
297  m_row.m_event_name.make_row(klass);
298 
301 
302  get_normalizer(klass);
303  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
304  m_row_exists= true;
305 }
306 
307 void table_ews_global_by_event_name
308 ::make_cond_row(PFS_cond_class *klass)
309 {
310  m_row.m_event_name.make_row(klass);
311 
314 
315  get_normalizer(klass);
316  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
317  m_row_exists= true;
318 }
319 
320 void table_ews_global_by_event_name
321 ::make_file_row(PFS_file_class *klass)
322 {
323  m_row.m_event_name.make_row(klass);
324 
327 
328  get_normalizer(klass);
329  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
330  m_row_exists= true;
331 }
332 
333 void table_ews_global_by_event_name
334 ::make_table_io_row(PFS_instr_class *klass)
335 {
336  m_row.m_event_name.make_row(klass);
337 
340 
341  get_normalizer(klass);
342  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
343  m_row_exists= true;
344 }
345 
346 void table_ews_global_by_event_name
347 ::make_table_lock_row(PFS_instr_class *klass)
348 {
349  m_row.m_event_name.make_row(klass);
350 
353 
354  get_normalizer(klass);
355  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
356  m_row_exists= true;
357 }
358 
359 void table_ews_global_by_event_name
360 ::make_socket_row(PFS_socket_class *klass)
361 {
362  m_row.m_event_name.make_row(klass);
363 
366 
367  get_normalizer(klass);
368  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
369  m_row_exists= true;
370 }
371 
372 void table_ews_global_by_event_name
373 ::make_idle_row(PFS_instr_class *klass)
374 {
375  m_row.m_event_name.make_row(klass);
376 
377  PFS_connection_wait_visitor visitor(klass);
378  PFS_connection_iterator::visit_global(false, /* hosts */
379  false, /* users */
380  false, /* accts */
381  true, /* threads */ &visitor);
382  get_normalizer(klass);
383  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
384  m_row_exists= true;
385 }
386 
388 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
389  bool read_all)
390 {
391  Field *f;
392 
393  if (unlikely(! m_row_exists))
394  return HA_ERR_RECORD_DELETED;
395 
396  /* Set the null bits */
397  DBUG_ASSERT(table->s->null_bytes == 0);
398 
399  for (; (f= *fields) ; fields++)
400  {
401  if (read_all || bitmap_is_set(table->read_set, f->field_index))
402  {
403  switch(f->field_index)
404  {
405  case 0: /* EVENT_NAME */
406  m_row.m_event_name.set_field(f);
407  break;
408  default: /* 1, ... COUNT/SUM/MIN/AVG/MAX */
409  m_row.m_stat.set_field(f->field_index - 1, f);
410  break;
411  }
412  }
413  }
414 
415  return 0;
416 }
417