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