MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_instr_class.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2013, 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 
16 #ifndef PFS_INSTR_CLASS_H
17 #define PFS_INSTR_CLASS_H
18 
19 #include "my_global.h"
20 #include "mysql_com.h" /* NAME_LEN */
21 #include "lf.h"
22 #include "pfs_global.h"
23 
33 #define PFS_MAX_INFO_NAME_LENGTH 128
34 
42 #define PFS_MAX_FULL_PREFIX_NAME_LENGTH 32
43 
44 #include <my_global.h>
45 #include <my_sys.h>
46 #include <mysql/psi/psi.h>
47 #include "pfs_lock.h"
48 #include "pfs_stat.h"
49 #include "pfs_column_types.h"
50 
51 struct PFS_global_param;
52 
58 extern my_bool pfs_enabled;
60 
62 typedef unsigned int PFS_sync_key;
64 typedef unsigned int PFS_thread_key;
66 typedef unsigned int PFS_file_key;
68 typedef unsigned int PFS_stage_key;
70 typedef unsigned int PFS_statement_key;
72 typedef unsigned int PFS_socket_key;
73 
74 enum PFS_class_type
75 {
76  PFS_CLASS_NONE= 0,
77  PFS_CLASS_MUTEX= 1,
78  PFS_CLASS_RWLOCK= 2,
79  PFS_CLASS_COND= 3,
80  PFS_CLASS_FILE= 4,
81  PFS_CLASS_TABLE= 5,
82  PFS_CLASS_STAGE= 6,
83  PFS_CLASS_STATEMENT= 7,
84  PFS_CLASS_SOCKET= 8,
85  PFS_CLASS_TABLE_IO= 9,
86  PFS_CLASS_TABLE_LOCK= 10,
87  PFS_CLASS_IDLE= 11,
88  PFS_CLASS_LAST= PFS_CLASS_IDLE,
89  PFS_CLASS_MAX= PFS_CLASS_LAST + 1
90 };
91 
94 {
95  /* Instrument name. */
96  char *m_name;
97  /* Name length. */
98  uint m_name_length;
100  bool m_enabled;
102  bool m_timed;
103 };
104 
106 extern int pfs_instr_config_state;
107 
108 static const int PFS_INSTR_CONFIG_NOT_INITIALIZED= 0;
109 static const int PFS_INSTR_CONFIG_ALLOCATED= 1;
110 static const int PFS_INSTR_CONFIG_DEALLOCATED= 2;
111 
112 struct PFS_thread;
113 
114 extern uint mutex_class_start;
115 extern uint rwlock_class_start;
116 extern uint cond_class_start;
117 extern uint file_class_start;
118 extern uint socket_class_start;
119 extern uint wait_class_max;
120 
123 {
125  PFS_class_type m_type;
127  bool m_enabled;
129  bool m_timed;
131  int m_flags;
146 
147  bool is_singleton() const
148  {
149  return m_flags & PSI_FLAG_GLOBAL;
150  }
151  static void set_enabled(PFS_instr_class *pfs, bool enabled);
152  static void set_timed(PFS_instr_class *pfs, bool timed);
153 
154  bool is_deferred() const
155  {
156  switch(m_type)
157  {
158  case PFS_CLASS_SOCKET:
159  return true;
160  break;
161  default:
162  return false;
163  break;
164  };
165  }
166 };
167 
168 struct PFS_mutex;
169 
171 struct PFS_ALIGNED PFS_mutex_class : public PFS_instr_class
172 {
177 };
178 
179 struct PFS_rwlock;
180 
182 struct PFS_ALIGNED PFS_rwlock_class : public PFS_instr_class
183 {
188 };
189 
190 struct PFS_cond;
191 
193 struct PFS_ALIGNED PFS_cond_class : public PFS_instr_class
194 {
202 };
203 
205 struct PFS_ALIGNED PFS_thread_class
206 {
208  bool m_enabled;
215 };
216 
219 {
226  char m_hash_key[1 + NAME_LEN + 1 + NAME_LEN + 1];
229 };
230 
233 {
235  char m_name[NAME_LEN];
238 };
239 
241 struct PFS_ALIGNED PFS_table_share
242 {
243 public:
244  uint32 get_version()
245  { return m_lock.get_version(); }
246 
247  enum_object_type get_object_type()
248  {
249  return (enum_object_type) m_key.m_hash_key[0];
250  }
251 
252  void aggregate_io(void);
253  void aggregate_lock(void);
254 
255  inline void aggregate(void)
256  {
257  aggregate_io();
258  aggregate_lock();
259  }
260 
261  inline void init_refcount(void)
262  {
263  PFS_atomic::store_32(& m_refcount, 1);
264  }
265 
266  inline int get_refcount(void)
267  {
268  return PFS_atomic::load_32(& m_refcount);
269  }
270 
271  inline void inc_refcount(void)
272  {
273  PFS_atomic::add_32(& m_refcount, 1);
274  }
275 
276  inline void dec_refcount(void)
277  {
278  PFS_atomic::add_32(& m_refcount, -1);
279  }
280 
281  void refresh_setup_object_flags(PFS_thread *thread);
282 
289  bool m_enabled;
294  bool m_timed;
298  const char *m_schema_name;
302  const char *m_table_name;
310  PFS_table_key m_keys[MAX_INDEXES];
311 
312 private:
314  int m_refcount;
315 };
316 
323 
324 inline uint sanitize_index_count(uint count)
325 {
326  if (likely(count <= MAX_INDEXES))
327  return count;
328  return 0;
329 }
330 
331 #define GLOBAL_TABLE_IO_EVENT_INDEX 0
332 #define GLOBAL_TABLE_LOCK_EVENT_INDEX 1
333 #define GLOBAL_IDLE_EVENT_INDEX 2
334 
340 
346 
351 
352 struct PFS_file;
353 
355 struct PFS_ALIGNED PFS_file_class : public PFS_instr_class
356 {
361 };
362 
364 struct PFS_ALIGNED PFS_stage_class : public PFS_instr_class
365 {
373 };
374 
376 struct PFS_ALIGNED PFS_statement_class : public PFS_instr_class
377 {
378 };
379 
380 struct PFS_socket;
381 
383 struct PFS_ALIGNED PFS_socket_class : public PFS_instr_class
384 {
389 };
390 
391 void init_event_name_sizing(const PFS_global_param *param);
392 
393 void register_global_classes();
394 
395 int init_sync_class(uint mutex_class_sizing,
396  uint rwlock_class_sizing,
397  uint cond_class_sizing);
398 
399 void cleanup_sync_class();
400 int init_thread_class(uint thread_class_sizing);
401 void cleanup_thread_class();
402 int init_table_share(uint table_share_sizing);
403 void cleanup_table_share();
406 int init_file_class(uint file_class_sizing);
407 void cleanup_file_class();
408 int init_stage_class(uint stage_class_sizing);
409 void cleanup_stage_class();
410 int init_statement_class(uint statement_class_sizing);
412 int init_socket_class(uint socket_class_sizing);
413 void cleanup_socket_class();
414 
415 PFS_sync_key register_mutex_class(const char *name, uint name_length,
416  int flags);
417 
418 PFS_sync_key register_rwlock_class(const char *name, uint name_length,
419  int flags);
420 
421 PFS_sync_key register_cond_class(const char *name, uint name_length,
422  int flags);
423 
424 PFS_thread_key register_thread_class(const char *name, uint name_length,
425  int flags);
426 
427 PFS_file_key register_file_class(const char *name, uint name_length,
428  int flags);
429 
431  uint prefix_length,
432  uint name_length,
433  int flags);
434 
435 PFS_statement_key register_statement_class(const char *name, uint name_length,
436  int flags);
437 
438 PFS_socket_key register_socket_class(const char *name, uint name_length,
439  int flags);
440 
441 PFS_mutex_class *find_mutex_class(PSI_mutex_key key);
442 PFS_mutex_class *sanitize_mutex_class(PFS_mutex_class *unsafe);
443 PFS_rwlock_class *find_rwlock_class(PSI_rwlock_key key);
444 PFS_rwlock_class *sanitize_rwlock_class(PFS_rwlock_class *unsafe);
445 PFS_cond_class *find_cond_class(PSI_cond_key key);
446 PFS_cond_class *sanitize_cond_class(PFS_cond_class *unsafe);
447 PFS_thread_class *find_thread_class(PSI_thread_key key);
448 PFS_thread_class *sanitize_thread_class(PFS_thread_class *unsafe);
449 PFS_file_class *find_file_class(PSI_file_key key);
450 PFS_file_class *sanitize_file_class(PFS_file_class *unsafe);
451 PFS_stage_class *find_stage_class(PSI_stage_key key);
452 PFS_stage_class *sanitize_stage_class(PFS_stage_class *unsafe);
453 PFS_statement_class *find_statement_class(PSI_statement_key key);
454 PFS_statement_class *sanitize_statement_class(PFS_statement_class *unsafe);
455 PFS_instr_class *find_table_class(uint index);
456 PFS_instr_class *sanitize_table_class(PFS_instr_class *unsafe);
457 PFS_socket_class *find_socket_class(PSI_socket_key key);
458 PFS_socket_class *sanitize_socket_class(PFS_socket_class *unsafe);
459 PFS_instr_class *find_idle_class(uint index);
460 PFS_instr_class *sanitize_idle_class(PFS_instr_class *unsafe);
461 
463  bool temporary,
464  const TABLE_SHARE *share);
466 void drop_table_share(PFS_thread *thread,
467  bool temporary,
468  const char *schema_name, uint schema_name_length,
469  const char *table_name, uint table_name_length);
470 
472 
473 extern ulong mutex_class_max;
474 extern ulong mutex_class_lost;
475 extern ulong rwlock_class_max;
476 extern ulong rwlock_class_lost;
477 extern ulong cond_class_max;
478 extern ulong cond_class_lost;
479 extern ulong thread_class_max;
480 extern ulong thread_class_lost;
481 extern ulong file_class_max;
482 extern ulong file_class_lost;
483 extern ulong stage_class_max;
484 extern ulong stage_class_lost;
485 extern ulong statement_class_max;
486 extern ulong statement_class_lost;
487 extern ulong socket_class_max;
488 extern ulong socket_class_lost;
489 extern ulong table_share_max;
490 extern ulong table_share_lost;
491 
492 /* Exposing the data directly, for iterators. */
493 
494 extern PFS_mutex_class *mutex_class_array;
495 extern PFS_rwlock_class *rwlock_class_array;
496 extern PFS_cond_class *cond_class_array;
497 extern PFS_file_class *file_class_array;
499 
501 void reset_file_class_io();
502 void reset_socket_class_io();
503 
506 
508 
510 #endif
511