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
16/**
17 @file storage/perfschema/table_socket_summary_by_event_name.cc
18 Table SOCKET_EVENT_NAMES (implementation).
19*/
20
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"
26#include "table_socket_summary_by_event_name.h"
27#include "pfs_global.h"
28#include "pfs_visitor.h"
29
30THR_LOCK table_socket_summary_by_event_name::m_table_lock;
31
32PFS_engine_table_share
33table_socket_summary_by_event_name::m_share=
34{
35 { C_STRING_WITH_LEN("socket_summary_by_event_name") },
36 &pfs_readonly_acl,
37 &table_socket_summary_by_event_name::create,
38 NULL, /* write_row */
39 table_socket_summary_by_event_name::delete_all_rows,
40 NULL, /* get_row_count */
41 1000, /* records */
42 sizeof(PFS_simple_index),
43 &m_table_lock,
44 { C_STRING_WITH_LEN("CREATE TABLE socket_summary_by_event_name("
45 "EVENT_NAME VARCHAR(128) not null,"
46 "COUNT_STAR BIGINT unsigned not null,"
47 "SUM_TIMER_WAIT BIGINT unsigned not null,"
48 "MIN_TIMER_WAIT BIGINT unsigned not null,"
49 "AVG_TIMER_WAIT BIGINT unsigned not null,"
50 "MAX_TIMER_WAIT BIGINT unsigned not null,"
51 "COUNT_READ BIGINT unsigned not null,"
52 "SUM_TIMER_READ BIGINT unsigned not null,"
53 "MIN_TIMER_READ BIGINT unsigned not null,"
54 "AVG_TIMER_READ BIGINT unsigned not null,"
55 "MAX_TIMER_READ BIGINT unsigned not null,"
56 "SUM_NUMBER_OF_BYTES_READ BIGINT unsigned not null,"
57 "COUNT_WRITE BIGINT unsigned not null,"
58 "SUM_TIMER_WRITE BIGINT unsigned not null,"
59 "MIN_TIMER_WRITE BIGINT unsigned not null,"
60 "AVG_TIMER_WRITE BIGINT unsigned not null,"
61 "MAX_TIMER_WRITE BIGINT unsigned not null,"
62 "SUM_NUMBER_OF_BYTES_WRITE BIGINT unsigned not null,"
63 "COUNT_MISC BIGINT unsigned not null,"
64 "SUM_TIMER_MISC BIGINT unsigned not null,"
65 "MIN_TIMER_MISC BIGINT unsigned not null,"
66 "AVG_TIMER_MISC BIGINT unsigned not null,"
67 "MAX_TIMER_MISC BIGINT unsigned not null)") }
68};
69
70PFS_engine_table* table_socket_summary_by_event_name::create(void)
71{
72 return new table_socket_summary_by_event_name();
73}
74
75table_socket_summary_by_event_name::table_socket_summary_by_event_name()
76 : PFS_engine_table(&m_share, &m_pos),
77 m_row_exists(false), m_pos(1), m_next_pos(1)
78{}
79
80int table_socket_summary_by_event_name::delete_all_rows(void)
81{
82 reset_socket_instance_io();
83 reset_socket_class_io();
84 return 0;
85}
86
87void table_socket_summary_by_event_name::reset_position(void)
88{
89 m_pos.m_index= 1;
90 m_next_pos.m_index= 1;
91}
92
93int table_socket_summary_by_event_name::rnd_next(void)
94{
95 PFS_socket_class *socket_class;
96
97 m_pos.set_at(&m_next_pos);
98
99 socket_class= find_socket_class(m_pos.m_index);
100 if (socket_class)
101 {
102 make_row(socket_class);
103 m_next_pos.set_after(&m_pos);
104 return 0;
105 }
106
107 return HA_ERR_END_OF_FILE;
108}
109
110int table_socket_summary_by_event_name::rnd_pos(const void *pos)
111{
112 PFS_socket_class *socket_class;
113
114 set_position(pos);
115
116 socket_class= find_socket_class(m_pos.m_index);
117 if (socket_class)
118 {
119 make_row(socket_class);
120 return 0;
121 }
122
123 return HA_ERR_RECORD_DELETED;
124}
125
126void table_socket_summary_by_event_name::make_row(PFS_socket_class *socket_class)
127{
128 m_row.m_event_name.make_row(socket_class);
129
130 PFS_instance_socket_io_stat_visitor visitor;
131 PFS_instance_iterator::visit_socket_instances(socket_class, &visitor);
132
133 time_normalizer *normalizer= time_normalizer::get(wait_timer);
134
135 /* Collect timer and byte count stats */
136 m_row.m_io_stat.set(normalizer, &visitor.m_socket_io_stat);
137 m_row_exists= true;
138}
139
140int table_socket_summary_by_event_name::read_row_values(TABLE *table,
141 unsigned char *,
142 Field **fields,
143 bool read_all)
144{
145 Field *f;
146
147 if (unlikely(!m_row_exists))
148 return HA_ERR_RECORD_DELETED;
149
150 /* Set the null bits */
151 DBUG_ASSERT(table->s->null_bytes == 0);
152
153 for (; (f= *fields) ; fields++)
154 {
155 if (read_all || bitmap_is_set(table->read_set, f->field_index))
156 {
157 switch(f->field_index)
158 {
159 case 0: /* EVENT_NAME */
160 m_row.m_event_name.set_field(f);
161 break;
162 case 1: /* COUNT_STAR */
163 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_count);
164 break;
165 case 2: /* SUM_TIMER_WAIT */
166 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_sum);
167 break;
168 case 3: /* MIN_TIMER_WAIT */
169 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_min);
170 break;
171 case 4: /* AVG_TIMER_WAIT */
172 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_avg);
173 break;
174 case 5: /* MAX_TIMER_WAIT */
175 set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_max);
176 break;
177
178 case 6: /* COUNT_READ */
179 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_count);
180 break;
181 case 7: /* SUM_TIMER_READ */
182 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_sum);
183 break;
184 case 8: /* MIN_TIMER_READ */
185 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_min);
186 break;
187 case 9: /* AVG_TIMER_READ */
188 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_avg);
189 break;
190 case 10: /* MAX_TIMER_READ */
191 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_max);
192 break;
193 case 11: /* SUM_NUMBER_OF_BYTES_READ */
194 set_field_ulonglong(f, m_row.m_io_stat.m_read.m_bytes);
195 break;
196
197 case 12: /* COUNT_WRITE */
198 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_count);
199 break;
200 case 13: /* SUM_TIMER_WRITE */
201 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_sum);
202 break;
203 case 14: /* MIN_TIMER_WRITE */
204 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_min);
205 break;
206 case 15: /* AVG_TIMER_WRITE */
207 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_avg);
208 break;
209 case 16: /* MAX_TIMER_WRITE */
210 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_max);
211 break;
212 case 17: /* SUM_NUMBER_OF_BYTES_WRITE */
213 set_field_ulonglong(f, m_row.m_io_stat.m_write.m_bytes);
214 break;
215
216 case 18: /* COUNT_MISC */
217 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_count);
218 break;
219 case 19: /* SUM_TIMER_MISC */
220 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_sum);
221 break;
222 case 20: /* MIN_TIMER_MISC */
223 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_min);
224 break;
225 case 21: /* AVG_TIMER_MISC */
226 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_avg);
227 break;
228 case 22: /* MAX_TIMER_MISC */
229 set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_max);
230 break;
231
232 default:
233 DBUG_ASSERT(false);
234 break;
235 }
236 } // if
237 } // for
238
239 return 0;
240}
241
242