1/* Copyright (c) 2010, 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 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#include "my_global.h"
17#include "my_sys.h"
18#include "pfs_visitor.h"
19#include "pfs_instr.h"
20#include "pfs_instr_class.h"
21#include "pfs_user.h"
22#include "pfs_host.h"
23#include "pfs_account.h"
24
25/**
26 @file storage/perfschema/pfs_visitor.cc
27 Visitors (implementation).
28*/
29
30/**
31 @addtogroup Performance_schema_buffers
32 @{
33*/
34
35/** Connection iterator */
36void PFS_connection_iterator::visit_global(bool with_hosts, bool with_users,
37 bool with_accounts, bool with_threads,
38 PFS_connection_visitor *visitor)
39{
40 DBUG_ASSERT(visitor != NULL);
41
42 visitor->visit_global();
43
44 if (with_hosts)
45 {
46 PFS_host *pfs= host_array;
47 PFS_host *pfs_last= pfs + host_max;
48 for ( ; pfs < pfs_last; pfs++)
49 {
50 if (pfs->m_lock.is_populated())
51 visitor->visit_host(pfs);
52 }
53 }
54
55 if (with_users)
56 {
57 PFS_user *pfs= user_array;
58 PFS_user *pfs_last= pfs + user_max;
59 for ( ; pfs < pfs_last; pfs++)
60 {
61 if (pfs->m_lock.is_populated())
62 visitor->visit_user(pfs);
63 }
64 }
65
66 if (with_accounts)
67 {
68 PFS_account *pfs= account_array;
69 PFS_account *pfs_last= pfs + account_max;
70 for ( ; pfs < pfs_last; pfs++)
71 {
72 if (pfs->m_lock.is_populated())
73 visitor->visit_account(pfs);
74 }
75 }
76
77 if (with_threads)
78 {
79 PFS_thread *pfs= thread_array;
80 PFS_thread *pfs_last= pfs + thread_max;
81 for ( ; pfs < pfs_last; pfs++)
82 {
83 if (pfs->m_lock.is_populated())
84 visitor->visit_thread(pfs);
85 }
86 }
87}
88
89void PFS_connection_iterator::visit_host(PFS_host *host,
90 bool with_accounts, bool with_threads,
91 PFS_connection_visitor *visitor)
92{
93 DBUG_ASSERT(visitor != NULL);
94
95 visitor->visit_host(host);
96
97 if (with_accounts)
98 {
99 PFS_account *pfs= account_array;
100 PFS_account *pfs_last= pfs + account_max;
101 for ( ; pfs < pfs_last; pfs++)
102 {
103 if ((pfs->m_host == host) && pfs->m_lock.is_populated())
104 {
105 visitor->visit_account(pfs);
106 }
107 }
108 }
109
110 if (with_threads)
111 {
112 PFS_thread *pfs= thread_array;
113 PFS_thread *pfs_last= pfs + thread_max;
114 for ( ; pfs < pfs_last; pfs++)
115 {
116 if (pfs->m_lock.is_populated())
117 {
118 PFS_account *safe_account= sanitize_account(pfs->m_account);
119 if ((safe_account != NULL) && (safe_account->m_host == host))
120 {
121 /*
122 If the thread belongs to a known user@host that belongs to this host,
123 process it.
124 */
125 visitor->visit_thread(pfs);
126 }
127 else if (pfs->m_host == host)
128 {
129 /*
130 If the thread belongs to a 'lost' user@host that belong to this host,
131 process it.
132 */
133 visitor->visit_thread(pfs);
134 }
135 }
136 }
137 }
138}
139
140void PFS_connection_iterator::visit_user(PFS_user *user,
141 bool with_accounts, bool with_threads,
142 PFS_connection_visitor *visitor)
143{
144 DBUG_ASSERT(visitor != NULL);
145
146 visitor->visit_user(user);
147
148 if (with_accounts)
149 {
150 PFS_account *pfs= account_array;
151 PFS_account *pfs_last= pfs + account_max;
152 for ( ; pfs < pfs_last; pfs++)
153 {
154 if ((pfs->m_user == user) && pfs->m_lock.is_populated())
155 {
156 visitor->visit_account(pfs);
157 }
158 }
159 }
160
161 if (with_threads)
162 {
163 PFS_thread *pfs= thread_array;
164 PFS_thread *pfs_last= pfs + thread_max;
165 for ( ; pfs < pfs_last; pfs++)
166 {
167 if (pfs->m_lock.is_populated())
168 {
169 PFS_account *safe_account= sanitize_account(pfs->m_account);
170 if ((safe_account != NULL) && (safe_account->m_user == user))
171 {
172 /*
173 If the thread belongs to a known user@host that belongs to this user,
174 process it.
175 */
176 visitor->visit_thread(pfs);
177 }
178 else if (pfs->m_user == user)
179 {
180 /*
181 If the thread belongs to a 'lost' user@host that belong to this user,
182 process it.
183 */
184 visitor->visit_thread(pfs);
185 }
186 }
187 }
188 }
189}
190
191void PFS_connection_iterator::visit_account(PFS_account *account,
192 bool with_threads,
193 PFS_connection_visitor *visitor)
194{
195 DBUG_ASSERT(visitor != NULL);
196
197 visitor->visit_account(account);
198
199 if (with_threads)
200 {
201 PFS_thread *pfs= thread_array;
202 PFS_thread *pfs_last= pfs + thread_max;
203 for ( ; pfs < pfs_last; pfs++)
204 {
205 if ((pfs->m_account == account) && pfs->m_lock.is_populated())
206 {
207 visitor->visit_thread(pfs);
208 }
209 }
210 }
211}
212
213void PFS_instance_iterator::visit_all(PFS_instance_visitor *visitor)
214{
215 visit_all_mutex(visitor);
216 visit_all_rwlock(visitor);
217 visit_all_cond(visitor);
218 visit_all_file(visitor);
219}
220
221void PFS_instance_iterator::visit_all_mutex(PFS_instance_visitor *visitor)
222{
223 visit_all_mutex_classes(visitor);
224 visit_all_mutex_instances(visitor);
225}
226
227void PFS_instance_iterator::visit_all_mutex_classes(PFS_instance_visitor *visitor)
228{
229 PFS_mutex_class *pfs= mutex_class_array;
230 PFS_mutex_class *pfs_last= pfs + mutex_class_max;
231 for ( ; pfs < pfs_last; pfs++)
232 {
233 if (pfs->m_name_length != 0)
234 {
235 visitor->visit_mutex_class(pfs);
236 }
237 }
238}
239
240void PFS_instance_iterator::visit_all_mutex_instances(PFS_instance_visitor *visitor)
241{
242 PFS_mutex *pfs= mutex_array;
243 PFS_mutex *pfs_last= pfs + mutex_max;
244 for ( ; pfs < pfs_last; pfs++)
245 {
246 if (pfs->m_lock.is_populated())
247 {
248 visitor->visit_mutex(pfs);
249 }
250 }
251}
252
253void PFS_instance_iterator::visit_all_rwlock(PFS_instance_visitor *visitor)
254{
255 visit_all_rwlock_classes(visitor);
256 visit_all_rwlock_instances(visitor);
257}
258
259void PFS_instance_iterator::visit_all_rwlock_classes(PFS_instance_visitor *visitor)
260{
261 PFS_rwlock_class *pfs= rwlock_class_array;
262 PFS_rwlock_class *pfs_last= pfs + rwlock_class_max;
263 for ( ; pfs < pfs_last; pfs++)
264 {
265 if (pfs->m_name_length != 0)
266 {
267 visitor->visit_rwlock_class(pfs);
268 }
269 }
270}
271
272void PFS_instance_iterator::visit_all_rwlock_instances(PFS_instance_visitor *visitor)
273{
274 PFS_rwlock *pfs= rwlock_array;
275 PFS_rwlock *pfs_last= pfs + rwlock_max;
276 for ( ; pfs < pfs_last; pfs++)
277 {
278 if (pfs->m_lock.is_populated())
279 {
280 visitor->visit_rwlock(pfs);
281 }
282 }
283}
284
285void PFS_instance_iterator::visit_all_cond(PFS_instance_visitor *visitor)
286{
287 visit_all_cond_classes(visitor);
288 visit_all_cond_instances(visitor);
289}
290
291void PFS_instance_iterator::visit_all_cond_classes(PFS_instance_visitor *visitor)
292{
293 PFS_cond_class *pfs= cond_class_array;
294 PFS_cond_class *pfs_last= pfs + cond_class_max;
295 for ( ; pfs < pfs_last; pfs++)
296 {
297 if (pfs->m_name_length != 0)
298 {
299 visitor->visit_cond_class(pfs);
300 }
301 }
302}
303
304void PFS_instance_iterator::visit_all_cond_instances(PFS_instance_visitor *visitor)
305{
306 PFS_cond *pfs= cond_array;
307 PFS_cond *pfs_last= pfs + cond_max;
308 for ( ; pfs < pfs_last; pfs++)
309 {
310 if (pfs->m_lock.is_populated())
311 {
312 visitor->visit_cond(pfs);
313 }
314 }
315}
316
317void PFS_instance_iterator::visit_all_file(PFS_instance_visitor *visitor)
318{
319 visit_all_file_classes(visitor);
320 visit_all_file_instances(visitor);
321}
322
323void PFS_instance_iterator::visit_all_file_classes(PFS_instance_visitor *visitor)
324{
325 PFS_file_class *pfs= file_class_array;
326 PFS_file_class *pfs_last= pfs + file_class_max;
327 for ( ; pfs < pfs_last; pfs++)
328 {
329 if (pfs->m_name_length != 0)
330 {
331 visitor->visit_file_class(pfs);
332 }
333 }
334}
335
336void PFS_instance_iterator::visit_all_file_instances(PFS_instance_visitor *visitor)
337{
338 PFS_file *pfs= file_array;
339 PFS_file *pfs_last= pfs + file_max;
340 for ( ; pfs < pfs_last; pfs++)
341 {
342 if (pfs->m_lock.is_populated())
343 {
344 visitor->visit_file(pfs);
345 }
346 }
347}
348
349/** Instance iterator */
350
351void PFS_instance_iterator::visit_mutex_instances(PFS_mutex_class *klass,
352 PFS_instance_visitor *visitor)
353{
354 DBUG_ASSERT(visitor != NULL);
355
356 visitor->visit_mutex_class(klass);
357
358 if (klass->is_singleton())
359 {
360 PFS_mutex *pfs= sanitize_mutex(klass->m_singleton);
361 if (likely(pfs != NULL))
362 {
363 if (likely(pfs->m_lock.is_populated()))
364 {
365 visitor->visit_mutex(pfs);
366 }
367 }
368 }
369 else
370 {
371 PFS_mutex *pfs= mutex_array;
372 PFS_mutex *pfs_last= pfs + mutex_max;
373 for ( ; pfs < pfs_last; pfs++)
374 {
375 if ((pfs->m_class == klass) && pfs->m_lock.is_populated())
376 {
377 visitor->visit_mutex(pfs);
378 }
379 }
380 }
381}
382
383void PFS_instance_iterator::visit_rwlock_instances(PFS_rwlock_class *klass,
384 PFS_instance_visitor *visitor)
385{
386 DBUG_ASSERT(visitor != NULL);
387
388 visitor->visit_rwlock_class(klass);
389
390 if (klass->is_singleton())
391 {
392 PFS_rwlock *pfs= sanitize_rwlock(klass->m_singleton);
393 if (likely(pfs != NULL))
394 {
395 if (likely(pfs->m_lock.is_populated()))
396 {
397 visitor->visit_rwlock(pfs);
398 }
399 }
400 }
401 else
402 {
403 PFS_rwlock *pfs= rwlock_array;
404 PFS_rwlock *pfs_last= pfs + rwlock_max;
405 for ( ; pfs < pfs_last; pfs++)
406 {
407 if ((pfs->m_class == klass) && pfs->m_lock.is_populated())
408 {
409 visitor->visit_rwlock(pfs);
410 }
411 }
412 }
413}
414
415void PFS_instance_iterator::visit_cond_instances(PFS_cond_class *klass,
416 PFS_instance_visitor *visitor)
417{
418 DBUG_ASSERT(visitor != NULL);
419
420 visitor->visit_cond_class(klass);
421
422 if (klass->is_singleton())
423 {
424 PFS_cond *pfs= sanitize_cond(klass->m_singleton);
425 if (likely(pfs != NULL))
426 {
427 if (likely(pfs->m_lock.is_populated()))
428 {
429 visitor->visit_cond(pfs);
430 }
431 }
432 }
433 else
434 {
435 PFS_cond *pfs= cond_array;
436 PFS_cond *pfs_last= pfs + cond_max;
437 for ( ; pfs < pfs_last; pfs++)
438 {
439 if ((pfs->m_class == klass) && pfs->m_lock.is_populated())
440 {
441 visitor->visit_cond(pfs);
442 }
443 }
444 }
445}
446
447void PFS_instance_iterator::visit_file_instances(PFS_file_class *klass,
448 PFS_instance_visitor *visitor)
449{
450 DBUG_ASSERT(visitor != NULL);
451
452 visitor->visit_file_class(klass);
453
454 if (klass->is_singleton())
455 {
456 PFS_file *pfs= sanitize_file(klass->m_singleton);
457 if (likely(pfs != NULL))
458 {
459 if (likely(pfs->m_lock.is_populated()))
460 {
461 visitor->visit_file(pfs);
462 }
463 }
464 }
465 else
466 {
467 PFS_file *pfs= file_array;
468 PFS_file *pfs_last= pfs + file_max;
469 for ( ; pfs < pfs_last; pfs++)
470 {
471 if ((pfs->m_class == klass) && pfs->m_lock.is_populated())
472 {
473 visitor->visit_file(pfs);
474 }
475 }
476 }
477}
478
479/** Socket instance iterator visting a socket class and all instances */
480
481void PFS_instance_iterator::visit_socket_instances(PFS_socket_class *klass,
482 PFS_instance_visitor *visitor)
483{
484 DBUG_ASSERT(visitor != NULL);
485
486 visitor->visit_socket_class(klass);
487
488 if (klass->is_singleton())
489 {
490 PFS_socket *pfs= sanitize_socket(klass->m_singleton);
491 if (likely(pfs != NULL))
492 {
493 if (likely(pfs->m_lock.is_populated()))
494 {
495 visitor->visit_socket(pfs);
496 }
497 }
498 }
499 else
500 {
501 PFS_socket *pfs= socket_array;
502 PFS_socket *pfs_last= pfs + socket_max;
503 for ( ; pfs < pfs_last; pfs++)
504 {
505 if ((pfs->m_class == klass) && pfs->m_lock.is_populated())
506 {
507 visitor->visit_socket(pfs);
508 }
509 }
510 }
511}
512
513/** Socket instance iterator visting sockets owned by PFS_thread. */
514
515void PFS_instance_iterator::visit_socket_instances(PFS_socket_class *klass,
516 PFS_instance_visitor *visitor,
517 PFS_thread *thread,
518 bool visit_class)
519{
520 DBUG_ASSERT(visitor != NULL);
521 DBUG_ASSERT(thread != NULL);
522
523 if (visit_class)
524 visitor->visit_socket_class(klass);
525
526 if (klass->is_singleton())
527 {
528 PFS_socket *pfs= sanitize_socket(klass->m_singleton);
529 if (likely(pfs != NULL))
530 {
531 if (unlikely(pfs->m_thread_owner == thread))
532 visitor->visit_socket(pfs);
533 }
534 }
535 else
536 {
537 /* Get current socket stats from each socket instance owned by this thread */
538 PFS_socket *pfs= socket_array;
539 PFS_socket *pfs_last= pfs + socket_max;
540
541 for ( ; pfs < pfs_last; pfs++)
542 {
543 if (unlikely((pfs->m_class == klass) &&
544 (pfs->m_thread_owner == thread)))
545 {
546 visitor->visit_socket(pfs);
547 }
548 }
549 }
550}
551
552/** Generic instance iterator with PFS_thread as matching criteria */
553
554void PFS_instance_iterator::visit_instances(PFS_instr_class *klass,
555 PFS_instance_visitor *visitor,
556 PFS_thread *thread,
557 bool visit_class)
558{
559 DBUG_ASSERT(visitor != NULL);
560 DBUG_ASSERT(klass != NULL);
561
562 switch (klass->m_type)
563 {
564 case PFS_CLASS_SOCKET:
565 {
566 PFS_socket_class *socket_class= reinterpret_cast<PFS_socket_class*>(klass);
567 PFS_instance_iterator::visit_socket_instances(socket_class, visitor,
568 thread, visit_class);
569 }
570 break;
571 default:
572 break;
573 }
574}
575
576/** Object iterator */
577void PFS_object_iterator::visit_all(PFS_object_visitor *visitor)
578{
579 visit_all_tables(visitor);
580}
581
582void PFS_object_iterator::visit_all_tables(PFS_object_visitor *visitor)
583{
584 DBUG_ASSERT(visitor != NULL);
585
586 visitor->visit_global();
587
588 /* For all the table shares ... */
589 PFS_table_share *share= table_share_array;
590 PFS_table_share *share_last= table_share_array + table_share_max;
591 for ( ; share < share_last; share++)
592 {
593 if (share->m_lock.is_populated())
594 {
595 visitor->visit_table_share(share);
596 }
597 }
598
599 /* For all the table handles ... */
600 PFS_table *table= table_array;
601 PFS_table *table_last= table_array + table_max;
602 for ( ; table < table_last; table++)
603 {
604 if (table->m_lock.is_populated())
605 {
606 visitor->visit_table(table);
607 }
608 }
609}
610
611void PFS_object_iterator::visit_tables(PFS_table_share *share,
612 PFS_object_visitor *visitor)
613{
614 DBUG_ASSERT(visitor != NULL);
615
616 visitor->visit_table_share(share);
617
618 /* For all the table handles ... */
619 PFS_table *table= table_array;
620 PFS_table *table_last= table_array + table_max;
621 for ( ; table < table_last; table++)
622 {
623 if ((table->m_share == share) && table->m_lock.is_populated())
624 {
625 visitor->visit_table(table);
626 }
627 }
628}
629
630void PFS_object_iterator::visit_table_indexes(PFS_table_share *share,
631 uint index,
632 PFS_object_visitor *visitor)
633{
634 DBUG_ASSERT(visitor != NULL);
635
636 visitor->visit_table_share_index(share, index);
637
638 /* For all the table handles ... */
639 PFS_table *table= table_array;
640 PFS_table *table_last= table_array + table_max;
641 for ( ; table < table_last; table++)
642 {
643 if ((table->m_share == share) && table->m_lock.is_populated())
644 {
645 visitor->visit_table_index(table, index);
646 }
647 }
648}
649
650/** Connection wait visitor */
651
652PFS_connection_wait_visitor
653::PFS_connection_wait_visitor(PFS_instr_class *klass)
654{
655 m_index= klass->m_event_name_index;
656}
657
658PFS_connection_wait_visitor::~PFS_connection_wait_visitor()
659{}
660
661void PFS_connection_wait_visitor::visit_global()
662{
663 /*
664 This visitor is used only for idle instruments.
665 For waits, do not sum by connection but by instances,
666 it is more efficient.
667 */
668 DBUG_ASSERT(m_index == global_idle_class.m_event_name_index);
669 m_stat.aggregate(& global_idle_stat);
670}
671
672void PFS_connection_wait_visitor::visit_host(PFS_host *pfs)
673{
674 m_stat.aggregate(& pfs->m_instr_class_waits_stats[m_index]);
675}
676
677void PFS_connection_wait_visitor::visit_user(PFS_user *pfs)
678{
679 m_stat.aggregate(& pfs->m_instr_class_waits_stats[m_index]);
680}
681
682void PFS_connection_wait_visitor::visit_account(PFS_account *pfs)
683{
684 m_stat.aggregate(& pfs->m_instr_class_waits_stats[m_index]);
685}
686
687void PFS_connection_wait_visitor::visit_thread(PFS_thread *pfs)
688{
689 m_stat.aggregate(& pfs->m_instr_class_waits_stats[m_index]);
690}
691
692PFS_connection_all_wait_visitor
693::PFS_connection_all_wait_visitor()
694{}
695
696PFS_connection_all_wait_visitor::~PFS_connection_all_wait_visitor()
697{}
698
699void PFS_connection_all_wait_visitor::visit_global()
700{
701 /* Sum by instances, not by connection */
702 DBUG_ASSERT(false);
703}
704
705void PFS_connection_all_wait_visitor::visit_connection_slice(PFS_connection_slice *pfs)
706{
707 PFS_single_stat *stat= pfs->m_instr_class_waits_stats;
708 PFS_single_stat *stat_last= stat + wait_class_max;
709 for ( ; stat < stat_last; stat++)
710 {
711 m_stat.aggregate(stat);
712 }
713}
714
715void PFS_connection_all_wait_visitor::visit_host(PFS_host *pfs)
716{
717 visit_connection_slice(pfs);
718}
719
720void PFS_connection_all_wait_visitor::visit_user(PFS_user *pfs)
721{
722 visit_connection_slice(pfs);
723}
724
725void PFS_connection_all_wait_visitor::visit_account(PFS_account *pfs)
726{
727 visit_connection_slice(pfs);
728}
729
730void PFS_connection_all_wait_visitor::visit_thread(PFS_thread *pfs)
731{
732 visit_connection_slice(pfs);
733}
734
735PFS_connection_stage_visitor::PFS_connection_stage_visitor(PFS_stage_class *klass)
736{
737 m_index= klass->m_event_name_index;
738}
739
740PFS_connection_stage_visitor::~PFS_connection_stage_visitor()
741{}
742
743void PFS_connection_stage_visitor::visit_global()
744{
745 m_stat.aggregate(& global_instr_class_stages_array[m_index]);
746}
747
748void PFS_connection_stage_visitor::visit_host(PFS_host *pfs)
749{
750 m_stat.aggregate(& pfs->m_instr_class_stages_stats[m_index]);
751}
752
753void PFS_connection_stage_visitor::visit_user(PFS_user *pfs)
754{
755 m_stat.aggregate(& pfs->m_instr_class_stages_stats[m_index]);
756}
757
758void PFS_connection_stage_visitor::visit_account(PFS_account *pfs)
759{
760 m_stat.aggregate(& pfs->m_instr_class_stages_stats[m_index]);
761}
762
763void PFS_connection_stage_visitor::visit_thread(PFS_thread *pfs)
764{
765 m_stat.aggregate(& pfs->m_instr_class_stages_stats[m_index]);
766}
767
768PFS_connection_statement_visitor
769::PFS_connection_statement_visitor(PFS_statement_class *klass)
770{
771 m_index= klass->m_event_name_index;
772}
773
774PFS_connection_statement_visitor::~PFS_connection_statement_visitor()
775{}
776
777void PFS_connection_statement_visitor::visit_global()
778{
779 m_stat.aggregate(& global_instr_class_statements_array[m_index]);
780}
781
782void PFS_connection_statement_visitor::visit_host(PFS_host *pfs)
783{
784 m_stat.aggregate(& pfs->m_instr_class_statements_stats[m_index]);
785}
786
787void PFS_connection_statement_visitor::visit_user(PFS_user *pfs)
788{
789 m_stat.aggregate(& pfs->m_instr_class_statements_stats[m_index]);
790}
791
792void PFS_connection_statement_visitor::visit_account(PFS_account *pfs)
793{
794 m_stat.aggregate(& pfs->m_instr_class_statements_stats[m_index]);
795}
796
797void PFS_connection_statement_visitor::visit_thread(PFS_thread *pfs)
798{
799 m_stat.aggregate(& pfs->m_instr_class_statements_stats[m_index]);
800}
801
802/** Instance wait visitor */
803PFS_connection_all_statement_visitor
804::PFS_connection_all_statement_visitor()
805{}
806
807PFS_connection_all_statement_visitor::~PFS_connection_all_statement_visitor()
808{}
809
810void PFS_connection_all_statement_visitor::visit_global()
811{
812 PFS_statement_stat *stat= global_instr_class_statements_array;
813 PFS_statement_stat *stat_last= stat + statement_class_max;
814 for ( ; stat < stat_last; stat++)
815 {
816 m_stat.aggregate(stat);
817 }
818}
819
820void PFS_connection_all_statement_visitor::visit_connection_slice(PFS_connection_slice *pfs)
821{
822 PFS_statement_stat *stat= pfs->m_instr_class_statements_stats;
823 PFS_statement_stat *stat_last= stat + statement_class_max;
824 for ( ; stat < stat_last; stat++)
825 {
826 m_stat.aggregate(stat);
827 }
828}
829
830void PFS_connection_all_statement_visitor::visit_host(PFS_host *pfs)
831{
832 visit_connection_slice(pfs);
833}
834
835void PFS_connection_all_statement_visitor::visit_user(PFS_user *pfs)
836{
837 visit_connection_slice(pfs);
838}
839
840void PFS_connection_all_statement_visitor::visit_account(PFS_account *pfs)
841{
842 visit_connection_slice(pfs);
843}
844
845void PFS_connection_all_statement_visitor::visit_thread(PFS_thread *pfs)
846{
847 visit_connection_slice(pfs);
848}
849
850PFS_connection_stat_visitor::PFS_connection_stat_visitor()
851{}
852
853PFS_connection_stat_visitor::~PFS_connection_stat_visitor()
854{}
855
856void PFS_connection_stat_visitor::visit_global()
857{}
858
859void PFS_connection_stat_visitor::visit_host(PFS_host *pfs)
860{
861 m_stat.aggregate_disconnected(pfs->m_disconnected_count);
862}
863
864void PFS_connection_stat_visitor::visit_user(PFS_user *pfs)
865{
866 m_stat.aggregate_disconnected(pfs->m_disconnected_count);
867}
868
869void PFS_connection_stat_visitor::visit_account(PFS_account *pfs)
870{
871 m_stat.aggregate_disconnected(pfs->m_disconnected_count);
872}
873
874void PFS_connection_stat_visitor::visit_thread(PFS_thread *)
875{
876 m_stat.aggregate_active(1);
877}
878
879PFS_instance_wait_visitor::PFS_instance_wait_visitor()
880{
881}
882
883PFS_instance_wait_visitor::~PFS_instance_wait_visitor()
884{}
885
886void PFS_instance_wait_visitor::visit_mutex_class(PFS_mutex_class *pfs)
887{
888 m_stat.aggregate(&pfs->m_mutex_stat.m_wait_stat);
889}
890
891void PFS_instance_wait_visitor::visit_rwlock_class(PFS_rwlock_class *pfs)
892{
893 m_stat.aggregate(&pfs->m_rwlock_stat.m_wait_stat);
894}
895
896void PFS_instance_wait_visitor::visit_cond_class(PFS_cond_class *pfs)
897{
898 m_stat.aggregate(&pfs->m_cond_stat.m_wait_stat);
899}
900
901void PFS_instance_wait_visitor::visit_file_class(PFS_file_class *pfs)
902{
903 pfs->m_file_stat.m_io_stat.sum_waits(&m_stat);
904}
905
906void PFS_instance_wait_visitor::visit_socket_class(PFS_socket_class *pfs)
907{
908 pfs->m_socket_stat.m_io_stat.sum_waits(&m_stat);
909}
910
911void PFS_instance_wait_visitor::visit_mutex(PFS_mutex *pfs)
912{
913 m_stat.aggregate(& pfs->m_mutex_stat.m_wait_stat);
914}
915
916void PFS_instance_wait_visitor::visit_rwlock(PFS_rwlock *pfs)
917{
918 m_stat.aggregate(& pfs->m_rwlock_stat.m_wait_stat);
919}
920
921void PFS_instance_wait_visitor::visit_cond(PFS_cond *pfs)
922{
923 m_stat.aggregate(& pfs->m_cond_stat.m_wait_stat);
924}
925
926void PFS_instance_wait_visitor::visit_file(PFS_file *pfs)
927{
928 /* Combine per-operation file wait stats before aggregating */
929 PFS_single_stat stat;
930 pfs->m_file_stat.m_io_stat.sum_waits(&stat);
931 m_stat.aggregate(&stat);
932}
933
934void PFS_instance_wait_visitor::visit_socket(PFS_socket *pfs)
935{
936 /* Combine per-operation socket wait stats before aggregating */
937 PFS_single_stat stat;
938 pfs->m_socket_stat.m_io_stat.sum_waits(&stat);
939 m_stat.aggregate(&stat);
940}
941
942/** Table IO wait visitor */
943
944PFS_object_wait_visitor::PFS_object_wait_visitor()
945{}
946
947PFS_object_wait_visitor::~PFS_object_wait_visitor()
948{}
949
950void PFS_object_wait_visitor::visit_global()
951{
952 global_table_io_stat.sum(& m_stat);
953 global_table_lock_stat.sum(& m_stat);
954}
955
956void PFS_object_wait_visitor::visit_table_share(PFS_table_share *pfs)
957{
958 uint safe_key_count= sanitize_index_count(pfs->m_key_count);
959 pfs->m_table_stat.sum(& m_stat, safe_key_count);
960}
961
962void PFS_object_wait_visitor::visit_table(PFS_table *pfs)
963{
964 PFS_table_share *table_share= sanitize_table_share(pfs->m_share);
965 if (table_share != NULL)
966 {
967 uint safe_key_count= sanitize_index_count(table_share->m_key_count);
968 pfs->m_table_stat.sum(& m_stat, safe_key_count);
969 }
970}
971
972PFS_table_io_wait_visitor::PFS_table_io_wait_visitor()
973{}
974
975PFS_table_io_wait_visitor::~PFS_table_io_wait_visitor()
976{}
977
978void PFS_table_io_wait_visitor::visit_global()
979{
980 global_table_io_stat.sum(& m_stat);
981}
982
983void PFS_table_io_wait_visitor::visit_table_share(PFS_table_share *pfs)
984{
985 PFS_table_io_stat io_stat;
986 uint safe_key_count= sanitize_index_count(pfs->m_key_count);
987 uint index;
988
989 /* Aggregate index stats */
990 for (index= 0; index < safe_key_count; index++)
991 io_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]);
992
993 /* Aggregate global stats */
994 io_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]);
995
996 io_stat.sum(& m_stat);
997}
998
999void PFS_table_io_wait_visitor::visit_table(PFS_table *pfs)
1000{
1001 PFS_table_share *safe_share= sanitize_table_share(pfs->m_share);
1002
1003 if (likely(safe_share != NULL))
1004 {
1005 PFS_table_io_stat io_stat;
1006 uint safe_key_count= sanitize_index_count(safe_share->m_key_count);
1007 uint index;
1008
1009 /* Aggregate index stats */
1010 for (index= 0; index < safe_key_count; index++)
1011 io_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]);
1012
1013 /* Aggregate global stats */
1014 io_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]);
1015
1016 io_stat.sum(& m_stat);
1017 }
1018}
1019
1020/** Table IO stat visitor */
1021
1022PFS_table_io_stat_visitor::PFS_table_io_stat_visitor()
1023{}
1024
1025PFS_table_io_stat_visitor::~PFS_table_io_stat_visitor()
1026{}
1027
1028void PFS_table_io_stat_visitor::visit_table_share(PFS_table_share *pfs)
1029{
1030 uint safe_key_count= sanitize_index_count(pfs->m_key_count);
1031 uint index;
1032
1033 /* Aggregate index stats */
1034 for (index= 0; index < safe_key_count; index++)
1035 m_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]);
1036
1037 /* Aggregate global stats */
1038 m_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]);
1039}
1040
1041void PFS_table_io_stat_visitor::visit_table(PFS_table *pfs)
1042{
1043 PFS_table_share *safe_share= sanitize_table_share(pfs->m_share);
1044
1045 if (likely(safe_share != NULL))
1046 {
1047 uint safe_key_count= sanitize_index_count(safe_share->m_key_count);
1048 uint index;
1049
1050 /* Aggregate index stats */
1051 for (index= 0; index < safe_key_count; index++)
1052 m_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]);
1053
1054 /* Aggregate global stats */
1055 m_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]);
1056 }
1057}
1058
1059/** Index IO stat visitor */
1060
1061PFS_index_io_stat_visitor::PFS_index_io_stat_visitor()
1062{}
1063
1064PFS_index_io_stat_visitor::~PFS_index_io_stat_visitor()
1065{}
1066
1067void PFS_index_io_stat_visitor::visit_table_share_index(PFS_table_share *pfs, uint index)
1068{
1069 m_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]);
1070}
1071
1072void PFS_index_io_stat_visitor::visit_table_index(PFS_table *pfs, uint index)
1073{
1074 m_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]);
1075}
1076
1077/** Table lock wait visitor */
1078
1079PFS_table_lock_wait_visitor::PFS_table_lock_wait_visitor()
1080{}
1081
1082PFS_table_lock_wait_visitor::~PFS_table_lock_wait_visitor()
1083{}
1084
1085void PFS_table_lock_wait_visitor::visit_global()
1086{
1087 global_table_lock_stat.sum(& m_stat);
1088}
1089
1090void PFS_table_lock_wait_visitor::visit_table_share(PFS_table_share *pfs)
1091{
1092 pfs->m_table_stat.sum_lock(& m_stat);
1093}
1094
1095void PFS_table_lock_wait_visitor::visit_table(PFS_table *pfs)
1096{
1097 pfs->m_table_stat.sum_lock(& m_stat);
1098}
1099
1100/** Table lock stat visitor */
1101
1102PFS_table_lock_stat_visitor::PFS_table_lock_stat_visitor()
1103{}
1104
1105PFS_table_lock_stat_visitor::~PFS_table_lock_stat_visitor()
1106{}
1107
1108void PFS_table_lock_stat_visitor::visit_table_share(PFS_table_share *pfs)
1109{
1110 m_stat.aggregate(& pfs->m_table_stat.m_lock_stat);
1111}
1112
1113void PFS_table_lock_stat_visitor::visit_table(PFS_table *pfs)
1114{
1115 m_stat.aggregate(& pfs->m_table_stat.m_lock_stat);
1116}
1117
1118PFS_instance_socket_io_stat_visitor::PFS_instance_socket_io_stat_visitor()
1119{}
1120
1121PFS_instance_socket_io_stat_visitor::~PFS_instance_socket_io_stat_visitor()
1122{}
1123
1124void PFS_instance_socket_io_stat_visitor::visit_socket_class(PFS_socket_class *pfs)
1125{
1126 /* Aggregate wait times, event counts and byte counts */
1127 m_socket_io_stat.aggregate(&pfs->m_socket_stat.m_io_stat);
1128}
1129
1130void PFS_instance_socket_io_stat_visitor::visit_socket(PFS_socket *pfs)
1131{
1132 /* Aggregate wait times, event counts and byte counts */
1133 m_socket_io_stat.aggregate(&pfs->m_socket_stat.m_io_stat);
1134}
1135
1136
1137PFS_instance_file_io_stat_visitor::PFS_instance_file_io_stat_visitor()
1138{}
1139
1140PFS_instance_file_io_stat_visitor::~PFS_instance_file_io_stat_visitor()
1141{}
1142
1143void PFS_instance_file_io_stat_visitor::visit_file_class(PFS_file_class *pfs)
1144{
1145 /* Aggregate wait times, event counts and byte counts */
1146 m_file_io_stat.aggregate(&pfs->m_file_stat.m_io_stat);
1147}
1148
1149void PFS_instance_file_io_stat_visitor::visit_file(PFS_file *pfs)
1150{
1151 /* Aggregate wait times, event counts and byte counts */
1152 m_file_io_stat.aggregate(&pfs->m_file_stat.m_io_stat);
1153}
1154/** @} */
1155