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 
16 #ifndef PFS_EVENTS_WAITS_H
17 #define PFS_EVENTS_WAITS_H
18 
19 /**
20   @file storage/perfschema/pfs_events_waits.h
21   Events waits data structures (declarations).
22 */
23 
24 #include "pfs_column_types.h"
25 #include "pfs_lock.h"
26 
27 struct PFS_mutex;
28 struct PFS_rwlock;
29 struct PFS_cond;
30 struct PFS_table;
31 struct PFS_file;
32 struct PFS_thread;
33 struct PFS_instr_class;
34 
35 /** Class of a wait event. */
36 enum events_waits_class
37 {
38   NO_WAIT_CLASS= 0,
39   WAIT_CLASS_MUTEX,
40   WAIT_CLASS_RWLOCK,
41   WAIT_CLASS_COND,
42   WAIT_CLASS_TABLE,
43   WAIT_CLASS_FILE
44 };
45 
46 /** State of a timer. */
47 enum timer_state
48 {
49   /**
50     Not timed.
51     In this state, TIMER_START, TIMER_END and TIMER_WAIT are NULL.
52   */
53   TIMER_STATE_UNTIMED,
54   /**
55     About to start.
56     In this state, TIMER_START, TIMER_END and TIMER_WAIT are NULL.
57   */
58   TIMER_STATE_STARTING,
59   /**
60     Started, but not yet ended.
61     In this state, TIMER_START has a value, TIMER_END and TIMER_WAIT are NULL.
62   */
63   TIMER_STATE_STARTED,
64   /**
65     Ended.
66     In this state, TIMER_START, TIMER_END and TIMER_WAIT have a value.
67   */
68   TIMER_STATE_TIMED
69 };
70 
71 /** Target object a wait event is waiting on. */
72 union events_waits_target
73 {
74   /** Mutex waited on. */
75   PFS_mutex *m_mutex;
76   /** RWLock waited on. */
77   PFS_rwlock *m_rwlock;
78   /** Condition waited on. */
79   PFS_cond *m_cond;
80   /** Table waited on. */
81   PFS_table *m_table;
82   /** File waited on. */
83   PFS_file *m_file;
84 };
85 
86 /** A wait event record. */
87 struct PFS_events_waits
88 {
89   /**
90     The type of wait.
91     Readers:
92     - the consumer threads.
93     Writers:
94     - the producer threads, in the instrumentation.
95     Out of bound Writers:
96     - TRUNCATE EVENTS_WAITS_CURRENT
97     - TRUNCATE EVENTS_WAITS_HISTORY
98     - TRUNCATE EVENTS_WAITS_HISTORY_LONG
99   */
100   events_waits_class m_wait_class;
101   /** Executing thread. */
102   PFS_thread *m_thread;
103   /** Instrument metadata. */
104   PFS_instr_class *m_class;
105   /** Timer state. */
106   enum timer_state m_timer_state;
107   /** Event id. */
108   ulonglong m_event_id;
109   /**
110     Timer start.
111     This member is populated only if m_timed is true.
112   */
113   ulonglong m_timer_start;
114   /**
115     Timer end.
116     This member is populated only if m_timed is true.
117   */
118   ulonglong m_timer_end;
119   /** Schema name. */
120   const char *m_schema_name;
121   /** Length in bytes of @c m_schema_name. */
122   uint m_schema_name_length;
123   /** Object name. */
124   const char *m_object_name;
125   /** Length in bytes of @c m_object_name. */
126   uint m_object_name_length;
127   /** Address in memory of the object instance waited on. */
128   const void *m_object_instance_addr;
129   /** Location of the instrumentation in the source code (file name). */
130   const char *m_source_file;
131   /** Location of the instrumentation in the source code (line number). */
132   uint m_source_line;
133   /** Operation performed. */
134   enum_operation_type m_operation;
135   /**
136     Number of bytes read/written.
137     This member is populated for file READ/WRITE operations only.
138   */
139   size_t m_number_of_bytes;
140 };
141 
142 /**
143   A wait locker.
144   A locker is a transient helper structure used by the instrumentation
145   during the recording of a wait.
146 */
147 struct PFS_wait_locker
148 {
149   /** The timer used to measure the wait. */
150   enum_timer_name m_timer_name;
151   /** The object waited on. */
152   events_waits_target m_target;
153   /** The wait data recorded. */
154   PFS_events_waits m_waits_current;
155 };
156 
157 void insert_events_waits_history(PFS_thread *thread, PFS_events_waits *wait);
158 
159 void insert_events_waits_history_long(PFS_events_waits *wait);
160 
161 extern bool flag_events_waits_current;
162 extern bool flag_events_waits_history;
163 extern bool flag_events_waits_history_long;
164 extern bool flag_events_waits_summary_by_thread_by_event_name;
165 extern bool flag_events_waits_summary_by_event_name;
166 extern bool flag_events_waits_summary_by_instance;
167 extern bool flag_events_locks_summary_by_thread_by_name;
168 extern bool flag_events_locks_summary_by_event_name;
169 extern bool flag_events_locks_summary_by_instance;
170 extern bool flag_file_summary_by_event_name;
171 extern bool flag_file_summary_by_instance;
172 extern bool events_waits_history_long_full;
173 extern volatile uint32 events_waits_history_long_index;
174 extern PFS_events_waits *events_waits_history_long_array;
175 extern ulong events_waits_history_long_size;
176 
177 int init_events_waits_history_long(uint events_waits_history_long_sizing);
178 void cleanup_events_waits_history_long();
179 
180 void reset_events_waits_current();
181 void reset_events_waits_history();
182 void reset_events_waits_history_long();
183 
184 #endif
185 
186