MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_ews_by_host_by_event_name.cc
Go to the documentation of this file.
1 /* Copyright (c) 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
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #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 static const TABLE_FIELD_TYPE field_types[]=
34 {
35  {
36  { C_STRING_WITH_LEN("HOST") },
37  { C_STRING_WITH_LEN("char(60)") },
38  { NULL, 0}
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("COUNT_STAR") },
47  { C_STRING_WITH_LEN("bigint(20)") },
48  { NULL, 0}
49  },
50  {
51  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
52  { C_STRING_WITH_LEN("bigint(20)") },
53  { NULL, 0}
54  },
55  {
56  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
57  { C_STRING_WITH_LEN("bigint(20)") },
58  { NULL, 0}
59  },
60  {
61  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
62  { C_STRING_WITH_LEN("bigint(20)") },
63  { NULL, 0}
64  },
65  {
66  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
67  { C_STRING_WITH_LEN("bigint(20)") },
68  { NULL, 0}
69  }
70 };
71 
73 table_ews_by_host_by_event_name::m_field_def=
74 { 7, field_types };
75 
78 {
79  { C_STRING_WITH_LEN("events_waits_summary_by_host_by_event_name") },
81  table_ews_by_host_by_event_name::create,
82  NULL, /* write_row */
83  table_ews_by_host_by_event_name::delete_all_rows,
84  NULL, /* get_row_count */
85  1000, /* records */
87  &m_table_lock,
88  &m_field_def,
89  false /* checked */
90 };
91 
93 table_ews_by_host_by_event_name::create(void)
94 {
96 }
97 
98 int
99 table_ews_by_host_by_event_name::delete_all_rows(void)
100 {
104  return 0;
105 }
106 
107 table_ews_by_host_by_event_name::table_ews_by_host_by_event_name()
108  : PFS_engine_table(&m_share, &m_pos),
109  m_row_exists(false), m_pos(), m_next_pos()
110 {}
111 
113 {
114  m_pos.reset();
115  m_next_pos.reset();
116 }
117 
119 {
120  PFS_host *host;
121  PFS_instr_class *instr_class;
122 
123  for (m_pos.set_at(&m_next_pos);
124  m_pos.has_more_host();
125  m_pos.next_host())
126  {
127  host= &host_array[m_pos.m_index_1];
128  if (host->m_lock.is_populated())
129  {
130  for ( ;
131  m_pos.has_more_view();
132  m_pos.next_view())
133  {
134  switch (m_pos.m_index_2)
135  {
136  case pos_ews_by_host_by_event_name::VIEW_MUTEX:
137  instr_class= find_mutex_class(m_pos.m_index_3);
138  break;
139  case pos_ews_by_host_by_event_name::VIEW_RWLOCK:
140  instr_class= find_rwlock_class(m_pos.m_index_3);
141  break;
142  case pos_ews_by_host_by_event_name::VIEW_COND:
143  instr_class= find_cond_class(m_pos.m_index_3);
144  break;
145  case pos_ews_by_host_by_event_name::VIEW_FILE:
146  instr_class= find_file_class(m_pos.m_index_3);
147  break;
148  case pos_ews_by_host_by_event_name::VIEW_TABLE:
149  instr_class= find_table_class(m_pos.m_index_3);
150  break;
151  case pos_ews_by_host_by_event_name::VIEW_SOCKET:
152  instr_class= find_socket_class(m_pos.m_index_3);
153  break;
154  case pos_ews_by_host_by_event_name::VIEW_IDLE:
155  instr_class= find_idle_class(m_pos.m_index_3);
156  break;
157  default:
158  instr_class= NULL;
159  DBUG_ASSERT(false);
160  break;
161  }
162 
163  if (instr_class)
164  {
165  make_row(host, instr_class);
166  m_next_pos.set_after(&m_pos);
167  return 0;
168  }
169  }
170  }
171  }
172 
173  return HA_ERR_END_OF_FILE;
174 }
175 
176 int
178 {
179  PFS_host *host;
180  PFS_instr_class *instr_class;
181 
182  set_position(pos);
183  DBUG_ASSERT(m_pos.m_index_1 < host_max);
184 
185  host= &host_array[m_pos.m_index_1];
186  if (! host->m_lock.is_populated())
187  return HA_ERR_RECORD_DELETED;
188 
189  switch (m_pos.m_index_2)
190  {
191  case pos_ews_by_host_by_event_name::VIEW_MUTEX:
192  instr_class= find_mutex_class(m_pos.m_index_3);
193  break;
194  case pos_ews_by_host_by_event_name::VIEW_RWLOCK:
195  instr_class= find_rwlock_class(m_pos.m_index_3);
196  break;
197  case pos_ews_by_host_by_event_name::VIEW_COND:
198  instr_class= find_cond_class(m_pos.m_index_3);
199  break;
200  case pos_ews_by_host_by_event_name::VIEW_FILE:
201  instr_class= find_file_class(m_pos.m_index_3);
202  break;
203  case pos_ews_by_host_by_event_name::VIEW_TABLE:
204  instr_class= find_table_class(m_pos.m_index_3);
205  break;
206  case pos_ews_by_host_by_event_name::VIEW_SOCKET:
207  instr_class= find_socket_class(m_pos.m_index_3);
208  break;
209  case pos_ews_by_host_by_event_name::VIEW_IDLE:
210  instr_class= find_idle_class(m_pos.m_index_3);
211  break;
212  default:
213  instr_class= NULL;
214  DBUG_ASSERT(false);
215  break;
216  }
217  if (instr_class)
218  {
219  make_row(host, instr_class);
220  return 0;
221  }
222 
223  return HA_ERR_RECORD_DELETED;
224 }
225 
226 void table_ews_by_host_by_event_name
227 ::make_row(PFS_host *host, PFS_instr_class *klass)
228 {
229  pfs_lock lock;
230  m_row_exists= false;
231 
232  host->m_lock.begin_optimistic_lock(&lock);
233 
234  if (m_row.m_host.make_row(host))
235  return;
236 
237  m_row.m_event_name.make_row(klass);
238 
239  PFS_connection_wait_visitor visitor(klass);
240  PFS_connection_iterator::visit_host(host, true, true, & visitor);
241 
242  if (! host->m_lock.end_optimistic_lock(&lock))
243  return;
244 
245  m_row_exists= true;
246 
247  get_normalizer(klass);
248  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
249 }
250 
252 ::read_row_values(TABLE *table, unsigned char *buf, Field **fields,
253  bool read_all)
254 {
255  Field *f;
256 
257  if (unlikely(! m_row_exists))
258  return HA_ERR_RECORD_DELETED;
259 
260  /* Set the null bits */
261  DBUG_ASSERT(table->s->null_bytes == 1);
262  buf[0]= 0;
263 
264  for (; (f= *fields) ; fields++)
265  {
266  if (read_all || bitmap_is_set(table->read_set, f->field_index))
267  {
268  switch(f->field_index)
269  {
270  case 0: /* HOST */
271  m_row.m_host.set_field(f);
272  break;
273  case 1: /* EVENT_NAME */
274  m_row.m_event_name.set_field(f);
275  break;
276  default: /* 2, ... COUNT/SUM/MIN/AVG/MAX */
277  m_row.m_stat.set_field(f->field_index - 2, f);
278  break;
279  }
280  }
281  }
282 
283  return 0;
284 }
285