MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_events_stages.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 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 "table_events_stages.h"
24 #include "pfs_instr_class.h"
25 #include "pfs_instr.h"
26 #include "pfs_events_stages.h"
27 #include "pfs_timer.h"
28 
29 THR_LOCK table_events_stages_current::m_table_lock;
30 
31 static const TABLE_FIELD_TYPE field_types[]=
32 {
33  {
34  { C_STRING_WITH_LEN("THREAD_ID") },
35  { C_STRING_WITH_LEN("bigint(20)") },
36  { NULL, 0}
37  },
38  {
39  { C_STRING_WITH_LEN("EVENT_ID") },
40  { C_STRING_WITH_LEN("bigint(20)") },
41  { NULL, 0}
42  },
43  {
44  { C_STRING_WITH_LEN("END_EVENT_ID") },
45  { C_STRING_WITH_LEN("bigint(20)") },
46  { NULL, 0}
47  },
48  {
49  { C_STRING_WITH_LEN("EVENT_NAME") },
50  { C_STRING_WITH_LEN("varchar(128)") },
51  { NULL, 0}
52  },
53  {
54  { C_STRING_WITH_LEN("SOURCE") },
55  { C_STRING_WITH_LEN("varchar(64)") },
56  { NULL, 0}
57  },
58  {
59  { C_STRING_WITH_LEN("TIMER_START") },
60  { C_STRING_WITH_LEN("bigint(20)") },
61  { NULL, 0}
62  },
63  {
64  { C_STRING_WITH_LEN("TIMER_END") },
65  { C_STRING_WITH_LEN("bigint(20)") },
66  { NULL, 0}
67  },
68  {
69  { C_STRING_WITH_LEN("TIMER_WAIT") },
70  { C_STRING_WITH_LEN("bigint(20)") },
71  { NULL, 0}
72  },
73  {
74  { C_STRING_WITH_LEN("NESTING_EVENT_ID") },
75  { C_STRING_WITH_LEN("bigint(20)") },
76  { NULL, 0}
77  },
78  {
79  { C_STRING_WITH_LEN("NESTING_EVENT_TYPE") },
80  { C_STRING_WITH_LEN("enum(\'STATEMENT\',\'STAGE\',\'WAIT\'") },
81  { NULL, 0}
82  }
83 };
84 
86 table_events_stages_current::m_field_def=
87 {10 , field_types };
88 
91 {
92  { C_STRING_WITH_LEN("events_stages_current") },
94  &table_events_stages_current::create,
95  NULL, /* write_row */
96  &table_events_stages_current::delete_all_rows,
97  NULL, /* get_row_count */
98  1000, /* records */
99  sizeof(PFS_simple_index), /* ref length */
100  &m_table_lock,
101  &m_field_def,
102  false /* checked */
103 };
104 
105 THR_LOCK table_events_stages_history::m_table_lock;
106 
109 {
110  { C_STRING_WITH_LEN("events_stages_history") },
112  &table_events_stages_history::create,
113  NULL, /* write_row */
114  &table_events_stages_history::delete_all_rows,
115  NULL, /* get_row_count */
116  1000, /* records */
117  sizeof(pos_events_stages_history), /* ref length */
118  &m_table_lock,
119  &table_events_stages_current::m_field_def,
120  false /* checked */
121 };
122 
123 THR_LOCK table_events_stages_history_long::m_table_lock;
124 
127 {
128  { C_STRING_WITH_LEN("events_stages_history_long") },
130  &table_events_stages_history_long::create,
131  NULL, /* write_row */
132  &table_events_stages_history_long::delete_all_rows,
133  NULL, /* get_row_count */
134  10000, /* records */
135  sizeof(PFS_simple_index), /* ref length */
136  &m_table_lock,
137  &table_events_stages_current::m_field_def,
138  false /* checked */
139 };
140 
141 table_events_stages_common::table_events_stages_common
142 (const PFS_engine_table_share *share, void *pos)
143  : PFS_engine_table(share, pos),
144  m_row_exists(false)
145 {}
146 
152 {
153  const char *base;
154  const char *safe_source_file;
155 
156  m_row_exists= false;
157 
158  PFS_stage_class *unsafe= (PFS_stage_class*) stage->m_class;
159  PFS_stage_class *klass= sanitize_stage_class(unsafe);
160  if (unlikely(klass == NULL))
161  return;
162 
164  m_row.m_event_id= stage->m_event_id;
168 
171 
172  m_row.m_name= klass->m_name;
173  m_row.m_name_length= klass->m_name_length;
174 
175  safe_source_file= stage->m_source_file;
176  if (unlikely(safe_source_file == NULL))
177  return;
178 
179  base= base_name(safe_source_file);
180  m_row.m_source_length= my_snprintf(m_row.m_source, sizeof(m_row.m_source),
181  "%s:%d", base, stage->m_source_line);
182  if (m_row.m_source_length > sizeof(m_row.m_source))
184 
185  m_row_exists= true;
186  return;
187 }
188 
190  unsigned char *buf,
191  Field **fields,
192  bool read_all)
193 {
194  Field *f;
195 
196  if (unlikely(! m_row_exists))
197  return HA_ERR_RECORD_DELETED;
198 
199  /* Set the null bits */
200  DBUG_ASSERT(table->s->null_bytes == 1);
201  buf[0]= 0;
202 
203  for (; (f= *fields) ; fields++)
204  {
205  if (read_all || bitmap_is_set(table->read_set, f->field_index))
206  {
207  switch(f->field_index)
208  {
209  case 0: /* THREAD_ID */
211  break;
212  case 1: /* EVENT_ID */
214  break;
215  case 2: /* END_EVENT_ID */
216  if (m_row.m_end_event_id > 0)
218  else
219  f->set_null();
220  break;
221  case 3: /* EVENT_NAME */
223  break;
224  case 4: /* SOURCE */
226  break;
227  case 5: /* TIMER_START */
228  if (m_row.m_timer_start != 0)
230  else
231  f->set_null();
232  break;
233  case 6: /* TIMER_END */
234  if (m_row.m_timer_end != 0)
236  else
237  f->set_null();
238  break;
239  case 7: /* TIMER_WAIT */
240  if (m_row.m_timer_wait != 0)
242  else
243  f->set_null();
244  break;
245  case 8: /* NESTING_EVENT_ID */
246  if (m_row.m_nesting_event_id != 0)
248  else
249  f->set_null();
250  break;
251  case 9: /* NESTING_EVENT_TYPE */
252  if (m_row.m_nesting_event_id != 0)
254  else
255  f->set_null();
256  break;
257  default:
258  DBUG_ASSERT(false);
259  }
260  }
261  }
262  return 0;
263 }
264 
265 PFS_engine_table* table_events_stages_current::create(void)
266 {
267  return new table_events_stages_current();
268 }
269 
270 table_events_stages_current::table_events_stages_current()
271  : table_events_stages_common(&m_share, &m_pos),
272  m_pos(0), m_next_pos(0)
273 {}
274 
276 {
277  m_pos.m_index= 0;
278  m_next_pos.m_index= 0;
279 }
280 
282 {
284  return 0;
285 }
286 
288 {
289  PFS_thread *pfs_thread;
290  PFS_events_stages *stage;
291 
292  for (m_pos.set_at(&m_next_pos);
293  m_pos.m_index < thread_max;
294  m_pos.next())
295  {
296  pfs_thread= &thread_array[m_pos.m_index];
297 
298  if (! pfs_thread->m_lock.is_populated())
299  {
300  /* This thread does not exist */
301  continue;
302  }
303 
304  stage= &pfs_thread->m_stage_current;
305 
306  make_row(stage);
307  m_next_pos.set_after(&m_pos);
308  return 0;
309  }
310 
311  return HA_ERR_END_OF_FILE;
312 }
313 
315 {
316  PFS_thread *pfs_thread;
317  PFS_events_stages *stage;
318 
319  set_position(pos);
320  DBUG_ASSERT(m_pos.m_index < thread_max);
321  pfs_thread= &thread_array[m_pos.m_index];
322 
323  if (! pfs_thread->m_lock.is_populated())
324  return HA_ERR_RECORD_DELETED;
325 
326  stage= &pfs_thread->m_stage_current;
327  make_row(stage);
328  return 0;
329 }
330 
331 int table_events_stages_current::delete_all_rows(void)
332 {
334  return 0;
335 }
336 
337 PFS_engine_table* table_events_stages_history::create(void)
338 {
339  return new table_events_stages_history();
340 }
341 
342 table_events_stages_history::table_events_stages_history()
343  : table_events_stages_common(&m_share, &m_pos),
344  m_pos(), m_next_pos()
345 {}
346 
348 {
349  m_pos.reset();
350  m_next_pos.reset();
351 }
352 
354 {
356  return 0;
357 }
358 
360 {
361  PFS_thread *pfs_thread;
362  PFS_events_stages *stage;
363 
365  return HA_ERR_END_OF_FILE;
366 
367  for (m_pos.set_at(&m_next_pos);
368  m_pos.m_index_1 < thread_max;
369  m_pos.next_thread())
370  {
371  pfs_thread= &thread_array[m_pos.m_index_1];
372 
373  if (! pfs_thread->m_lock.is_populated())
374  {
375  /* This thread does not exist */
376  continue;
377  }
378 
380  {
381  /* This thread does not have more (full) history */
382  continue;
383  }
384 
385  if ( ! pfs_thread->m_stages_history_full &&
386  (m_pos.m_index_2 >= pfs_thread->m_stages_history_index))
387  {
388  /* This thread does not have more (not full) history */
389  continue;
390  }
391 
392  stage= &pfs_thread->m_stages_history[m_pos.m_index_2];
393 
394  if (stage->m_class != NULL)
395  {
396  make_row(stage);
397  /* Next iteration, look for the next history in this thread */
398  m_next_pos.set_after(&m_pos);
399  return 0;
400  }
401  }
402 
403  return HA_ERR_END_OF_FILE;
404 }
405 
407 {
408  PFS_thread *pfs_thread;
409  PFS_events_stages *stage;
410 
411  DBUG_ASSERT(events_stages_history_per_thread != 0);
412  set_position(pos);
413  DBUG_ASSERT(m_pos.m_index_1 < thread_max);
414  pfs_thread= &thread_array[m_pos.m_index_1];
415 
416  if (! pfs_thread->m_lock.is_populated())
417  return HA_ERR_RECORD_DELETED;
418 
419  DBUG_ASSERT(m_pos.m_index_2 < events_stages_history_per_thread);
420 
421  if ( ! pfs_thread->m_stages_history_full &&
422  (m_pos.m_index_2 >= pfs_thread->m_stages_history_index))
423  return HA_ERR_RECORD_DELETED;
424 
425  stage= &pfs_thread->m_stages_history[m_pos.m_index_2];
426 
427  if (stage->m_class == NULL)
428  return HA_ERR_RECORD_DELETED;
429 
430  make_row(stage);
431  return 0;
432 }
433 
434 int table_events_stages_history::delete_all_rows(void)
435 {
437  return 0;
438 }
439 
440 PFS_engine_table* table_events_stages_history_long::create(void)
441 {
443 }
444 
445 table_events_stages_history_long::table_events_stages_history_long()
446  : table_events_stages_common(&m_share, &m_pos),
447  m_pos(0), m_next_pos(0)
448 {}
449 
451 {
452  m_pos.m_index= 0;
453  m_next_pos.m_index= 0;
454 }
455 
457 {
459  return 0;
460 }
461 
463 {
464  PFS_events_stages *stage;
465  uint limit;
466 
467  if (events_stages_history_long_size == 0)
468  return HA_ERR_END_OF_FILE;
469 
471  limit= events_stages_history_long_size;
472  else
473  limit= events_stages_history_long_index % events_stages_history_long_size;
474 
475  for (m_pos.set_at(&m_next_pos); m_pos.m_index < limit; m_pos.next())
476  {
478 
479  if (stage->m_class != NULL)
480  {
481  make_row(stage);
482  /* Next iteration, look for the next entry */
483  m_next_pos.set_after(&m_pos);
484  return 0;
485  }
486  }
487 
488  return HA_ERR_END_OF_FILE;
489 }
490 
492 {
493  PFS_events_stages *stage;
494  uint limit;
495 
496  if (events_stages_history_long_size == 0)
497  return HA_ERR_RECORD_DELETED;
498 
499  set_position(pos);
500 
502  limit= events_stages_history_long_size;
503  else
504  limit= events_stages_history_long_index % events_stages_history_long_size;
505 
506  if (m_pos.m_index > limit)
507  return HA_ERR_RECORD_DELETED;
508 
510 
511  if (stage->m_class == NULL)
512  return HA_ERR_RECORD_DELETED;
513 
514  make_row(stage);
515  return 0;
516 }
517 
518 int table_events_stages_history_long::delete_all_rows(void)
519 {
521  return 0;
522 }
523