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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 /**
24 @file storage/perfschema/table_socket_summary_by_instance.cc
25 Table SOCKET_SUMMARY_BY_INSTANCE (implementation).
26 */
27
28 #include "my_global.h"
29 #include "my_pthread.h"
30 #include "pfs_instr.h"
31 #include "pfs_column_types.h"
32 #include "pfs_column_values.h"
33 #include "table_socket_summary_by_instance.h"
34 #include "pfs_global.h"
35
36 THR_LOCK table_socket_summary_by_instance::m_table_lock;
37
38 static const TABLE_FIELD_TYPE field_types[]=
39 {
40 {
41 { C_STRING_WITH_LEN("EVENT_NAME") },
42 { C_STRING_WITH_LEN("varchar(128)") },
43 { NULL, 0}
44 },
45 {
46 { C_STRING_WITH_LEN("OBJECT_INSTANCE_BEGIN") },
47 { C_STRING_WITH_LEN("bigint(20)") },
48 { NULL, 0}
49 },
50 {
51 { C_STRING_WITH_LEN("COUNT_STAR") },
52 { C_STRING_WITH_LEN("bigint(20)") },
53 { NULL, 0}
54 },
55 {
56 { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
57 { C_STRING_WITH_LEN("bigint(20)") },
58 { NULL, 0}
59 },
60 {
61 { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
62 { C_STRING_WITH_LEN("bigint(20)") },
63 { NULL, 0}
64 },
65 {
66 { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
67 { C_STRING_WITH_LEN("bigint(20)") },
68 { NULL, 0}
69 },
70 {
71 { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
72 { C_STRING_WITH_LEN("bigint(20)") },
73 { NULL, 0}
74 },
75
76 /** Read */
77 {
78 { C_STRING_WITH_LEN("COUNT_READ") },
79 { C_STRING_WITH_LEN("bigint(20)") },
80 { NULL, 0}
81 },
82 {
83 { C_STRING_WITH_LEN("SUM_TIMER_READ") },
84 { C_STRING_WITH_LEN("bigint(20)") },
85 { NULL, 0}
86 },
87 {
88 { C_STRING_WITH_LEN("MIN_TIMER_READ") },
89 { C_STRING_WITH_LEN("bigint(20)") },
90 { NULL, 0}
91 },
92 {
93 { C_STRING_WITH_LEN("AVG_TIMER_READ") },
94 { C_STRING_WITH_LEN("bigint(20)") },
95 { NULL, 0}
96 },
97 {
98 { C_STRING_WITH_LEN("MAX_TIMER_READ") },
99 { C_STRING_WITH_LEN("bigint(20)") },
100 { NULL, 0}
101 },
102 {
103 { C_STRING_WITH_LEN("SUM_NUMBER_OF_BYTES_READ") },
104 { C_STRING_WITH_LEN("bigint(20)") },
105 { NULL, 0}
106 },
107
108 /** Write */
109 {
110 { C_STRING_WITH_LEN("COUNT_WRITE") },
111 { C_STRING_WITH_LEN("bigint(20)") },
112 { NULL, 0}
113 },
114 {
115 { C_STRING_WITH_LEN("SUM_TIMER_WRITE") },
116 { C_STRING_WITH_LEN("bigint(20)") },
117 { NULL, 0}
118 },
119 {
120 { C_STRING_WITH_LEN("MIN_TIMER_WRITE") },
121 { C_STRING_WITH_LEN("bigint(20)") },
122 { NULL, 0}
123 },
124 {
125 { C_STRING_WITH_LEN("AVG_TIMER_WRITE") },
126 { C_STRING_WITH_LEN("bigint(20)") },
127 { NULL, 0}
128 },
129 {
130 { C_STRING_WITH_LEN("MAX_TIMER_WRITE") },
131 { C_STRING_WITH_LEN("bigint(20)") },
132 { NULL, 0}
133 },
134 {
135 { C_STRING_WITH_LEN("SUM_NUMBER_OF_BYTES_WRITE") },
136 { C_STRING_WITH_LEN("bigint(20)") },
137 { NULL, 0}
138 },
139
140 /** Misc */
141 {
142 { C_STRING_WITH_LEN("COUNT_MISC") },
143 { C_STRING_WITH_LEN("bigint(20)") },
144 { NULL, 0}
145 },
146 {
147 { C_STRING_WITH_LEN("SUM_TIMER_MISC") },
148 { C_STRING_WITH_LEN("bigint(20)") },
149 { NULL, 0}
150 },
151 {
152 { C_STRING_WITH_LEN("MIN_TIMER_MISC") },
153 { C_STRING_WITH_LEN("bigint(20)") },
154 { NULL, 0}
155 },
156 {
157 { C_STRING_WITH_LEN("AVG_TIMER_MISC") },
158 { C_STRING_WITH_LEN("bigint(20)") },
159 { NULL, 0}
160 },
161 {
162 { C_STRING_WITH_LEN("MAX_TIMER_MISC") },
163 { C_STRING_WITH_LEN("bigint(20)") },
164 { NULL, 0}
165 }
166 };
167
168 TABLE_FIELD_DEF
169 table_socket_summary_by_instance::m_field_def=
170 { 24, field_types };
171
172 PFS_engine_table_share
173 table_socket_summary_by_instance::m_share=
174 {
175 { C_STRING_WITH_LEN("socket_summary_by_instance") },
176 &pfs_readonly_acl,
177 &table_socket_summary_by_instance::create,
178 NULL, /* write_row */
179 table_socket_summary_by_instance::delete_all_rows,
180 NULL, /* get_row_count */
181 1000, /* records */
182 sizeof(PFS_simple_index),
183 &m_table_lock,
184 &m_field_def,
185 false /* checked */
186 };
187
create(void)188 PFS_engine_table* table_socket_summary_by_instance::create(void)
189 {
190 return new table_socket_summary_by_instance();
191 }
192
table_socket_summary_by_instance()193 table_socket_summary_by_instance::table_socket_summary_by_instance()
194 : PFS_engine_table(&m_share, &m_pos),
195 m_row_exists(false), m_pos(0), m_next_pos(0)
196 {}
197
delete_all_rows(void)198 int table_socket_summary_by_instance::delete_all_rows(void)
199 {
200 reset_socket_instance_io();
201 return 0;
202 }
203
reset_position(void)204 void table_socket_summary_by_instance::reset_position(void)
205 {
206 m_pos.m_index= 0;
207 m_next_pos.m_index= 0;
208 }
209
rnd_next(void)210 int table_socket_summary_by_instance::rnd_next(void)
211 {
212 PFS_socket *pfs;
213
214 for (m_pos.set_at(&m_next_pos);
215 m_pos.m_index < socket_max;
216 m_pos.next())
217 {
218 pfs= &socket_array[m_pos.m_index];
219 if (pfs->m_lock.is_populated())
220 {
221 make_row(pfs);
222 m_next_pos.set_after(&m_pos);
223 return 0;
224 }
225 }
226
227 return HA_ERR_END_OF_FILE;
228 }
229
rnd_pos(const void * pos)230 int table_socket_summary_by_instance::rnd_pos(const void *pos)
231 {
232 PFS_socket *pfs;
233
234 set_position(pos);
235 DBUG_ASSERT(m_pos.m_index < socket_max);
236 pfs= &socket_array[m_pos.m_index];
237
238 if (! pfs->m_lock.is_populated())
239 return HA_ERR_RECORD_DELETED;
240
241 make_row(pfs);
242 return 0;
243 }
244
make_row(PFS_socket * pfs)245 void table_socket_summary_by_instance::make_row(PFS_socket *pfs)
246 {
247 pfs_lock lock;
248 PFS_socket_class *safe_class;
249
250 m_row_exists= false;
251
252 /* Protect this reader against a socket delete */
253 pfs->m_lock.begin_optimistic_lock(&lock);
254
255 safe_class= sanitize_socket_class(pfs->m_class);
256 if (unlikely(safe_class == NULL))
257 return;
258
259 m_row.m_event_name.make_row(safe_class);
260 m_row.m_identity= pfs->m_identity;
261
262 time_normalizer *normalizer= time_normalizer::get(wait_timer);
263
264 /* Collect timer and byte count stats */
265 m_row.m_io_stat.set(normalizer, &pfs->m_socket_stat.m_io_stat);
266
267 if (!pfs->m_lock.end_optimistic_lock(&lock))
268 return;
269
270 m_row_exists= true;
271 }
272
read_row_values(TABLE * table,unsigned char *,Field ** fields,bool read_all)273 int table_socket_summary_by_instance::read_row_values(TABLE *table,
274 unsigned char *,
275 Field **fields,
276 bool read_all)
277 {
278 Field *f;
279
280 if (unlikely(!m_row_exists))
281 return HA_ERR_RECORD_DELETED;
282
283 /* Set the null bits */
284 DBUG_ASSERT(table->s->null_bytes == 0);
285
286 for (; (f= *fields) ; fields++)
287 {
288 if (read_all || bitmap_is_set(table->read_set, f->field_index))
289 {
290 switch(f->field_index)
291 {
292 case 0: /* EVENT_NAME */
293 m_row.m_event_name.set_field(f);
294 break;
295 case 1: /* OBJECT_INSTANCE */
296 set_field_ulonglong(f, (ulonglong)m_row.m_identity);
297 break;
298
299 case 2:/* COUNT_STAR */
300 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_count);
301 break;
302 case 3:/* SUM_TIMER_WAIT */
303 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_sum);
304 break;
305 case 4: /* MIN_TIMER_WAIT */
306 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_min);
307 break;
308 case 5: /* AVG_TIMER_WAIT */
309 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_avg);
310 break;
311 case 6: /* MAX_TIMER_WAIT */
312 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_max);
313 break;
314
315 case 7: /* COUNT_READ */
316 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_count);
317 break;
318 case 8: /* SUM_TIMER_READ */
319 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_sum);
320 break;
321 case 9: /* MIN_TIMER_READ */
322 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_min);
323 break;
324 case 10: /* AVG_TIMER_READ */
325 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_avg);
326 break;
327 case 11: /* MAX_TIMER_READ */
328 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_max);
329 break;
330 case 12: /* SUM_NUMBER_OF_BYTES_READ */
331 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_bytes);
332 break;
333
334 case 13: /* COUNT_WRITE */
335 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_count);
336 break;
337 case 14: /* SUM_TIMER_WRITE */
338 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_sum);
339 break;
340 case 15: /* MIN_TIMER_WRITE */
341 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_min);
342 break;
343 case 16: /* AVG_TIMER_WRITE */
344 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_avg);
345 break;
346 case 17: /* MAX_TIMER_WRITE */
347 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_max);
348 break;
349 case 18: /* SUM_NUMBER_OF_BYTES_WRITE */
350 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_bytes);
351 break;
352
353 case 19: /* COUNT_MISC */
354 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_count);
355 break;
356 case 20: /* SUM_TIMER_MISC */
357 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_sum);
358 break;
359 case 21: /* MIN_TIMER_MISC */
360 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_min);
361 break;
362 case 22: /* AVG_TIMER_MISC */
363 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_avg);
364 break;
365 case 23: /* MAX_TIMER_MISC */
366 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_max);
367 break;
368 default:
369 DBUG_ASSERT(false);
370 break;
371 }
372 }
373 }
374
375 return 0;
376 }
377