1 | /* Copyright (c) 2010, 2012, 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 |
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ |
15 | |
16 | /** |
17 | @file storage/perfschema/table_ews_by_host_by_event_name.cc |
18 | Table EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME (implementation). |
19 | */ |
20 | |
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" |
26 | #include "table_ews_by_host_by_event_name.h" |
27 | #include "pfs_global.h" |
28 | #include "pfs_account.h" |
29 | #include "pfs_visitor.h" |
30 | |
31 | THR_LOCK table_ews_by_host_by_event_name::m_table_lock; |
32 | |
33 | PFS_engine_table_share |
34 | table_ews_by_host_by_event_name::m_share= |
35 | { |
36 | { C_STRING_WITH_LEN("events_waits_summary_by_host_by_event_name" ) }, |
37 | &pfs_truncatable_acl, |
38 | table_ews_by_host_by_event_name::create, |
39 | NULL, /* write_row */ |
40 | table_ews_by_host_by_event_name::delete_all_rows, |
41 | NULL, /* get_row_count */ |
42 | 1000, /* records */ |
43 | sizeof(pos_ews_by_host_by_event_name), |
44 | &m_table_lock, |
45 | { C_STRING_WITH_LEN("CREATE TABLE events_waits_summary_by_host_by_event_name(" |
46 | "HOST CHAR(60) collate utf8_bin default null," |
47 | "EVENT_NAME VARCHAR(128) not null," |
48 | "COUNT_STAR BIGINT unsigned not null," |
49 | "SUM_TIMER_WAIT BIGINT unsigned not null," |
50 | "MIN_TIMER_WAIT BIGINT unsigned not null," |
51 | "AVG_TIMER_WAIT BIGINT unsigned not null," |
52 | "MAX_TIMER_WAIT BIGINT unsigned not null)" ) } |
53 | }; |
54 | |
55 | PFS_engine_table* |
56 | table_ews_by_host_by_event_name::create(void) |
57 | { |
58 | return new table_ews_by_host_by_event_name(); |
59 | } |
60 | |
61 | int |
62 | table_ews_by_host_by_event_name::delete_all_rows(void) |
63 | { |
64 | reset_events_waits_by_thread(); |
65 | reset_events_waits_by_account(); |
66 | reset_events_waits_by_host(); |
67 | return 0; |
68 | } |
69 | |
70 | table_ews_by_host_by_event_name::table_ews_by_host_by_event_name() |
71 | : PFS_engine_table(&m_share, &m_pos), |
72 | m_row_exists(false), m_pos(), m_next_pos() |
73 | {} |
74 | |
75 | void table_ews_by_host_by_event_name::reset_position(void) |
76 | { |
77 | m_pos.reset(); |
78 | m_next_pos.reset(); |
79 | } |
80 | |
81 | int table_ews_by_host_by_event_name::rnd_next(void) |
82 | { |
83 | PFS_host *host; |
84 | PFS_instr_class *instr_class; |
85 | |
86 | for (m_pos.set_at(&m_next_pos); |
87 | m_pos.has_more_host(); |
88 | m_pos.next_host()) |
89 | { |
90 | host= &host_array[m_pos.m_index_1]; |
91 | if (host->m_lock.is_populated()) |
92 | { |
93 | for ( ; |
94 | m_pos.has_more_view(); |
95 | m_pos.next_view()) |
96 | { |
97 | switch (m_pos.m_index_2) |
98 | { |
99 | case pos_ews_by_host_by_event_name::VIEW_MUTEX: |
100 | instr_class= find_mutex_class(m_pos.m_index_3); |
101 | break; |
102 | case pos_ews_by_host_by_event_name::VIEW_RWLOCK: |
103 | instr_class= find_rwlock_class(m_pos.m_index_3); |
104 | break; |
105 | case pos_ews_by_host_by_event_name::VIEW_COND: |
106 | instr_class= find_cond_class(m_pos.m_index_3); |
107 | break; |
108 | case pos_ews_by_host_by_event_name::VIEW_FILE: |
109 | instr_class= find_file_class(m_pos.m_index_3); |
110 | break; |
111 | case pos_ews_by_host_by_event_name::VIEW_TABLE: |
112 | instr_class= find_table_class(m_pos.m_index_3); |
113 | break; |
114 | case pos_ews_by_host_by_event_name::VIEW_SOCKET: |
115 | instr_class= find_socket_class(m_pos.m_index_3); |
116 | break; |
117 | case pos_ews_by_host_by_event_name::VIEW_IDLE: |
118 | instr_class= find_idle_class(m_pos.m_index_3); |
119 | break; |
120 | default: |
121 | instr_class= NULL; |
122 | DBUG_ASSERT(false); |
123 | break; |
124 | } |
125 | |
126 | if (instr_class) |
127 | { |
128 | make_row(host, instr_class); |
129 | m_next_pos.set_after(&m_pos); |
130 | return 0; |
131 | } |
132 | } |
133 | } |
134 | } |
135 | |
136 | return HA_ERR_END_OF_FILE; |
137 | } |
138 | |
139 | int |
140 | table_ews_by_host_by_event_name::rnd_pos(const void *pos) |
141 | { |
142 | PFS_host *host; |
143 | PFS_instr_class *instr_class; |
144 | |
145 | set_position(pos); |
146 | DBUG_ASSERT(m_pos.m_index_1 < host_max); |
147 | |
148 | host= &host_array[m_pos.m_index_1]; |
149 | if (! host->m_lock.is_populated()) |
150 | return HA_ERR_RECORD_DELETED; |
151 | |
152 | switch (m_pos.m_index_2) |
153 | { |
154 | case pos_ews_by_host_by_event_name::VIEW_MUTEX: |
155 | instr_class= find_mutex_class(m_pos.m_index_3); |
156 | break; |
157 | case pos_ews_by_host_by_event_name::VIEW_RWLOCK: |
158 | instr_class= find_rwlock_class(m_pos.m_index_3); |
159 | break; |
160 | case pos_ews_by_host_by_event_name::VIEW_COND: |
161 | instr_class= find_cond_class(m_pos.m_index_3); |
162 | break; |
163 | case pos_ews_by_host_by_event_name::VIEW_FILE: |
164 | instr_class= find_file_class(m_pos.m_index_3); |
165 | break; |
166 | case pos_ews_by_host_by_event_name::VIEW_TABLE: |
167 | instr_class= find_table_class(m_pos.m_index_3); |
168 | break; |
169 | case pos_ews_by_host_by_event_name::VIEW_SOCKET: |
170 | instr_class= find_socket_class(m_pos.m_index_3); |
171 | break; |
172 | case pos_ews_by_host_by_event_name::VIEW_IDLE: |
173 | instr_class= find_idle_class(m_pos.m_index_3); |
174 | break; |
175 | default: |
176 | instr_class= NULL; |
177 | DBUG_ASSERT(false); |
178 | break; |
179 | } |
180 | if (instr_class) |
181 | { |
182 | make_row(host, instr_class); |
183 | return 0; |
184 | } |
185 | |
186 | return HA_ERR_RECORD_DELETED; |
187 | } |
188 | |
189 | void table_ews_by_host_by_event_name |
190 | ::make_row(PFS_host *host, PFS_instr_class *klass) |
191 | { |
192 | pfs_lock lock; |
193 | m_row_exists= false; |
194 | |
195 | host->m_lock.begin_optimistic_lock(&lock); |
196 | |
197 | if (m_row.m_host.make_row(host)) |
198 | return; |
199 | |
200 | m_row.m_event_name.make_row(klass); |
201 | |
202 | PFS_connection_wait_visitor visitor(klass); |
203 | PFS_connection_iterator::visit_host(host, true, true, & visitor); |
204 | |
205 | if (! host->m_lock.end_optimistic_lock(&lock)) |
206 | return; |
207 | |
208 | m_row_exists= true; |
209 | |
210 | get_normalizer(klass); |
211 | m_row.m_stat.set(m_normalizer, &visitor.m_stat); |
212 | } |
213 | |
214 | int table_ews_by_host_by_event_name |
215 | ::read_row_values(TABLE *table, unsigned char *buf, Field **fields, |
216 | bool read_all) |
217 | { |
218 | Field *f; |
219 | |
220 | if (unlikely(! m_row_exists)) |
221 | return HA_ERR_RECORD_DELETED; |
222 | |
223 | /* Set the null bits */ |
224 | DBUG_ASSERT(table->s->null_bytes == 1); |
225 | buf[0]= 0; |
226 | |
227 | for (; (f= *fields) ; fields++) |
228 | { |
229 | if (read_all || bitmap_is_set(table->read_set, f->field_index)) |
230 | { |
231 | switch(f->field_index) |
232 | { |
233 | case 0: /* HOST */ |
234 | m_row.m_host.set_field(f); |
235 | break; |
236 | case 1: /* EVENT_NAME */ |
237 | m_row.m_event_name.set_field(f); |
238 | break; |
239 | default: /* 2, ... COUNT/SUM/MIN/AVG/MAX */ |
240 | m_row.m_stat.set_field(f->field_index - 2, f); |
241 | break; |
242 | } |
243 | } |
244 | } |
245 | |
246 | return 0; |
247 | } |
248 | |
249 | |