MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_esgs_by_user_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_esgs_by_user_by_event_name::m_table_lock;
32 
33 static const TABLE_FIELD_TYPE field_types[]=
34 {
35  {
36  { C_STRING_WITH_LEN("USER") },
37  { C_STRING_WITH_LEN("char(16)") },
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_esgs_by_user_by_event_name::m_field_def=
74 { 7, field_types };
75 
78 {
79  { C_STRING_WITH_LEN("events_stages_summary_by_user_by_event_name") },
81  table_esgs_by_user_by_event_name::create,
82  NULL, /* write_row */
83  table_esgs_by_user_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_esgs_by_user_by_event_name::create(void)
94 {
96 }
97 
98 int
99 table_esgs_by_user_by_event_name::delete_all_rows(void)
100 {
104  return 0;
105 }
106 
107 table_esgs_by_user_by_event_name::table_esgs_by_user_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 {
121  return 0;
122 }
123 
125 {
126  PFS_user *user;
127  PFS_stage_class *stage_class;
128 
129  for (m_pos.set_at(&m_next_pos);
130  m_pos.has_more_user();
131  m_pos.next_user())
132  {
133  user= &user_array[m_pos.m_index_1];
134  if (user->m_lock.is_populated())
135  {
136  stage_class= find_stage_class(m_pos.m_index_2);
137  if (stage_class)
138  {
139  make_row(user, stage_class);
140  m_next_pos.set_after(&m_pos);
141  return 0;
142  }
143  }
144  }
145 
146  return HA_ERR_END_OF_FILE;
147 }
148 
149 int
151 {
152  PFS_user *user;
153  PFS_stage_class *stage_class;
154 
155  set_position(pos);
156  DBUG_ASSERT(m_pos.m_index_1 < user_max);
157 
158  user= &user_array[m_pos.m_index_1];
159  if (! user->m_lock.is_populated())
160  return HA_ERR_RECORD_DELETED;
161 
162  stage_class= find_stage_class(m_pos.m_index_2);
163  if (stage_class)
164  {
165  make_row(user, stage_class);
166  return 0;
167  }
168 
169  return HA_ERR_RECORD_DELETED;
170 }
171 
172 void table_esgs_by_user_by_event_name
173 ::make_row(PFS_user *user, PFS_stage_class *klass)
174 {
175  pfs_lock lock;
176  m_row_exists= false;
177 
178  user->m_lock.begin_optimistic_lock(&lock);
179 
180  if (m_row.m_user.make_row(user))
181  return;
182 
183  m_row.m_event_name.make_row(klass);
184 
185  PFS_connection_stage_visitor visitor(klass);
186  PFS_connection_iterator::visit_user(user, true, true, & visitor);
187 
188  if (! user->m_lock.end_optimistic_lock(&lock))
189  return;
190 
191  m_row_exists= true;
192  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
193 }
194 
196 ::read_row_values(TABLE *table, unsigned char *buf, Field **fields,
197  bool read_all)
198 {
199  Field *f;
200 
201  if (unlikely(! m_row_exists))
202  return HA_ERR_RECORD_DELETED;
203 
204  /* Set the null bits */
205  DBUG_ASSERT(table->s->null_bytes == 1);
206  buf[0]= 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: /* USER */
215  m_row.m_user.set_field(f);
216  break;
217  case 1: /* EVENT_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