MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_instr.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_H
17 #define PFS_INSTR_H
18 
24 struct PFS_mutex_class;
25 struct PFS_rwlock_class;
26 struct PFS_cond_class;
27 struct PFS_file_class;
28 struct PFS_table_share;
29 struct PFS_thread_class;
30 struct PFS_socket_class;
31 
32 #ifdef __WIN__
33 #include <winsock2.h>
34 #else
35 #include <arpa/inet.h>
36 #endif
37 #include "my_global.h"
38 #include "my_compiler.h"
39 #include "pfs_lock.h"
40 #include "pfs_stat.h"
41 #include "pfs_instr_class.h"
42 #include "pfs_events_waits.h"
43 #include "pfs_events_stages.h"
44 #include "pfs_events_statements.h"
45 #include "pfs_server.h"
46 #include "lf.h"
47 #include "pfs_con_slice.h"
48 
54 struct PFS_thread;
55 struct PFS_host;
56 struct PFS_user;
57 struct PFS_account;
58 
60 struct PFS_instr
61 {
65  bool m_enabled;
67  bool m_timed;
68 };
69 
71 struct PFS_ALIGNED PFS_mutex : public PFS_instr
72 {
74  const void *m_identity;
85  ulonglong m_last_locked;
86 };
87 
89 struct PFS_ALIGNED PFS_rwlock : public PFS_instr
90 {
92  const void *m_identity;
100  uint m_readers;
105  ulonglong m_last_written;
110  ulonglong m_last_read;
111 };
112 
114 struct PFS_ALIGNED PFS_cond : public PFS_instr
115 {
117  const void *m_identity;
124 };
125 
127 struct PFS_ALIGNED PFS_file : public PFS_instr
128 {
129  uint32 get_version()
130  { return m_lock.get_version(); }
131 
133  const void *m_identity;
135  char m_filename[FN_REFLEN];
142 };
143 
145 struct PFS_ALIGNED PFS_table
146 {
167 
170 
173 
174 public:
180  void aggregate(void)
181  {
182  if (m_has_io_stats && m_has_lock_stats)
183  {
184  safe_aggregate(& m_table_stat, m_share);
185  m_has_io_stats= false;
186  m_has_lock_stats= false;
187  }
188  else if (m_has_io_stats)
189  {
190  safe_aggregate_io(& m_table_stat, m_share);
191  m_has_io_stats= false;
192  }
193  else if (m_has_lock_stats)
194  {
195  safe_aggregate_lock(& m_table_stat, m_share);
196  m_has_lock_stats= false;
197  }
198  }
199 
207  void sanitized_aggregate(void);
208 
213  void sanitized_aggregate_io(void);
214 
219  void sanitized_aggregate_lock(void);
220 
228  const void *m_identity;
231 
232 private:
233  static void safe_aggregate(PFS_table_stat *stat,
234  PFS_table_share *safe_share);
235  static void safe_aggregate_io(PFS_table_stat *stat,
236  PFS_table_share *safe_share);
237  static void safe_aggregate_lock(PFS_table_stat *stat,
238  PFS_table_share *safe_share);
239 };
240 
242 struct PFS_ALIGNED PFS_socket : public PFS_instr
243 {
244  uint32 get_version()
245  { return m_lock.get_version(); }
246 
248  const void *m_identity;
252  uint m_fd;
254  struct sockaddr_storage m_sock_addr;
256  socklen_t m_addr_len;
258  bool m_idle;
263 };
264 
285 #define WAIT_STACK_LOGICAL_SIZE 5
286 
292 #define WAIT_STACK_BOTTOM 1
293 
297 #define WAIT_STACK_SIZE (WAIT_STACK_BOTTOM + WAIT_STACK_LOGICAL_SIZE)
298 
300 extern uint statement_stack_max;
301 
307 #define PFS_MAX_ALLOC_RETRY 1000
308 
310 #define PFS_MAX_SCAN_PASS 2
311 
320 struct PFS_scan
321 {
322 public:
328  void init(uint random, uint max_size);
329 
334  bool has_pass() const
335  { return (m_pass < m_pass_max); }
336 
340  void next_pass()
341  { m_pass++; }
342 
344  uint first() const
345  { return m_first[m_pass]; }
346 
348  uint last() const
349  { return m_last[m_pass]; }
350 
351 private:
353  uint m_pass;
355  uint m_pass_max;
357  uint m_first[PFS_MAX_SCAN_PASS];
359  uint m_last[PFS_MAX_SCAN_PASS];
360 };
361 
362 
364 struct PFS_ALIGNED PFS_thread : PFS_connection_slice
365 {
366  static PFS_thread* get_current_thread(void);
367 
369  bool m_enabled;
373  ulonglong m_event_id;
435  PFS_events_waits m_events_waits_stack[WAIT_STACK_SIZE];
446 
457 
468 
479  char m_username[USERNAME_LENGTH];
489  char m_hostname[HOSTNAME_LENGTH];
499  char m_dbname[NAME_LEN];
508  time_t m_start_time;
521  char m_processlist_info[COL_INFO_SIZE];
527 
528  PFS_events_stages m_stage_current;
529 
532  PFS_events_statements *m_statement_stack;
533 
534  PFS_host *m_host;
535  PFS_user *m_user;
536  PFS_account *m_account;
537 
539  void reset_session_connect_attrs();
540 
556 };
557 
558 extern PFS_stage_stat *global_instr_class_stages_array;
559 extern PFS_statement_stat *global_instr_class_statements_array;
560 
561 PFS_mutex *sanitize_mutex(PFS_mutex *unsafe);
562 PFS_rwlock *sanitize_rwlock(PFS_rwlock *unsafe);
563 PFS_cond *sanitize_cond(PFS_cond *unsafe);
565 PFS_file *sanitize_file(PFS_file *unsafe);
566 PFS_socket *sanitize_socket(PFS_socket *unsafe);
567 
568 int init_instruments(const PFS_global_param *param);
569 void cleanup_instruments();
570 int init_file_hash();
571 void cleanup_file_hash();
572 PFS_mutex* create_mutex(PFS_mutex_class *mutex_class, const void *identity);
573 void destroy_mutex(PFS_mutex *pfs);
574 PFS_rwlock* create_rwlock(PFS_rwlock_class *klass, const void *identity);
575 void destroy_rwlock(PFS_rwlock *pfs);
576 PFS_cond* create_cond(PFS_cond_class *klass, const void *identity);
577 void destroy_cond(PFS_cond *pfs);
578 
579 PFS_thread* create_thread(PFS_thread_class *klass, const void *identity,
580  ulonglong processlist_id);
581 
582 void destroy_thread(PFS_thread *pfs);
583 
585  const char *filename, uint len, bool create);
586 
587 void release_file(PFS_file *pfs);
588 void destroy_file(PFS_thread *thread, PFS_file *pfs);
589 PFS_table* create_table(PFS_table_share *share, PFS_thread *opening_thread,
590  const void *identity);
591 void destroy_table(PFS_table *pfs);
592 
594  const my_socket *fd,
595  const struct sockaddr *addr,
596  socklen_t addr_len);
597 void destroy_socket(PFS_socket *pfs);
598 
599 /* For iterators and show status. */
600 
601 extern ulong mutex_max;
602 extern ulong mutex_lost;
603 extern ulong rwlock_max;
604 extern ulong rwlock_lost;
605 extern ulong cond_max;
606 extern ulong cond_lost;
607 extern ulong thread_max;
608 extern ulong thread_lost;
609 extern ulong file_max;
610 extern ulong file_lost;
611 extern long file_handle_max;
612 extern ulong file_handle_lost;
613 extern ulong table_max;
614 extern ulong table_lost;
615 extern ulong socket_max;
616 extern ulong socket_lost;
620 extern ulong locker_lost;
621 extern ulong statement_lost;
622 extern ulong session_connect_attrs_lost;
624 
625 /* Exposing the data directly, for iterators. */
626 
627 extern PFS_mutex *mutex_array;
628 extern PFS_rwlock *rwlock_array;
629 extern PFS_cond *cond_array;
630 extern PFS_thread *thread_array;
631 extern PFS_file *file_array;
632 extern PFS_file **file_handle_array;
633 extern PFS_table *table_array;
634 extern PFS_socket *socket_array;
635 
639 
640 void aggregate_all_event_names(PFS_single_stat *from_array,
641  PFS_single_stat *to_array);
642 void aggregate_all_event_names(PFS_single_stat *from_array,
643  PFS_single_stat *to_array_1,
644  PFS_single_stat *to_array_2);
645 
646 void aggregate_all_stages(PFS_stage_stat *from_array,
647  PFS_stage_stat *to_array);
648 void aggregate_all_stages(PFS_stage_stat *from_array,
649  PFS_stage_stat *to_array_1,
650  PFS_stage_stat *to_array_2);
651 
652 void aggregate_all_statements(PFS_statement_stat *from_array,
653  PFS_statement_stat *to_array);
654 void aggregate_all_statements(PFS_statement_stat *from_array,
655  PFS_statement_stat *to_array_1,
656  PFS_statement_stat *to_array_2);
657 
658 void aggregate_thread(PFS_thread *thread,
659  PFS_account *safe_account,
660  PFS_user *safe_user,
661  PFS_host *safe_host);
662 void aggregate_thread_waits(PFS_thread *thread,
663  PFS_account *safe_account,
664  PFS_user *safe_user,
665  PFS_host *safe_host);
666 void aggregate_thread_stages(PFS_thread *thread,
667  PFS_account *safe_account,
668  PFS_user *safe_user,
669  PFS_host *safe_host);
670 void aggregate_thread_statements(PFS_thread *thread,
671  PFS_account *safe_account,
672  PFS_user *safe_user,
673  PFS_host *safe_host);
674 void clear_thread_account(PFS_thread *thread);
675 void set_thread_account(PFS_thread *thread);
676 
691 
692 extern LF_HASH filename_hash;
693 
695 #endif
696