MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_esms_by_thread_by_event_name.cc
Go to the documentation of this file.
1 /* Copyright (c) 2010, 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
14  Foundation, Inc., 51 Franklin St, 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_esms_by_thread_by_event_name::m_table_lock;
31 
32 static const TABLE_FIELD_TYPE field_types[]=
33 {
34  {
35  { C_STRING_WITH_LEN("THREAD_ID") },
36  { C_STRING_WITH_LEN("bigint(20)") },
37  { NULL, 0}
38  },
39  {
40  { C_STRING_WITH_LEN("EVENT_NAME") },
41  { C_STRING_WITH_LEN("varchar(128)") },
42  { NULL, 0}
43  },
44  {
45  { C_STRING_WITH_LEN("COUNT_STAR") },
46  { C_STRING_WITH_LEN("bigint(20)") },
47  { NULL, 0}
48  },
49  {
50  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
51  { C_STRING_WITH_LEN("bigint(20)") },
52  { NULL, 0}
53  },
54  {
55  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
56  { C_STRING_WITH_LEN("bigint(20)") },
57  { NULL, 0}
58  },
59  {
60  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
61  { C_STRING_WITH_LEN("bigint(20)") },
62  { NULL, 0}
63  },
64  {
65  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
66  { C_STRING_WITH_LEN("bigint(20)") },
67  { NULL, 0}
68  },
69  {
70  { C_STRING_WITH_LEN("SUM_LOCK_TIME") },
71  { C_STRING_WITH_LEN("bigint(20)") },
72  { NULL, 0}
73  },
74  {
75  { C_STRING_WITH_LEN("SUM_ERRORS") },
76  { C_STRING_WITH_LEN("bigint(20)") },
77  { NULL, 0}
78  },
79  {
80  { C_STRING_WITH_LEN("SUM_WARNINGS") },
81  { C_STRING_WITH_LEN("bigint(20)") },
82  { NULL, 0}
83  },
84  {
85  { C_STRING_WITH_LEN("SUM_ROWS_AFFECTED") },
86  { C_STRING_WITH_LEN("bigint(20)") },
87  { NULL, 0}
88  },
89  {
90  { C_STRING_WITH_LEN("SUM_ROWS_SENT") },
91  { C_STRING_WITH_LEN("bigint(20)") },
92  { NULL, 0}
93  },
94  {
95  { C_STRING_WITH_LEN("SUM_ROWS_EXAMINED") },
96  { C_STRING_WITH_LEN("bigint(20)") },
97  { NULL, 0}
98  },
99  {
100  { C_STRING_WITH_LEN("SUM_CREATED_TMP_DISK_TABLES") },
101  { C_STRING_WITH_LEN("bigint(20)") },
102  { NULL, 0}
103  },
104  {
105  { C_STRING_WITH_LEN("SUM_CREATED_TMP_TABLES") },
106  { C_STRING_WITH_LEN("bigint(20)") },
107  { NULL, 0}
108  },
109  {
110  { C_STRING_WITH_LEN("SUM_SELECT_FULL_JOIN") },
111  { C_STRING_WITH_LEN("bigint(20)") },
112  { NULL, 0}
113  },
114  {
115  { C_STRING_WITH_LEN("SUM_SELECT_FULL_RANGE_JOIN") },
116  { C_STRING_WITH_LEN("bigint(20)") },
117  { NULL, 0}
118  },
119  {
120  { C_STRING_WITH_LEN("SUM_SELECT_RANGE") },
121  { C_STRING_WITH_LEN("bigint(20)") },
122  { NULL, 0}
123  },
124  {
125  { C_STRING_WITH_LEN("SUM_SELECT_RANGE_CHECK") },
126  { C_STRING_WITH_LEN("bigint(20)") },
127  { NULL, 0}
128  },
129  {
130  { C_STRING_WITH_LEN("SUM_SELECT_SCAN") },
131  { C_STRING_WITH_LEN("bigint(20)") },
132  { NULL, 0}
133  },
134  {
135  { C_STRING_WITH_LEN("SUM_SORT_MERGE_PASSES") },
136  { C_STRING_WITH_LEN("bigint(20)") },
137  { NULL, 0}
138  },
139  {
140  { C_STRING_WITH_LEN("SUM_SORT_RANGE") },
141  { C_STRING_WITH_LEN("bigint(20)") },
142  { NULL, 0}
143  },
144  {
145  { C_STRING_WITH_LEN("SUM_SORT_ROWS") },
146  { C_STRING_WITH_LEN("bigint(20)") },
147  { NULL, 0}
148  },
149  {
150  { C_STRING_WITH_LEN("SUM_SORT_SCAN") },
151  { C_STRING_WITH_LEN("bigint(20)") },
152  { NULL, 0}
153  },
154  {
155  { C_STRING_WITH_LEN("SUM_NO_INDEX_USED") },
156  { C_STRING_WITH_LEN("bigint(20)") },
157  { NULL, 0}
158  },
159  {
160  { C_STRING_WITH_LEN("SUM_NO_GOOD_INDEX_USED") },
161  { C_STRING_WITH_LEN("bigint(20)") },
162  { NULL, 0}
163  }
164 };
165 
167 table_esms_by_thread_by_event_name::m_field_def=
168 { 26, field_types };
169 
172 {
173  { C_STRING_WITH_LEN("events_statements_summary_by_thread_by_event_name") },
175  table_esms_by_thread_by_event_name::create,
176  NULL, /* write_row */
177  table_esms_by_thread_by_event_name::delete_all_rows,
178  NULL, /* get_row_count */
179  1000, /* records */
181  &m_table_lock,
182  &m_field_def,
183  false /* checked */
184 };
185 
187 table_esms_by_thread_by_event_name::create(void)
188 {
190 }
191 
192 int
193 table_esms_by_thread_by_event_name::delete_all_rows(void)
194 {
196  return 0;
197 }
198 
199 table_esms_by_thread_by_event_name::table_esms_by_thread_by_event_name()
200  : PFS_engine_table(&m_share, &m_pos),
201  m_row_exists(false), m_pos(), m_next_pos()
202 {}
203 
205 {
206  m_pos.reset();
207  m_next_pos.reset();
208 }
209 
211 {
213  return 0;
214 }
215 
217 {
218  PFS_thread *thread;
219  PFS_statement_class *statement_class;
220 
221  for (m_pos.set_at(&m_next_pos);
222  m_pos.has_more_thread();
223  m_pos.next_thread())
224  {
225  thread= &thread_array[m_pos.m_index_1];
226 
227  /*
228  Important note: the thread scan is the outer loop (index 1),
229  to minimize the number of calls to atomic operations.
230  */
231  if (thread->m_lock.is_populated())
232  {
233  statement_class= find_statement_class(m_pos.m_index_2);
234  if (statement_class)
235  {
236  make_row(thread, statement_class);
237  m_next_pos.set_after(&m_pos);
238  return 0;
239  }
240  }
241  }
242 
243  return HA_ERR_END_OF_FILE;
244 }
245 
246 int
248 {
249  PFS_thread *thread;
250  PFS_statement_class *statement_class;
251 
252  set_position(pos);
253  DBUG_ASSERT(m_pos.m_index_1 < thread_max);
254 
255  thread= &thread_array[m_pos.m_index_1];
256  if (! thread->m_lock.is_populated())
257  return HA_ERR_RECORD_DELETED;
258 
259  statement_class= find_statement_class(m_pos.m_index_2);
260  if (statement_class)
261  {
262  make_row(thread, statement_class);
263  return 0;
264  }
265 
266  return HA_ERR_RECORD_DELETED;
267 }
268 
269 void table_esms_by_thread_by_event_name
270 ::make_row(PFS_thread *thread, PFS_statement_class *klass)
271 {
272  pfs_lock lock;
273  m_row_exists= false;
274 
275  /* Protect this reader against a thread termination */
276  thread->m_lock.begin_optimistic_lock(&lock);
277 
279 
280  m_row.m_event_name.make_row(klass);
281 
282  PFS_connection_statement_visitor visitor(klass);
283  PFS_connection_iterator::visit_thread(thread, & visitor);
284 
285  if (! thread->m_lock.end_optimistic_lock(&lock))
286  return;
287 
288  m_row_exists= true;
289  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
290 }
291 
293 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
294  bool read_all)
295 {
296  Field *f;
297 
298  if (unlikely(! m_row_exists))
299  return HA_ERR_RECORD_DELETED;
300 
301  /* Set the null bits */
302  DBUG_ASSERT(table->s->null_bytes == 0);
303 
304  for (; (f= *fields) ; fields++)
305  {
306  if (read_all || bitmap_is_set(table->read_set, f->field_index))
307  {
308  switch(f->field_index)
309  {
310  case 0: /* THREAD_ID */
311  set_field_ulonglong(f, m_row.m_thread_internal_id);
312  break;
313  case 1: /* EVENT_NAME */
314  m_row.m_event_name.set_field(f);
315  break;
316  default: /* 2, ... COUNT/SUM/MIN/AVG/MAX */
317  m_row.m_stat.set_field(f->field_index - 2, f);
318  break;
319  }
320  }
321  }
322 
323  return 0;
324 }
325