MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_performance_timers.cc
Go to the documentation of this file.
1 /* Copyright (c) 2008, 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 Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
21 #include "my_global.h"
22 #include "my_pthread.h"
24 #include "pfs_timer.h"
25 #include "pfs_global.h"
26 
27 THR_LOCK table_performance_timers::m_table_lock;
28 
29 static const TABLE_FIELD_TYPE field_types[]=
30 {
31  {
32  { C_STRING_WITH_LEN("TIMER_NAME") },
33  { C_STRING_WITH_LEN("enum(\'CYCLE\',\'NANOSECOND\',\'MICROSECOND\',"
34  "\'MILLISECOND\',\'TICK\')") },
35  { NULL, 0}
36  },
37  {
38  { C_STRING_WITH_LEN("TIMER_FREQUENCY") },
39  { C_STRING_WITH_LEN("bigint(20)") },
40  { NULL, 0}
41  },
42  {
43  { C_STRING_WITH_LEN("TIMER_RESOLUTION") },
44  { C_STRING_WITH_LEN("bigint(20)") },
45  { NULL, 0}
46  },
47  {
48  { C_STRING_WITH_LEN("TIMER_OVERHEAD") },
49  { C_STRING_WITH_LEN("bigint(20)") },
50  { NULL, 0}
51  }
52 };
53 
55 table_performance_timers::m_field_def=
56 { 4, field_types };
57 
60 {
61  { C_STRING_WITH_LEN("performance_timers") },
63  &table_performance_timers::create,
64  NULL, /* write_row */
65  NULL, /* delete_all_rows */
66  NULL, /* get_row_count */
67  COUNT_TIMER_NAME, /* records */
68  sizeof(PFS_simple_index), /* ref length */
69  &m_table_lock,
70  &m_field_def,
71  false /* checked */
72 };
73 
74 PFS_engine_table* table_performance_timers::create(void)
75 {
76  return new table_performance_timers();
77 }
78 
79 table_performance_timers::table_performance_timers()
80  : PFS_engine_table(&m_share, &m_pos),
81  m_row(NULL), m_pos(0), m_next_pos(0)
82 {
83  int index;
84 
85  index= (int)TIMER_NAME_CYCLE - FIRST_TIMER_NAME;
86  m_data[index].m_timer_name= TIMER_NAME_CYCLE;
87  m_data[index].m_info= pfs_timer_info.cycles;
88 
89  index= (int)TIMER_NAME_NANOSEC - FIRST_TIMER_NAME;
90  m_data[index].m_timer_name= TIMER_NAME_NANOSEC;
91  m_data[index].m_info= pfs_timer_info.nanoseconds;
92 
93  index= (int)TIMER_NAME_MICROSEC - FIRST_TIMER_NAME;
94  m_data[index].m_timer_name= TIMER_NAME_MICROSEC;
95  m_data[index].m_info= pfs_timer_info.microseconds;
96 
97  index= (int)TIMER_NAME_MILLISEC - FIRST_TIMER_NAME;
98  m_data[index].m_timer_name= TIMER_NAME_MILLISEC;
99  m_data[index].m_info= pfs_timer_info.milliseconds;
100 
101  index= (int)TIMER_NAME_TICK - FIRST_TIMER_NAME;
102  m_data[index].m_timer_name= TIMER_NAME_TICK;
103  m_data[index].m_info= pfs_timer_info.ticks;
104 }
105 
107 {
108  m_pos.m_index= 0;
109  m_next_pos.m_index= 0;
110 }
111 
113 {
114  int result;
115 
116  m_pos.set_at(&m_next_pos);
117 
118  if (m_pos.m_index < COUNT_TIMER_NAME)
119  {
120  m_row= &m_data[m_pos.m_index];
121  m_next_pos.set_after(&m_pos);
122  result= 0;
123  }
124  else
125  {
126  m_row= NULL;
127  result= HA_ERR_END_OF_FILE;
128  }
129 
130  return result;
131 }
132 
134 {
135  set_position(pos);
136  DBUG_ASSERT(m_pos.m_index < COUNT_TIMER_NAME);
137  m_row= &m_data[m_pos.m_index];
138  return 0;
139 }
140 
142  unsigned char *buf,
143  Field **fields,
144  bool read_all)
145 {
146  Field *f;
147 
148  DBUG_ASSERT(m_row);
149 
150  /* Set the null bits */
151  DBUG_ASSERT(table->s->null_bytes == 1);
152  buf[0]= 0;
153 
154  for (; (f= *fields) ; fields++)
155  {
156  if (read_all || bitmap_is_set(table->read_set, f->field_index))
157  {
158  switch(f->field_index)
159  {
160  case 0: /* TIMER_NAME */
161  set_field_enum(f, m_row->m_timer_name);
162  break;
163  case 1: /* TIMER_FREQUENCY */
164  if (m_row->m_info.routine != 0)
166  else
167  f->set_null();
168  break;
169  case 2: /* TIMER_RESOLUTION */
170  if (m_row->m_info.routine != 0)
172  else
173  f->set_null();
174  break;
175  case 3: /* TIMER_OVERHEAD */
176  if (m_row->m_info.routine != 0)
178  else
179  f->set_null();
180  break;
181  default:
182  DBUG_ASSERT(false);
183  }
184  }
185  }
186 
187  return 0;
188 }
189