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, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef PFS_EVENTS_WAITS_H
24 #define PFS_EVENTS_WAITS_H
25 
26 /**
27   @file storage/perfschema/pfs_events_waits.h
28   Events waits data structures (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_lock.h"
33 #include "pfs_events.h"
34 
35 struct PFS_mutex;
36 struct PFS_rwlock;
37 struct PFS_cond;
38 struct PFS_table;
39 struct PFS_file;
40 struct PFS_thread;
41 struct PFS_socket;
42 struct PFS_instr_class;
43 struct PFS_table_share;
44 struct PFS_account;
45 struct PFS_user;
46 struct PFS_host;
47 
48 /** Class of a wait event. */
49 enum events_waits_class
50 {
51   NO_WAIT_CLASS= 0,
52   WAIT_CLASS_MUTEX,
53   WAIT_CLASS_RWLOCK,
54   WAIT_CLASS_COND,
55   WAIT_CLASS_TABLE,
56   WAIT_CLASS_FILE,
57   WAIT_CLASS_SOCKET,
58   WAIT_CLASS_IDLE
59 };
60 
61 /** A wait event record. */
62 struct PFS_events_waits : public PFS_events
63 {
64   /**
65     The type of wait.
66     Readers:
67     - the consumer threads.
68     Writers:
69     - the producer threads, in the instrumentation.
70     Out of bound Writers:
71     - TRUNCATE EVENTS_WAITS_CURRENT
72     - TRUNCATE EVENTS_WAITS_HISTORY
73     - TRUNCATE EVENTS_WAITS_HISTORY_LONG
74   */
75   events_waits_class m_wait_class;
76   /** Executing thread. */
77   PFS_thread *m_thread;
78   /** Object type */
79   enum_object_type m_object_type;
80   /** Table share, for table operations only. */
81   PFS_table_share *m_weak_table_share;
82   /** File, for file operations only. */
83   PFS_file *m_weak_file;
84   /** Socket, for socket operations only. */
85   PFS_socket *m_weak_socket;
86   /** For weak pointers, target object version. */
87   uint32 m_weak_version;
88   /** Address in memory of the object instance waited on. */
89   const void *m_object_instance_addr;
90   /** Operation performed. */
91   enum_operation_type m_operation;
92   /**
93     Number of bytes read/written.
94     This member is populated for file READ/WRITE operations only.
95   */
96   size_t m_number_of_bytes;
97   /**
98     Index used.
99     This member is populated for TABLE IO operations only.
100   */
101   uint m_index;
102   /** Flags */
103   ulong m_flags;
104 };
105 
106 /** TIMED bit in the state flags bitfield. */
107 #define STATE_FLAG_TIMED (1<<0)
108 /** THREAD bit in the state flags bitfield. */
109 #define STATE_FLAG_THREAD (1<<1)
110 /** EVENT bit in the state flags bitfield. */
111 #define STATE_FLAG_EVENT (1<<2)
112 /** DIGEST bit in the state flags bitfield. */
113 #define STATE_FLAG_DIGEST (1<<3)
114 
115 void insert_events_waits_history(PFS_thread *thread, PFS_events_waits *wait);
116 
117 void insert_events_waits_history_long(PFS_events_waits *wait);
118 
119 extern bool flag_events_waits_current;
120 extern bool flag_events_waits_history;
121 extern bool flag_events_waits_history_long;
122 extern bool flag_global_instrumentation;
123 extern bool flag_thread_instrumentation;
124 
125 extern bool events_waits_history_long_full;
126 extern volatile uint32 events_waits_history_long_index;
127 extern PFS_events_waits *events_waits_history_long_array;
128 extern ulong events_waits_history_long_size;
129 
130 int init_events_waits_history_long(uint events_waits_history_long_sizing);
131 void cleanup_events_waits_history_long();
132 
133 void reset_events_waits_current();
134 void reset_events_waits_history();
135 void reset_events_waits_history_long();
136 void reset_events_waits_by_thread();
137 void reset_events_waits_by_account();
138 void reset_events_waits_by_user();
139 void reset_events_waits_by_host();
140 void reset_events_waits_global();
141 void aggregate_account_waits(PFS_account *account);
142 void aggregate_user_waits(PFS_user *user);
143 void aggregate_host_waits(PFS_host *host);
144 
145 void reset_table_waits_by_table();
146 void reset_table_io_waits_by_table();
147 void reset_table_lock_waits_by_table();
148 void reset_table_waits_by_table_handle();
149 void reset_table_io_waits_by_table_handle();
150 void reset_table_lock_waits_by_table_handle();
151 
152 #endif
153 
154