MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_setup_instruments.cc
Go to the documentation of this file.
1 /* Copyright (c) 2008, 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 Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
21 #include "my_global.h"
22 #include "my_pthread.h"
23 #include "pfs_instr_class.h"
24 #include "pfs_instr.h"
25 #include "pfs_column_types.h"
26 #include "pfs_column_values.h"
28 #include "pfs_global.h"
29 #include "pfs_setup_object.h"
30 
31 THR_LOCK table_setup_instruments::m_table_lock;
32 
33 static const TABLE_FIELD_TYPE field_types[]=
34 {
35  {
36  { C_STRING_WITH_LEN("NAME") },
37  { C_STRING_WITH_LEN("varchar(128)") },
38  { NULL, 0}
39  },
40  {
41  { C_STRING_WITH_LEN("ENABLED") },
42  { C_STRING_WITH_LEN("enum(\'YES\',\'NO\')") },
43  { NULL, 0}
44  },
45  {
46  { C_STRING_WITH_LEN("TIMED") },
47  { C_STRING_WITH_LEN("enum(\'YES\',\'NO\')") },
48  { NULL, 0}
49  }
50 };
51 
53 table_setup_instruments::m_field_def=
54 { 3, field_types };
55 
58 {
59  { C_STRING_WITH_LEN("setup_instruments") },
61  &table_setup_instruments::create,
62  NULL, /* write_row */
63  NULL, /* delete_all_rows */
64  NULL, /* get_row_count */
65  1000, /* records */
66  sizeof(pos_setup_instruments),
67  &m_table_lock,
68  &m_field_def,
69  false /* checked */
70 };
71 
72 PFS_engine_table* table_setup_instruments::create(void)
73 {
74  return new table_setup_instruments();
75 }
76 
77 table_setup_instruments::table_setup_instruments()
78  : PFS_engine_table(&m_share, &m_pos),
79  m_pos(), m_next_pos()
80 {}
81 
83 {
84  m_pos.reset();
85  m_next_pos.reset();
86 }
87 
89 {
90  PFS_instr_class *instr_class= NULL;
91 
92  /* Do not advertise hard coded instruments when disabled. */
93  if (! pfs_initialized)
94  return HA_ERR_END_OF_FILE;
95 
96  for (m_pos.set_at(&m_next_pos);
97  m_pos.has_more_view();
98  m_pos.next_view())
99  {
100  switch (m_pos.m_index_1)
101  {
102  case pos_setup_instruments::VIEW_MUTEX:
103  instr_class= find_mutex_class(m_pos.m_index_2);
104  break;
105  case pos_setup_instruments::VIEW_RWLOCK:
106  instr_class= find_rwlock_class(m_pos.m_index_2);
107  break;
108  case pos_setup_instruments::VIEW_COND:
109  instr_class= find_cond_class(m_pos.m_index_2);
110  break;
111  case pos_setup_instruments::VIEW_THREAD:
112  /* Not used yet */
113  break;
114  case pos_setup_instruments::VIEW_FILE:
115  instr_class= find_file_class(m_pos.m_index_2);
116  break;
117  case pos_setup_instruments::VIEW_TABLE:
118  instr_class= find_table_class(m_pos.m_index_2);
119  break;
120  case pos_setup_instruments::VIEW_STAGE:
121  instr_class= find_stage_class(m_pos.m_index_2);
122  break;
123  case pos_setup_instruments::VIEW_STATEMENT:
124  instr_class= find_statement_class(m_pos.m_index_2);
125  break;
126  case pos_setup_instruments::VIEW_SOCKET:
127  instr_class= find_socket_class(m_pos.m_index_2);
128  break;
129  case pos_setup_instruments::VIEW_IDLE:
130  instr_class= find_idle_class(m_pos.m_index_2);
131  break;
132  }
133  if (instr_class)
134  {
135  make_row(instr_class);
136  m_next_pos.set_after(&m_pos);
137  return 0;
138  }
139  }
140 
141  return HA_ERR_END_OF_FILE;
142 }
143 
145 {
146  PFS_instr_class *instr_class= NULL;
147 
148  /* Do not advertise hard coded instruments when disabled. */
149  if (! pfs_initialized)
150  return HA_ERR_END_OF_FILE;
151 
152  set_position(pos);
153 
154  switch (m_pos.m_index_1)
155  {
156  case pos_setup_instruments::VIEW_MUTEX:
157  instr_class= find_mutex_class(m_pos.m_index_2);
158  break;
159  case pos_setup_instruments::VIEW_RWLOCK:
160  instr_class= find_rwlock_class(m_pos.m_index_2);
161  break;
162  case pos_setup_instruments::VIEW_COND:
163  instr_class= find_cond_class(m_pos.m_index_2);
164  break;
165  case pos_setup_instruments::VIEW_THREAD:
166  /* Not used yet */
167  break;
168  case pos_setup_instruments::VIEW_FILE:
169  instr_class= find_file_class(m_pos.m_index_2);
170  break;
171  case pos_setup_instruments::VIEW_TABLE:
172  instr_class= find_table_class(m_pos.m_index_2);
173  break;
174  case pos_setup_instruments::VIEW_STAGE:
175  instr_class= find_stage_class(m_pos.m_index_2);
176  break;
177  case pos_setup_instruments::VIEW_STATEMENT:
178  instr_class= find_statement_class(m_pos.m_index_2);
179  break;
180  case pos_setup_instruments::VIEW_SOCKET:
181  instr_class= find_socket_class(m_pos.m_index_2);
182  break;
183  case pos_setup_instruments::VIEW_IDLE:
184  instr_class= find_idle_class(m_pos.m_index_2);
185  break;
186  }
187  if (instr_class)
188  {
189  make_row(instr_class);
190  return 0;
191  }
192 
193  return HA_ERR_RECORD_DELETED;
194 }
195 
196 void table_setup_instruments::make_row(PFS_instr_class *klass)
197 {
198  m_row.m_instr_class= klass;
199 }
200 
202  unsigned char *,
203  Field **fields,
204  bool read_all)
205 {
206  Field *f;
207 
208  DBUG_ASSERT(table->s->null_bytes == 0);
209 
210  /*
211  The row always exist, the instrument classes
212  are static and never disappear.
213  */
214 
215  for (; (f= *fields) ; fields++)
216  {
217  if (read_all || bitmap_is_set(table->read_set, f->field_index))
218  {
219  switch(f->field_index)
220  {
221  case 0: /* NAME */
223  break;
224  case 1: /* ENABLED */
225  set_field_enum(f, m_row.m_instr_class->m_enabled ? ENUM_YES : ENUM_NO);
226  break;
227  case 2: /* TIMED */
228  set_field_enum(f, m_row.m_instr_class->m_timed ? ENUM_YES : ENUM_NO);
229  break;
230  default:
231  DBUG_ASSERT(false);
232  }
233  }
234  }
235 
236  return 0;
237 }
238 
240  const unsigned char *,
241  unsigned char *,
242  Field **fields)
243 {
244  Field *f;
245  enum_yes_no value;
246 
247  for (; (f= *fields) ; fields++)
248  {
249  if (bitmap_is_set(table->write_set, f->field_index))
250  {
251  switch(f->field_index)
252  {
253  case 0: /* NAME */
254  return HA_ERR_WRONG_COMMAND;
255  case 1: /* ENABLED */
256  value= (enum_yes_no) get_field_enum(f);
257  m_row.m_instr_class->m_enabled= (value == ENUM_YES) ? true : false;
258  break;
259  case 2: /* TIMED */
260  value= (enum_yes_no) get_field_enum(f);
261  m_row.m_instr_class->m_timed= (value == ENUM_YES) ? true : false;
262  break;
263  default:
264  DBUG_ASSERT(false);
265  }
266  }
267  }
268 
269  switch (m_pos.m_index_1)
270  {
271  case pos_setup_instruments::VIEW_MUTEX:
273  break;
274  case pos_setup_instruments::VIEW_RWLOCK:
276  break;
277  case pos_setup_instruments::VIEW_COND:
279  break;
280  case pos_setup_instruments::VIEW_THREAD:
281  /* Not used yet */
282  break;
283  case pos_setup_instruments::VIEW_FILE:
285  break;
286  case pos_setup_instruments::VIEW_TABLE:
288  break;
289  case pos_setup_instruments::VIEW_STAGE:
290  case pos_setup_instruments::VIEW_STATEMENT:
291  /* No flag to update. */
292  break;
293  case pos_setup_instruments::VIEW_SOCKET:
295  break;
296  case pos_setup_instruments::VIEW_IDLE:
297  /* No flag to update. */
298  break;
299  default:
300  DBUG_ASSERT(false);
301  break;
302  }
303 
304  return 0;
305 }
306