Debian Codegraph @

storage/perfschema/pfs_events_waits.cc

raw symbols SCIP
1 /* Copyright (c) 2008, 2023, Oracle and/or its affiliates.
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, Fifth Floor, Boston, MA 02110-1335 USA */
22
23 /**
24 @file storage/perfschema/pfs_events_waits.cc
25 Events waits data structures (implementation).
26 */
27
28 #include "my_global.h"cxx . . $ `<file>/include/my_global.h`/
29 #include "my_sys.h"cxx . . $ `<file>/include/my_sys.h`/
30 #include "pfs_global.h"cxx . . $ `<file>/storage/perfschema/pfs_global.h`/
31 #include "pfs_instr_class.h"cxx . . $ `<file>/storage/perfschema/pfs_instr_class.h`/
32 #include "pfs_instr.h"cxx . . $ `<file>/storage/perfschema/pfs_instr.h`/
33 #include "pfs_user.h"cxx . . $ `<file>/storage/perfschema/pfs_user.h`/
34 #include "pfs_host.h"cxx . . $ `<file>/storage/perfschema/pfs_host.h`/
35 #include "pfs_account.h"cxx . . $ `<file>/storage/perfschema/pfs_account.h`/
36 #include "pfs_events_waits.h"cxx . . $ `<file>/storage/perfschema/pfs_events_waits.h`/
37 #include "pfs_buffer_container.h"cxx . . $ `<file>/storage/perfschema/pfs_buffer_container.h`/
38 #include "pfs_builtin_memory.h"cxx . . $ `<file>/storage/perfschema/pfs_builtin_memory.h`/
39 #include "m_string.h"cxx . . $ `<file>/include/m_string.h`/
40
41 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! ulong events_waits_history_long_sizecxx . . $ events_waits_history_long_size.= 0;
42 /** Consumer flag for table EVENTS_WAITS_CURRENT. */
43 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! bool flag_events_waits_currentcxx . . $ flag_events_waits_current.= false;
44 /** Consumer flag for table EVENTS_WAITS_HISTORY. */
45 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! bool flag_events_waits_historycxx . . $ flag_events_waits_history.= false;
46 /** Consumer flag for table EVENTS_WAITS_HISTORY_LONG. */
47 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! bool flag_events_waits_history_longcxx . . $ flag_events_waits_history_long.= false;
48 /** Consumer flag for the global instrumentation. */
49 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! bool flag_global_instrumentationcxx . . $ flag_global_instrumentation.= false;
50 /** Consumer flag for the per thread instrumentation. */
51 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! bool flag_thread_instrumentationcxx . . $ flag_thread_instrumentation.= false;
52
53 /** True if EVENTS_WAITS_HISTORY_LONG circular buffer is full. */
54 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! bool events_waits_history_long_fullcxx . . $ events_waits_history_long_full.= false;
55 /** Index in EVENTS_WAITS_HISTORY_LONG circular buffer. */
56 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! PFS_cacheline_uint32cxx . . $ PFS_cacheline_uint32# events_waits_history_long_indexcxx . . $ events_waits_history_long_index.;
57 /** EVENTS_WAITS_HISTORY_LONG circular buffer. */
58 PFS_ALIGNEDcxx . . $ `storage/perfschema/pfs_global.h:41:9`! PFS_events_waitscxx . . $ PFS_events_waits# *events_waits_history_long_arraycxx . . $ events_waits_history_long_array.= NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
59
60 /**
61 Initialize table EVENTS_WAITS_HISTORY_LONG.
62 @param events_waits_history_long_sizing table sizing
63 */
64 int init_events_waits_history_longcxx . . $ init_events_waits_history_long(4c679297bf94b9eb).(uint events_waits_history_long_sizing)
65 {
66 events_waits_history_long_sizecxx . . $ events_waits_history_long_size.= events_waits_history_long_sizing;
67 events_waits_history_long_fullcxx . . $ events_waits_history_long_full.= false;
68 events_waits_history_long_indexcxx . . $ events_waits_history_long_index..m_u32cxx . . $ PFS_cacheline_uint32#m_u32..storecxx . . $ std/__atomic_base#store(3f1f49b30cba5fcc).(0);
69
70 if (events_waits_history_long_sizecxx . . $ events_waits_history_long_size. == 0)
71 return 0;
72
73 events_waits_history_long_arraycxx . . $ events_waits_history_long_array.=
74 PFS_MALLOC_ARRAYcxx . . $ `storage/perfschema/pfs_global.h:87:9`!(& builtin_memory_waits_history_long,
75 events_waits_history_long_size,
76 sizeof(PFS_events_waits), PFS_events_waits,
77 MYFcxx . . $ `include/my_global.h:986:9`!(MY_ZEROFILLcxx . . $ `include/my_sys.h:87:9`!));
78
79 return (events_waits_history_long_arraycxx . . $ events_waits_history_long_array. ? 0 : 1);
80 }
81
82 /** Cleanup table EVENTS_WAITS_HISTORY_LONG. */
83 void cleanup_events_waits_history_longcxx . . $ cleanup_events_waits_history_long(49f6e7a06ebc5aa8).(void)
84 {
85 PFS_FREE_ARRAYcxx . . $ `storage/perfschema/pfs_global.h:103:9`!(& builtin_memory_waits_history_long,
86 events_waits_history_long_size, sizeof(PFS_events_waits),
87 events_waits_history_long_array);
88 events_waits_history_long_arraycxx . . $ events_waits_history_long_array.= NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
89 }
90
91 static inline void copy_events_waitscxx . . $ copy_events_waits(5c764f23a5dff2d2).(PFS_events_waitscxx . . $ PFS_events_waits# *dest,
92 const PFS_events_waitscxx . . $ PFS_events_waits# *source)
93 {
94 memcpy(dest, source, sizeof(PFS_events_waitscxx . . $ PFS_events_waits#));
95 }
96
97 /**
98 Insert a wait record in table EVENTS_WAITS_HISTORY.
99 @param thread thread that executed the wait
100 @param wait record to insert
101 */
102 void insert_events_waits_historycxx . . $ insert_events_waits_history(f1915386ee40f597).(PFS_threadcxx . . $ PFS_thread# *thread, PFS_events_waitscxx . . $ PFS_events_waits# *wait)
103 {
104 if (unlikelycxx . . $ `include/my_global.h:361:9`!(events_waits_history_per_thread == 0))
105 return;
106
107 uint index= thread->m_waits_history_indexcxx . . $ PFS_thread#m_waits_history_index.;
108
109 /*
110 A concurrent thread executing TRUNCATE TABLE EVENTS_WAITS_CURRENT
111 could alter the data that this thread is inserting,
112 causing a potential race condition.
113 We are not testing for this and insert a possibly empty record,
114 to make this thread (the writer) faster.
115 This is ok, the readers of m_waits_history will filter this out.
116 */
117 copy_events_waitscxx . . $ copy_events_waits(5c764f23a5dff2d2).(&thread->m_waits_historycxx . . $ PFS_thread#m_waits_history.[index], wait);
118
119 index++;
120 if (index >= events_waits_history_per_threadcxx . . $ events_waits_history_per_thread.)
121 {
122 index= 0;
123 thread->m_waits_history_fullcxx . . $ PFS_thread#m_waits_history_full.= true;
124 }
125 thread->m_waits_history_indexcxx . . $ PFS_thread#m_waits_history_index.= index;
126 }
127
128 /**
129 Insert a wait record in table EVENTS_WAITS_HISTORY_LONG.
130 @param wait record to insert
131 */
132 void insert_events_waits_history_longcxx . . $ insert_events_waits_history_long(1bc16a8be87be6d2).(PFS_events_waitscxx . . $ PFS_events_waits# *wait)
133 {
134 if (unlikelycxx . . $ `include/my_global.h:361:9`!(events_waits_history_long_size == 0))
135 return;
136
137 uint index= events_waits_history_long_indexcxx . . $ events_waits_history_long_index..m_u32cxx . . $ PFS_cacheline_uint32#m_u32..fetch_addcxx . . $ std/__atomic_base#fetch_add(8de7200f212ddeb7).(1);
138
139 index= index % events_waits_history_long_sizecxx . . $ events_waits_history_long_size.;
140 if (index == 0)
141 events_waits_history_long_fullcxx . . $ events_waits_history_long_full.= true;
142
143 /* See related comment in insert_events_waits_history. */
144 copy_events_waitscxx . . $ copy_events_waits(5c764f23a5dff2d2).(&events_waits_history_long_arraycxx . . $ events_waits_history_long_array.[index], wait);
145 }
146
147 static void fct_reset_events_waits_currentcxx . . $ fct_reset_events_waits_current(15748000876f743a).(PFS_threadcxx . . $ PFS_thread# *pfs_thread)
148 {
149 PFS_events_waitscxx . . $ PFS_events_waits# *pfs_wait= pfs_thread->m_events_waits_stackcxx . . $ PFS_thread#m_events_waits_stack.;
150 PFS_events_waitscxx . . $ PFS_events_waits# *pfs_wait_last= pfs_wait + WAIT_STACK_SIZEcxx . . $ `storage/perfschema/pfs_instr.h:337:9`!;
151
152 for ( ; pfs_wait < pfs_wait_last; pfs_wait++)
153 pfs_wait->m_wait_classcxx . . $ PFS_events_waits#m_wait_class.= NO_WAIT_CLASScxx . . $ NO_WAIT_CLASS.;
154 }
155
156
157 /** Reset table EVENTS_WAITS_CURRENT data. */
158 void reset_events_waits_currentcxx . . $ reset_events_waits_current(49f6e7a06ebc5aa8).(void)
159 {
160 global_thread_containercxx . . $ global_thread_container..apply_allcxx . . $ PFS_buffer_scalable_container#apply_all(56a1e2153553a317).(fct_reset_events_waits_currentcxx . . $ fct_reset_events_waits_current(15748000876f743a).);
161 }
162
163 static void fct_reset_events_waits_historycxx . . $ fct_reset_events_waits_history(15748000876f743a).(PFS_threadcxx . . $ PFS_thread# *pfs_thread)
164 {
165 PFS_events_waitscxx . . $ PFS_events_waits# *wait= pfs_thread->m_waits_historycxx . . $ PFS_thread#m_waits_history.;
166 PFS_events_waitscxx . . $ PFS_events_waits# *wait_last= wait + events_waits_history_per_threadcxx . . $ events_waits_history_per_thread.;
167
168 pfs_thread->m_waits_history_indexcxx . . $ PFS_thread#m_waits_history_index.= 0;
169 pfs_thread->m_waits_history_fullcxx . . $ PFS_thread#m_waits_history_full.= false;
170 for ( ; wait < wait_last; wait++)
171 wait->m_wait_classcxx . . $ PFS_events_waits#m_wait_class.= NO_WAIT_CLASScxx . . $ NO_WAIT_CLASS.;
172 }
173
174 /** Reset table EVENTS_WAITS_HISTORY data. */
175 void reset_events_waits_historycxx . . $ reset_events_waits_history(49f6e7a06ebc5aa8).(void)
176 {
177 global_thread_containercxx . . $ global_thread_container..apply_allcxx . . $ PFS_buffer_scalable_container#apply_all(56a1e2153553a317).(fct_reset_events_waits_historycxx . . $ fct_reset_events_waits_history(15748000876f743a).);
178 }
179
180 /** Reset table EVENTS_WAITS_HISTORY_LONG data. */
181 void reset_events_waits_history_longcxx . . $ reset_events_waits_history_long(49f6e7a06ebc5aa8).(void)
182 {
183 events_waits_history_long_indexcxx . . $ events_waits_history_long_index..m_u32cxx . . $ PFS_cacheline_uint32#m_u32..storecxx . . $ std/__atomic_base#store(3f1f49b30cba5fcc).(0);
184 events_waits_history_long_fullcxx . . $ events_waits_history_long_full.= false;
185
186 PFS_events_waitscxx . . $ PFS_events_waits# *wait= events_waits_history_long_arraycxx . . $ events_waits_history_long_array.;
187 PFS_events_waitscxx . . $ PFS_events_waits# *wait_last= wait + events_waits_history_long_sizecxx . . $ events_waits_history_long_size.;
188 for ( ; wait < wait_last; wait++)
189 wait->m_wait_classcxx . . $ PFS_events_waits#m_wait_class.= NO_WAIT_CLASScxx . . $ NO_WAIT_CLASS.;
190 }
191
192 static void fct_reset_events_waits_by_threadcxx . . $ fct_reset_events_waits_by_thread(15748000876f743a).(PFS_threadcxx . . $ PFS_thread# *thread)
193 {
194 PFS_accountcxx . . $ PFS_account# *account= sanitize_accountcxx . . $ sanitize_account(813b1b87e4a46bfb).(thread->m_accountcxx . . $ PFS_thread#m_account.);
195 PFS_usercxx . . $ PFS_user# *user= sanitize_usercxx . . $ sanitize_user(7c6db9ba032f8556).(thread->m_usercxx . . $ PFS_thread#m_user.);
196 PFS_hostcxx . . $ PFS_host# *host= sanitize_hostcxx . . $ sanitize_host(d0f3aaba030f3ffb).(thread->m_hostcxx . . $ PFS_thread#m_host.);
197 aggregate_thread_waitscxx . . $ aggregate_thread_waits(27bffc1cda8ffcdf).(thread, account, user, host);
198 }
199
200 /** Reset table EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME data. */
201 void reset_events_waits_by_threadcxx . . $ reset_events_waits_by_thread(49f6e7a06ebc5aa8).()
202 {
203 global_thread_containercxx . . $ global_thread_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_events_waits_by_threadcxx . . $ fct_reset_events_waits_by_thread(15748000876f743a).);
204 }
205
206 static void fct_reset_events_waits_by_accountcxx . . $ fct_reset_events_waits_by_account(af807f345a081b78).(PFS_accountcxx . . $ PFS_account# *pfs)
207 {
208 PFS_usercxx . . $ PFS_user# *user= sanitize_usercxx . . $ sanitize_user(7c6db9ba032f8556).(pfs->m_usercxx . . $ PFS_account#m_user.);
209 PFS_hostcxx . . $ PFS_host# *host= sanitize_hostcxx . . $ sanitize_host(d0f3aaba030f3ffb).(pfs->m_hostcxx . . $ PFS_account#m_host.);
210 pfs->aggregate_waitscxx . . $ PFS_account#aggregate_waits(5fb91acbdf55a203).(user, host);
211 }
212
213 /** Reset table EVENTS_WAITS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME data. */
214 void reset_events_waits_by_accountcxx . . $ reset_events_waits_by_account(49f6e7a06ebc5aa8).()
215 {
216 global_account_containercxx . . $ global_account_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_events_waits_by_accountcxx . . $ fct_reset_events_waits_by_account(af807f345a081b78).);
217 }
218
219 static void fct_reset_events_waits_by_usercxx . . $ fct_reset_events_waits_by_user(93a5df659a21a697).(PFS_usercxx . . $ PFS_user# *pfs)
220 {
221 pfs->aggregate_waitscxx . . $ PFS_user#aggregate_waits(49f6e7a06ebc5aa8).();
222 }
223
224 /** Reset table EVENTS_WAITS_SUMMARY_BY_USER_BY_EVENT_NAME data. */
225 void reset_events_waits_by_usercxx . . $ reset_events_waits_by_user(49f6e7a06ebc5aa8).()
226 {
227 global_user_containercxx . . $ global_user_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_events_waits_by_usercxx . . $ fct_reset_events_waits_by_user(93a5df659a21a697).);
228 }
229
230 static void fct_reset_events_waits_by_hostcxx . . $ fct_reset_events_waits_by_host(78a1b153780401fe).(PFS_hostcxx . . $ PFS_host# *pfs)
231 {
232 pfs->aggregate_waitscxx . . $ PFS_host#aggregate_waits(49f6e7a06ebc5aa8).();
233 }
234
235 /** Reset table EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME data. */
236 void reset_events_waits_by_hostcxx . . $ reset_events_waits_by_host(49f6e7a06ebc5aa8).()
237 {
238 global_host_containercxx . . $ global_host_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_events_waits_by_hostcxx . . $ fct_reset_events_waits_by_host(78a1b153780401fe).);
239 }
240
241 static void fct_reset_table_waits_by_tablecxx . . $ fct_reset_table_waits_by_table(eae2a253d7e93863).(PFS_table_sharecxx . . $ PFS_table_share# *pfs)
242 {
243 pfs->aggregatecxx . . $ PFS_table_share#aggregate(49f6e7a06ebc5aa8).();
244 }
245
246 void reset_table_waits_by_tablecxx . . $ reset_table_waits_by_table(49f6e7a06ebc5aa8).()
247 {
248 global_table_share_containercxx . . $ global_table_share_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_table_waits_by_tablecxx . . $ fct_reset_table_waits_by_table(eae2a253d7e93863).);
249 }
250
251 static void fct_reset_table_io_waits_by_tablecxx . . $ fct_reset_table_io_waits_by_table(eae2a253d7e93863).(PFS_table_sharecxx . . $ PFS_table_share# *pfs)
252 {
253 pfs->aggregate_iocxx . . $ PFS_table_share#aggregate_io(49f6e7a06ebc5aa8).();
254 }
255
256 void reset_table_io_waits_by_tablecxx . . $ reset_table_io_waits_by_table(49f6e7a06ebc5aa8).()
257 {
258 global_table_share_containercxx . . $ global_table_share_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_table_io_waits_by_tablecxx . . $ fct_reset_table_io_waits_by_table(eae2a253d7e93863).);
259 }
260
261 static void fct_reset_table_lock_waits_by_tablecxx . . $ fct_reset_table_lock_waits_by_table(eae2a253d7e93863).(PFS_table_sharecxx . . $ PFS_table_share# *pfs)
262 {
263 pfs->aggregate_lockcxx . . $ PFS_table_share#aggregate_lock(49f6e7a06ebc5aa8).();
264 }
265
266 void reset_table_lock_waits_by_tablecxx . . $ reset_table_lock_waits_by_table(49f6e7a06ebc5aa8).()
267 {
268 global_table_share_containercxx . . $ global_table_share_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_table_lock_waits_by_tablecxx . . $ fct_reset_table_lock_waits_by_table(eae2a253d7e93863).);
269 }
270
271 void fct_reset_table_waits_by_table_handlecxx . . $ fct_reset_table_waits_by_table_handle(17212f03a4fb3f0d).(PFS_tablecxx . . $ PFS_table# *pfs)
272 {
273 pfs->sanitized_aggregatecxx . . $ PFS_table#sanitized_aggregate(49f6e7a06ebc5aa8).();
274 }
275
276 void reset_table_waits_by_table_handlecxx . . $ reset_table_waits_by_table_handle(49f6e7a06ebc5aa8).()
277 {
278 global_table_containercxx . . $ global_table_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_table_waits_by_table_handlecxx . . $ fct_reset_table_waits_by_table_handle(17212f03a4fb3f0d).);
279 }
280
281 void fct_reset_table_io_waits_by_table_handlecxx . . $ fct_reset_table_io_waits_by_table_handle(17212f03a4fb3f0d).(PFS_tablecxx . . $ PFS_table# *pfs)
282 {
283 pfs->sanitized_aggregate_iocxx . . $ PFS_table#sanitized_aggregate_io(49f6e7a06ebc5aa8).();
284 }
285
286 void reset_table_io_waits_by_table_handlecxx . . $ reset_table_io_waits_by_table_handle(49f6e7a06ebc5aa8).()
287 {
288 global_table_containercxx . . $ global_table_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_table_io_waits_by_table_handlecxx . . $ fct_reset_table_io_waits_by_table_handle(17212f03a4fb3f0d).);
289 }
290
291 void fct_reset_table_lock_waits_by_table_handlecxx . . $ fct_reset_table_lock_waits_by_table_handle(17212f03a4fb3f0d).(PFS_tablecxx . . $ PFS_table# *pfs)
292 {
293 pfs->sanitized_aggregate_lockcxx . . $ PFS_table#sanitized_aggregate_lock(49f6e7a06ebc5aa8).();
294 }
295
296 void reset_table_lock_waits_by_table_handlecxx . . $ reset_table_lock_waits_by_table_handle(49f6e7a06ebc5aa8).()
297 {
298 global_table_containercxx . . $ global_table_container..applycxx . . $ PFS_buffer_scalable_container#apply(56a1e2153553a317).(fct_reset_table_lock_waits_by_table_handlecxx . . $ fct_reset_table_lock_waits_by_table_handle(17212f03a4fb3f0d).);
299 }
300