MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_os_global_by_type.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 
29 THR_LOCK table_os_global_by_type::m_table_lock;
30 
31 static const TABLE_FIELD_TYPE field_types[]=
32 {
33  {
34  { C_STRING_WITH_LEN("OBJECT_TYPE") },
35  { C_STRING_WITH_LEN("varchar(64)") },
36  { NULL, 0}
37  },
38  {
39  { C_STRING_WITH_LEN("OBJECT_SCHEMA") },
40  { C_STRING_WITH_LEN("varchar(64)") },
41  { NULL, 0}
42  },
43  {
44  { C_STRING_WITH_LEN("OBJECT_NAME") },
45  { C_STRING_WITH_LEN("varchar(64)") },
46  { NULL, 0}
47  },
48  {
49  { C_STRING_WITH_LEN("COUNT_STAR") },
50  { C_STRING_WITH_LEN("bigint(20)") },
51  { NULL, 0}
52  },
53  {
54  { C_STRING_WITH_LEN("SUM_TIMER_WAIT") },
55  { C_STRING_WITH_LEN("bigint(20)") },
56  { NULL, 0}
57  },
58  {
59  { C_STRING_WITH_LEN("MIN_TIMER_WAIT") },
60  { C_STRING_WITH_LEN("bigint(20)") },
61  { NULL, 0}
62  },
63  {
64  { C_STRING_WITH_LEN("AVG_TIMER_WAIT") },
65  { C_STRING_WITH_LEN("bigint(20)") },
66  { NULL, 0}
67  },
68  {
69  { C_STRING_WITH_LEN("MAX_TIMER_WAIT") },
70  { C_STRING_WITH_LEN("bigint(20)") },
71  { NULL, 0}
72  }
73 };
74 
76 table_os_global_by_type::m_field_def=
77 { 8, field_types };
78 
81 {
82  { C_STRING_WITH_LEN("objects_summary_global_by_type") },
84  table_os_global_by_type::create,
85  NULL, /* write_row */
86  table_os_global_by_type::delete_all_rows,
87  NULL, /* get_row_count */
88  1000, /* records */
89  sizeof(pos_os_global_by_type),
90  &m_table_lock,
91  &m_field_def,
92  false /* checked */
93 };
94 
96 table_os_global_by_type::create(void)
97 {
98  return new table_os_global_by_type();
99 }
100 
101 int
102 table_os_global_by_type::delete_all_rows(void)
103 {
104  reset_table_waits_by_table_handle();
105  reset_table_waits_by_table();
106  return 0;
107 }
108 
109 table_os_global_by_type::table_os_global_by_type()
110  : PFS_engine_table(&m_share, &m_pos),
111  m_row_exists(false), m_pos(), m_next_pos()
112 {}
113 
115 {
116  m_pos.reset();
117  m_next_pos.reset();
118 }
119 
121 {
122  PFS_table_share *table_share;
123 
124  for (m_pos.set_at(&m_next_pos);
125  m_pos.has_more_view();
126  m_pos.next_view())
127  {
128  switch (m_pos.m_index_1) {
129  case pos_os_global_by_type::VIEW_TABLE:
130  for ( ; m_pos.m_index_2 < table_share_max; m_pos.m_index_2++)
131  {
132  table_share= &table_share_array[m_pos.m_index_2];
133  if (table_share->m_lock.is_populated())
134  {
135  make_row(table_share);
136  m_next_pos.set_after(&m_pos);
137  return 0;
138  }
139  }
140  break;
141  default:
142  break;
143  }
144  }
145 
146  return HA_ERR_END_OF_FILE;
147 }
148 
149 int
151 {
152  PFS_table_share *table_share;
153 
154  set_position(pos);
155 
156  switch (m_pos.m_index_1) {
157  case pos_os_global_by_type::VIEW_TABLE:
158  DBUG_ASSERT(m_pos.m_index_2 < table_share_max);
159  table_share= &table_share_array[m_pos.m_index_2];
160  if (table_share->m_lock.is_populated())
161  {
162  make_row(table_share);
163  return 0;
164  }
165  break;
166  default:
167  break;
168  }
169 
170  return HA_ERR_RECORD_DELETED;
171 }
172 
173 void table_os_global_by_type::make_row(PFS_table_share *share)
174 {
175  pfs_lock lock;
176  PFS_single_stat cumulated_stat;
177  uint safe_key_count;
178 
179  m_row_exists= false;
180 
181  share->m_lock.begin_optimistic_lock(&lock);
182 
183  m_row.m_object_type= share->get_object_type();
184  memcpy(m_row.m_schema_name, share->m_schema_name, share->m_schema_name_length);
186  memcpy(m_row.m_object_name, share->m_table_name, share->m_table_name_length);
188 
189  /* This is a dirty read, some thread can write data while we are reading it */
190  safe_key_count= sanitize_index_count(share->m_key_count);
191 
192  share->m_table_stat.sum(& cumulated_stat, safe_key_count);
193 
194  if (! share->m_lock.end_optimistic_lock(&lock))
195  return;
196 
197  m_row_exists= true;
198 
199  if (share->get_refcount() > 0)
200  {
201  /* For all the table handles still opened ... */
203  PFS_table *table_last= table_array + table_max;
204  for ( ; table < table_last ; table++)
205  {
206  if ((table->m_share == share) && (table->m_lock.is_populated()))
207  {
208  /*
209  If the opened table handle is for this table share,
210  aggregate the table handle statistics.
211  */
212  table->m_table_stat.sum(& cumulated_stat, safe_key_count);
213  }
214  }
215  }
216 
218  m_row.m_stat.set(normalizer, &cumulated_stat);
219 }
220 
222  unsigned char *buf,
223  Field **fields,
224  bool read_all)
225 {
226  Field *f;
227 
228  if (unlikely(! m_row_exists))
229  return HA_ERR_RECORD_DELETED;
230 
231  /* Set the null bits */
232  DBUG_ASSERT(table->s->null_bytes == 1);
233  buf[0]= 0;
234 
235  for (; (f= *fields) ; fields++)
236  {
237  if (read_all || bitmap_is_set(table->read_set, f->field_index))
238  {
239  switch(f->field_index)
240  {
241  case 0: /* OBJECT_TYPE */
242  set_field_object_type(f, m_row.m_object_type);
243  break;
244  case 1: /* SCHEMA_NAME */
246  m_row.m_schema_name_length);
247  break;
248  case 2: /* OBJECT_NAME */
250  m_row.m_object_name_length);
251  break;
252  case 3: /* COUNT */
254  break;
255  case 4: /* SUM */
256  set_field_ulonglong(f, m_row.m_stat.m_sum);
257  break;
258  case 5: /* MIN */
259  set_field_ulonglong(f, m_row.m_stat.m_min);
260  break;
261  case 6: /* AVG */
262  set_field_ulonglong(f, m_row.m_stat.m_avg);
263  break;
264  case 7: /* MAX */
265  set_field_ulonglong(f, m_row.m_stat.m_max);
266  break;
267  default:
268  DBUG_ASSERT(false);
269  }
270  }
271  }
272 
273  return 0;
274 }
275