MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_events_waits_summary.cc
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2010, 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_events_waits_summary_by_instance::m_table_lock;
30 
31 static const TABLE_FIELD_TYPE ews_by_instance_field_types[]=
32 {
33  {
34  { C_STRING_WITH_LEN("EVENT_NAME") },
35  { C_STRING_WITH_LEN("varchar(128)") },
36  { NULL, 0}
37  },
38  {
39  { C_STRING_WITH_LEN("OBJECT_INSTANCE_BEGIN") },
40  { C_STRING_WITH_LEN("bigint(20)") },
41  { NULL, 0}
42  },
43  {
44  { C_STRING_WITH_LEN("COUNT_STAR") },
45  { C_STRING_WITH_LEN("bigint(20)") },
46  { NULL, 0}
47  },
48  {
49  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
50  { C_STRING_WITH_LEN("bigint(20)") },
51  { NULL, 0}
52  },
53  {
54  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
55  { C_STRING_WITH_LEN("bigint(20)") },
56  { NULL, 0}
57  },
58  {
59  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
60  { C_STRING_WITH_LEN("bigint(20)") },
61  { NULL, 0}
62  },
63  {
64  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
65  { C_STRING_WITH_LEN("bigint(20)") },
66  { NULL, 0}
67  }
68 };
69 
71 table_events_waits_summary_by_instance::m_field_def=
72 { 7, ews_by_instance_field_types };
73 
76 {
77  { C_STRING_WITH_LEN("events_waits_summary_by_instance") },
79  &table_events_waits_summary_by_instance::create,
80  NULL, /* write_row */
81  &table_events_waits_summary_by_instance::delete_all_rows,
82  NULL, /* get_row_count */
83  1000, /* records */
84  sizeof(pos_all_instr),
85  &m_table_lock,
86  &m_field_def,
87  false /* checked */
88 };
89 
90 PFS_engine_table* table_events_waits_summary_by_instance::create(void)
91 {
93 }
94 
95 int table_events_waits_summary_by_instance::delete_all_rows(void)
96 {
98  return 0;
99 }
100 
101 table_events_waits_summary_by_instance
102 ::table_events_waits_summary_by_instance()
103  : table_all_instr(&m_share), m_row_exists(false)
104 {}
105 
106 void table_events_waits_summary_by_instance
107 ::make_instr_row(PFS_instr *pfs, PFS_instr_class *klass,
108  const void *object_instance_begin,
109  PFS_single_stat *pfs_stat)
110 {
111  pfs_lock lock;
112  m_row_exists= false;
113 
114  /*
115  Protect this reader against a mutex/rwlock/cond destroy,
116  file delete, table drop.
117  */
118  pfs->m_lock.begin_optimistic_lock(&lock);
119 
120  m_row.m_name= klass->m_name;
121  m_row.m_name_length= klass->m_name_length;
122  m_row.m_object_instance_addr= (intptr) object_instance_begin;
123 
124  get_normalizer(klass);
125  m_row.m_stat.set(m_normalizer, pfs_stat);
126 
127  if (pfs->m_lock.end_optimistic_lock(&lock))
128  m_row_exists= true;
129 }
130 
136 {
137  PFS_mutex_class *safe_class;
138  safe_class= sanitize_mutex_class(pfs->m_class);
139  if (unlikely(safe_class == NULL))
140  return;
141 
142  make_instr_row(pfs, safe_class, pfs->m_identity, &pfs->m_mutex_stat.m_wait_stat);
143 }
144 
150 {
151  PFS_rwlock_class *safe_class;
152  safe_class= sanitize_rwlock_class(pfs->m_class);
153  if (unlikely(safe_class == NULL))
154  return;
155 
156  make_instr_row(pfs, safe_class, pfs->m_identity, &pfs->m_rwlock_stat.m_wait_stat);
157 }
158 
164 {
165  PFS_cond_class *safe_class;
166  safe_class= sanitize_cond_class(pfs->m_class);
167  if (unlikely(safe_class == NULL))
168  return;
169 
170  make_instr_row(pfs, safe_class, pfs->m_identity, &pfs->m_cond_stat.m_wait_stat);
171 }
172 
178 {
179  PFS_file_class *safe_class;
180  safe_class= sanitize_file_class(pfs->m_class);
181  if (unlikely(safe_class == NULL))
182  return;
183 
184  PFS_single_stat sum;
185  pfs->m_file_stat.m_io_stat.sum_waits(& sum);
186  /*
187  Files don't have a in memory structure associated to it,
188  so we use the address of the PFS_file buffer as object_instance_begin
189  */
190  make_instr_row(pfs, safe_class, pfs, & sum);
191 }
192 
198 {
199  PFS_socket_class *safe_class;
200  safe_class= sanitize_socket_class(pfs->m_class);
201  if (unlikely(safe_class == NULL))
202  return;
203 
204  /*
205  Consolidate wait times and byte counts for individual operations. This is
206  done by the consumer in order to reduce overhead on the socket instrument.
207  */
208  PFS_byte_stat pfs_stat;
209  pfs->m_socket_stat.m_io_stat.sum(&pfs_stat);
210 
211  /*
212  Sockets don't have an associated in-memory structure, so use the address of
213  the PFS_socket buffer as object_instance_begin.
214  */
215  make_instr_row(pfs, safe_class, pfs, &pfs_stat);
216 }
217 
219 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
220  bool read_all)
221 {
222  Field *f;
223 
224  if (unlikely(! m_row_exists))
225  return HA_ERR_RECORD_DELETED;
226 
227  /* Set the null bits */
228  DBUG_ASSERT(table->s->null_bytes == 0);
229 
230  for (; (f= *fields) ; fields++)
231  {
232  if (read_all || bitmap_is_set(table->read_set, f->field_index))
233  {
234  switch(f->field_index)
235  {
236  case 0: /* NAME */
237  set_field_varchar_utf8(f, m_row.m_name, m_row.m_name_length);
238  break;
239  case 1: /* OBJECT_INSTANCE */
240  set_field_ulonglong(f, m_row.m_object_instance_addr);
241  break;
242  case 2: /* COUNT */
243  set_field_ulonglong(f, m_row.m_stat.m_count);
244  break;
245  case 3: /* SUM */
246  set_field_ulonglong(f, m_row.m_stat.m_sum);
247  break;
248  case 4: /* MIN */
249  set_field_ulonglong(f, m_row.m_stat.m_min);
250  break;
251  case 5: /* AVG */
252  set_field_ulonglong(f, m_row.m_stat.m_avg);
253  break;
254  case 6: /* MAX */
255  set_field_ulonglong(f, m_row.m_stat.m_max);
256  break;
257  default:
258  DBUG_ASSERT(false);
259  }
260  }
261  }
262 
263  return 0;
264 }
265