MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_ews_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_ews_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 
72 table_ews_by_thread_by_event_name::m_field_def=
73 { 7, field_types };
74 
77 {
78  { C_STRING_WITH_LEN("events_waits_summary_by_thread_by_event_name") },
80  table_ews_by_thread_by_event_name::create,
81  NULL, /* write_row */
82  table_ews_by_thread_by_event_name::delete_all_rows,
83  NULL, /* get_row_count */
84  1000, /* records */
86  &m_table_lock,
87  &m_field_def,
88  false /* checked */
89 };
90 
92 table_ews_by_thread_by_event_name::create(void)
93 {
95 }
96 
97 int
98 table_ews_by_thread_by_event_name::delete_all_rows(void)
99 {
101  return 0;
102 }
103 
104 table_ews_by_thread_by_event_name::table_ews_by_thread_by_event_name()
105  : PFS_engine_table(&m_share, &m_pos),
106  m_row_exists(false), m_pos(), m_next_pos()
107 {}
108 
110 {
111  m_pos.reset();
112  m_next_pos.reset();
113 }
114 
116 {
117  PFS_thread *thread;
118  PFS_instr_class *instr_class;
119 
120  for (m_pos.set_at(&m_next_pos);
121  m_pos.has_more_thread();
122  m_pos.next_thread())
123  {
124  thread= &thread_array[m_pos.m_index_1];
125 
126  /*
127  Important note: the thread scan is the outer loop (index 1),
128  to minimize the number of calls to atomic operations.
129  */
130  if (thread->m_lock.is_populated())
131  {
132  for ( ;
133  m_pos.has_more_view();
134  m_pos.next_view())
135  {
136  switch (m_pos.m_index_2)
137  {
138  case pos_ews_by_thread_by_event_name::VIEW_MUTEX:
139  instr_class= find_mutex_class(m_pos.m_index_3);
140  break;
141  case pos_ews_by_thread_by_event_name::VIEW_RWLOCK:
142  instr_class= find_rwlock_class(m_pos.m_index_3);
143  break;
144  case pos_ews_by_thread_by_event_name::VIEW_COND:
145  instr_class= find_cond_class(m_pos.m_index_3);
146  break;
147  case pos_ews_by_thread_by_event_name::VIEW_FILE:
148  instr_class= find_file_class(m_pos.m_index_3);
149  break;
150  case pos_ews_by_thread_by_event_name::VIEW_TABLE:
151  instr_class= find_table_class(m_pos.m_index_3);
152  break;
153  case pos_ews_by_thread_by_event_name::VIEW_SOCKET:
154  instr_class= find_socket_class(m_pos.m_index_3);
155  break;
156  case pos_ews_by_thread_by_event_name::VIEW_IDLE:
157  instr_class= find_idle_class(m_pos.m_index_3);
158  break;
159  default:
160  DBUG_ASSERT(false);
161  instr_class= NULL;
162  break;
163  }
164 
165  if (instr_class != NULL)
166  {
167  make_row(thread, instr_class);
168  m_next_pos.set_after(&m_pos);
169  return 0;
170  }
171  }
172  }
173  }
174 
175  return HA_ERR_END_OF_FILE;
176 }
177 
178 int
180 {
181  PFS_thread *thread;
182  PFS_instr_class *instr_class;
183 
184  set_position(pos);
185  DBUG_ASSERT(m_pos.m_index_1 < thread_max);
186 
187  thread= &thread_array[m_pos.m_index_1];
188  if (! thread->m_lock.is_populated())
189  return HA_ERR_RECORD_DELETED;
190 
191  switch (m_pos.m_index_2)
192  {
193  case pos_ews_by_thread_by_event_name::VIEW_MUTEX:
194  instr_class= find_mutex_class(m_pos.m_index_3);
195  break;
196  case pos_ews_by_thread_by_event_name::VIEW_RWLOCK:
197  instr_class= find_rwlock_class(m_pos.m_index_3);
198  break;
199  case pos_ews_by_thread_by_event_name::VIEW_COND:
200  instr_class= find_cond_class(m_pos.m_index_3);
201  break;
202  case pos_ews_by_thread_by_event_name::VIEW_FILE:
203  instr_class= find_file_class(m_pos.m_index_3);
204  break;
205  case pos_ews_by_thread_by_event_name::VIEW_TABLE:
206  instr_class= find_table_class(m_pos.m_index_3);
207  break;
208  case pos_ews_by_thread_by_event_name::VIEW_SOCKET:
209  instr_class= find_socket_class(m_pos.m_index_3);
210  break;
211  case pos_ews_by_thread_by_event_name::VIEW_IDLE:
212  instr_class= find_idle_class(m_pos.m_index_3);
213  break;
214  default:
215  DBUG_ASSERT(false);
216  instr_class= NULL;
217  }
218 
219  if (instr_class)
220  {
221  make_row(thread, instr_class);
222  return 0;
223  }
224  return HA_ERR_RECORD_DELETED;
225 }
226 
227 void table_ews_by_thread_by_event_name
228 ::make_row(PFS_thread *thread, PFS_instr_class *klass)
229 {
230  pfs_lock lock;
231  m_row_exists= false;
232 
233  /* Protect this reader against a thread termination */
234  thread->m_lock.begin_optimistic_lock(&lock);
235 
237 
238  m_row.m_event_name.make_row(klass);
239 
240  PFS_connection_wait_visitor visitor(klass);
241  PFS_connection_iterator::visit_thread(thread, &visitor);
242 
243  /*
244  If the aggregation for this class is deferred, then we must pull the
245  current wait stats from the instances associated with this thread.
246  */
247  if (klass->is_deferred())
248  {
249  /* Visit instances owned by this thread. Do not visit the class. */
250  PFS_instance_wait_visitor inst_visitor;
251  PFS_instance_iterator::visit_instances(klass, &inst_visitor,
252  thread, false);
253  /* Combine the deferred stats and global stats */
254  visitor.m_stat.aggregate(&inst_visitor.m_stat);
255  }
256 
257  if (! thread->m_lock.end_optimistic_lock(&lock))
258  return;
259 
260  m_row_exists= true;
261 
262  get_normalizer(klass);
263  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
264 }
265 
267 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
268  bool read_all)
269 {
270  Field *f;
271 
272  if (unlikely(! m_row_exists))
273  return HA_ERR_RECORD_DELETED;
274 
275  /* Set the null bits */
276  DBUG_ASSERT(table->s->null_bytes == 0);
277 
278  for (; (f= *fields) ; fields++)
279  {
280  if (read_all || bitmap_is_set(table->read_set, f->field_index))
281  {
282  switch(f->field_index)
283  {
284  case 0: /* THREAD_ID */
285  set_field_ulonglong(f, m_row.m_thread_internal_id);
286  break;
287  case 1: /* EVENT_NAME */
288  m_row.m_event_name.set_field(f);
289  break;
290  default: /* 2, ... COUNT/SUM/MIN/AVG/MAX */
291  m_row.m_stat.set_field(f->field_index - 2, f);
292  break;
293  }
294  }
295  }
296 
297  return 0;
298 }
299