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