MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_esgs_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_esgs_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_esgs_by_thread_by_event_name::m_field_def=
73 { 7, field_types };
74 
77 {
78  { C_STRING_WITH_LEN("events_stages_summary_by_thread_by_event_name") },
80  table_esgs_by_thread_by_event_name::create,
81  NULL, /* write_row */
82  table_esgs_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_esgs_by_thread_by_event_name::create(void)
93 {
95 }
96 
97 int
98 table_esgs_by_thread_by_event_name::delete_all_rows(void)
99 {
101  return 0;
102 }
103 
104 table_esgs_by_thread_by_event_name::table_esgs_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 {
118  return 0;
119 }
120 
122 {
123  PFS_thread *thread;
124  PFS_stage_class *stage_class;
125 
126  for (m_pos.set_at(&m_next_pos);
127  m_pos.has_more_thread();
128  m_pos.next_thread())
129  {
130  thread= &thread_array[m_pos.m_index_1];
131 
132  /*
133  Important note: the thread scan is the outer loop (index 1),
134  to minimize the number of calls to atomic operations.
135  */
136  if (thread->m_lock.is_populated())
137  {
138  stage_class= find_stage_class(m_pos.m_index_2);
139  if (stage_class)
140  {
141  make_row(thread, stage_class);
142  m_next_pos.set_after(&m_pos);
143  return 0;
144  }
145  }
146  }
147 
148  return HA_ERR_END_OF_FILE;
149 }
150 
151 int
153 {
154  PFS_thread *thread;
155  PFS_stage_class *stage_class;
156 
157  set_position(pos);
158  DBUG_ASSERT(m_pos.m_index_1 < thread_max);
159 
160  thread= &thread_array[m_pos.m_index_1];
161  if (! thread->m_lock.is_populated())
162  return HA_ERR_RECORD_DELETED;
163 
164  stage_class= find_stage_class(m_pos.m_index_2);
165  if (stage_class)
166  {
167  make_row(thread, stage_class);
168  return 0;
169  }
170 
171  return HA_ERR_RECORD_DELETED;
172 }
173 
174 void table_esgs_by_thread_by_event_name
175 ::make_row(PFS_thread *thread, PFS_stage_class *klass)
176 {
177  pfs_lock lock;
178  m_row_exists= false;
179 
180  /* Protect this reader against a thread termination */
181  thread->m_lock.begin_optimistic_lock(&lock);
182 
184 
185  m_row.m_event_name.make_row(klass);
186 
187  PFS_connection_stage_visitor visitor(klass);
188  PFS_connection_iterator::visit_thread(thread, & visitor);
189 
190  if (thread->m_lock.end_optimistic_lock(&lock))
191  m_row_exists= true;
192 
193  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
194 }
195 
197 ::read_row_values(TABLE *table, unsigned char *, Field **fields,
198  bool read_all)
199 {
200  Field *f;
201 
202  if (unlikely(! m_row_exists))
203  return HA_ERR_RECORD_DELETED;
204 
205  /* Set the null bits */
206  DBUG_ASSERT(table->s->null_bytes == 0);
207 
208  for (; (f= *fields) ; fields++)
209  {
210  if (read_all || bitmap_is_set(table->read_set, f->field_index))
211  {
212  switch(f->field_index)
213  {
214  case 0: /* THREAD_ID */
215  set_field_ulonglong(f, m_row.m_thread_internal_id);
216  break;
217  case 1: /* NAME */
218  m_row.m_event_name.set_field(f);
219  break;
220  default: /* 2, ... COUNT/SUM/MIN/AVG/MAX */
221  m_row.m_stat.set_field(f->field_index - 2, f);
222  break;
223  }
224  }
225  }
226 
227  return 0;
228 }
229