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#ifndef PFS_VISITOR_H
17#define PFS_VISITOR_H
18
19#include "pfs_stat.h"
20
21/**
22 @file storage/perfschema/pfs_visitor.h
23 Visitors (declarations).
24*/
25
26/**
27 @addtogroup Performance_schema_buffers
28 @{
29*/
30
31struct PFS_user;
32struct PFS_account;
33struct PFS_host;
34struct PFS_thread;
35struct PFS_instr_class;
36struct PFS_mutex_class;
37struct PFS_rwlock_class;
38struct PFS_cond_class;
39struct PFS_file_class;
40struct PFS_socket_class;
41struct PFS_table_share;
42struct PFS_mutex;
43struct PFS_rwlock;
44struct PFS_cond;
45struct PFS_file;
46struct PFS_table;
47struct PFS_stage_class;
48struct PFS_statement_class;
49struct PFS_socket;
50struct PFS_connection_slice;
51
52/**
53 Interface class to visit groups of connections.
54 @sa PFS_connection_iterator
55*/
56class PFS_connection_visitor
57{
58public:
59 PFS_connection_visitor() {}
60 virtual ~PFS_connection_visitor() {}
61 /** Visit all connections. */
62 virtual void visit_global() {}
63 /** Visit all connections of a host. */
64 virtual void visit_host(PFS_host *pfs) {}
65 /** Visit all connections of a user+host. */
66 virtual void visit_account(PFS_account *pfs) {}
67 /** Visit all connections of a user. */
68 virtual void visit_user(PFS_user *pfs) {}
69 /** Visit a thread. */
70 virtual void visit_thread(PFS_thread *pfs) {}
71};
72
73/**
74 Iterator over groups of connections.
75 @sa PFS_connection_visitor
76*/
77class PFS_connection_iterator
78{
79public:
80 /**
81 Visit all connections.
82 @param with_hosts when true, visit also all hosts.
83 @param with_users when true, visit also all users.
84 @param with_accounts when true, visit also all user+host.
85 @param with_threads when true, visit also all threads.
86 @param visitor the visitor to call
87 */
88 static void visit_global(bool with_hosts, bool with_users,
89 bool with_accounts, bool with_threads,
90 PFS_connection_visitor *visitor);
91 /**
92 Visit all connections of a host.
93 @param host the host to visit.
94 @param with_accounts when true, visit also all related user+host.
95 @param with_threads when true, visit also all related threads.
96 @param visitor the visitor to call
97 */
98 static void visit_host(PFS_host *host, bool with_accounts, bool with_threads,
99 PFS_connection_visitor *visitor);
100 /**
101 Visit all connections of a user.
102 @param user the user to visit.
103 @param with_accounts when true, visit also all related user+host.
104 @param with_threads when true, visit also all related threads.
105 @param visitor the visitor to call
106 */
107 static void visit_user(PFS_user *user, bool with_accounts, bool with_threads,
108 PFS_connection_visitor *visitor);
109 /**
110 Visit all connections of a user+host.
111 @param account the user+host to visit.
112 @param with_threads when true, visit also all related threads.
113 @param visitor the visitor to call
114 */
115 static void visit_account(PFS_account *account, bool with_threads,
116 PFS_connection_visitor *visitor);
117 /**
118 Visit a thread or connection.
119 @param thread the thread to visit.
120 @param visitor the visitor to call
121 */
122 static inline void visit_thread(PFS_thread *thread,
123 PFS_connection_visitor *visitor)
124 { visitor->visit_thread(thread); }
125};
126
127/**
128 Interface class to visit groups of instrumentation point instances.
129 @sa PFS_instance_iterator
130*/
131class PFS_instance_visitor
132{
133public:
134 PFS_instance_visitor() {}
135 virtual ~PFS_instance_visitor() {}
136 /** Visit a mutex class. */
137 virtual void visit_mutex_class(PFS_mutex_class *pfs) {}
138 /** Visit a rwlock class. */
139 virtual void visit_rwlock_class(PFS_rwlock_class *pfs) {}
140 /** Visit a cond class. */
141 virtual void visit_cond_class(PFS_cond_class *pfs) {}
142 /** Visit a file class. */
143 virtual void visit_file_class(PFS_file_class *pfs) {}
144 /** Visit a socket class. */
145 virtual void visit_socket_class(PFS_socket_class *pfs) {}
146 /** Visit a mutex instance. */
147 virtual void visit_mutex(PFS_mutex *pfs) {}
148 /** Visit a rwlock instance. */
149 virtual void visit_rwlock(PFS_rwlock *pfs) {}
150 /** Visit a cond instance. */
151 virtual void visit_cond(PFS_cond *pfs) {}
152 /** Visit a file instance. */
153 virtual void visit_file(PFS_file *pfs) {}
154 /** Visit a socket instance. */
155 virtual void visit_socket(PFS_socket *pfs) {}
156};
157
158/**
159 Iterator over groups of instrumentation point instances.
160 @sa PFS_instance_visitor
161*/
162class PFS_instance_iterator
163{
164public:
165 static void visit_all(PFS_instance_visitor *visitor);
166 static void visit_all_mutex(PFS_instance_visitor *visitor);
167 static void visit_all_mutex_classes(PFS_instance_visitor *visitor);
168 static void visit_all_mutex_instances(PFS_instance_visitor *visitor);
169 static void visit_all_rwlock(PFS_instance_visitor *visitor);
170 static void visit_all_rwlock_classes(PFS_instance_visitor *visitor);
171 static void visit_all_rwlock_instances(PFS_instance_visitor *visitor);
172 static void visit_all_cond(PFS_instance_visitor *visitor);
173 static void visit_all_cond_classes(PFS_instance_visitor *visitor);
174 static void visit_all_cond_instances(PFS_instance_visitor *visitor);
175 static void visit_all_file(PFS_instance_visitor *visitor);
176 static void visit_all_file_classes(PFS_instance_visitor *visitor);
177 static void visit_all_file_instances(PFS_instance_visitor *visitor);
178
179 /**
180 Visit a mutex class and related instances.
181 @param klass the klass to visit.
182 @param visitor the visitor to call
183 */
184 static void visit_mutex_instances(PFS_mutex_class *klass,
185 PFS_instance_visitor *visitor);
186 /**
187 Visit a rwlock class and related instances.
188 @param klass the klass to visit.
189 @param visitor the visitor to call
190 */
191 static void visit_rwlock_instances(PFS_rwlock_class *klass,
192 PFS_instance_visitor *visitor);
193 /**
194 Visit a cond class and related instances.
195 @param klass the klass to visit.
196 @param visitor the visitor to call
197 */
198 static void visit_cond_instances(PFS_cond_class *klass,
199 PFS_instance_visitor *visitor);
200 /**
201 Visit a file class and related instances.
202 @param klass the klass to visit.
203 @param visitor the visitor to call
204 */
205 static void visit_file_instances(PFS_file_class *klass,
206 PFS_instance_visitor *visitor);
207 /**
208 Visit a socket class and related instances.
209 @param klass the klass to visit.
210 @param visitor the visitor to call
211 */
212 static void visit_socket_instances(PFS_socket_class *klass,
213 PFS_instance_visitor *visitor);
214 /**
215 Visit a socket class and related instances.
216 @param klass the klass to visit.
217 @param visitor the visitor to call
218 @param thread the owning thread to match
219 @param visit_class if true then visit the socket class
220 */
221 static void visit_socket_instances(PFS_socket_class *klass,
222 PFS_instance_visitor *visitor,
223 PFS_thread *thread,
224 bool visit_class= true);
225 /**
226 Visit an instrument class and related instances.
227 @param klass the klass to visit.
228 @param visitor the visitor to call
229 @param thread comparison criteria
230 @param visit_class if true then visit the class
231 */
232 static void visit_instances(PFS_instr_class *klass,
233 PFS_instance_visitor *visitor,
234 PFS_thread *thread,
235 bool visit_class= true);
236};
237
238/**
239 Interface class to visit groups of SQL objects.
240 @sa PFS_object_iterator
241*/
242class PFS_object_visitor
243{
244public:
245 PFS_object_visitor() {}
246 virtual ~PFS_object_visitor() {}
247 /** Visit global data. */
248 virtual void visit_global() {}
249 /** Visit a table share. */
250 virtual void visit_table_share(PFS_table_share *pfs) {}
251 /** Visit a table share index. */
252 virtual void visit_table_share_index(PFS_table_share *pfs, uint index) {}
253 /** Visit a table. */
254 virtual void visit_table(PFS_table *pfs) {}
255 /** Visit a table index. */
256 virtual void visit_table_index(PFS_table *pfs, uint index) {}
257};
258
259/**
260 Iterator over groups of SQL objects.
261 @sa PFS_object_visitor
262*/
263class PFS_object_iterator
264{
265public:
266 /** Visit all objects. */
267 static void visit_all(PFS_object_visitor *visitor);
268 /** Visit all tables and related handles. */
269 static void visit_all_tables(PFS_object_visitor *visitor);
270 /** Visit a table and related table handles. */
271 static void visit_tables(PFS_table_share *share,
272 PFS_object_visitor *visitor);
273 /** Visit a table index and related table handles indexes. */
274 static void visit_table_indexes(PFS_table_share *share,
275 uint index,
276 PFS_object_visitor *visitor);
277};
278
279/**
280 A concrete connection visitor that aggregates
281 wait statistics for a given event_name.
282*/
283class PFS_connection_wait_visitor : public PFS_connection_visitor
284{
285public:
286 /** Constructor. */
287 PFS_connection_wait_visitor(PFS_instr_class *klass);
288 virtual ~PFS_connection_wait_visitor();
289 virtual void visit_global();
290 virtual void visit_host(PFS_host *pfs);
291 virtual void visit_account(PFS_account *pfs);
292 virtual void visit_user(PFS_user *pfs);
293 virtual void visit_thread(PFS_thread *pfs);
294
295 /** EVENT_NAME instrument index. */
296 uint m_index;
297 /** Wait statistic collected. */
298 PFS_single_stat m_stat;
299};
300
301/**
302 A concrete connection visitor that aggregates
303 wait statistics for all events.
304*/
305class PFS_connection_all_wait_visitor : public PFS_connection_visitor
306{
307public:
308 /** Constructor. */
309 PFS_connection_all_wait_visitor();
310 virtual ~PFS_connection_all_wait_visitor();
311 virtual void visit_global();
312 virtual void visit_host(PFS_host *pfs);
313 virtual void visit_account(PFS_account *pfs);
314 virtual void visit_user(PFS_user *pfs);
315 virtual void visit_thread(PFS_thread *pfs);
316
317 /** Wait statistic collected. */
318 PFS_single_stat m_stat;
319
320private:
321 void visit_connection_slice(PFS_connection_slice *pfs);
322};
323
324/**
325 A concrete connection visitor that aggregates
326 stage statistics.
327*/
328class PFS_connection_stage_visitor : public PFS_connection_visitor
329{
330public:
331 /** Constructor. */
332 PFS_connection_stage_visitor(PFS_stage_class *klass);
333 virtual ~PFS_connection_stage_visitor();
334 virtual void visit_global();
335 virtual void visit_host(PFS_host *pfs);
336 virtual void visit_account(PFS_account *pfs);
337 virtual void visit_user(PFS_user *pfs);
338 virtual void visit_thread(PFS_thread *pfs);
339
340 /** EVENT_NAME instrument index. */
341 uint m_index;
342 /** Stage statistic collected. */
343 PFS_stage_stat m_stat;
344};
345
346/**
347 A concrete connection visitor that aggregates
348 statement statistics for a given event_name.
349*/
350class PFS_connection_statement_visitor : public PFS_connection_visitor
351{
352public:
353 /** Constructor. */
354 PFS_connection_statement_visitor(PFS_statement_class *klass);
355 virtual ~PFS_connection_statement_visitor();
356 virtual void visit_global();
357 virtual void visit_host(PFS_host *pfs);
358 virtual void visit_account(PFS_account *pfs);
359 virtual void visit_user(PFS_user *pfs);
360 virtual void visit_thread(PFS_thread *pfs);
361
362 /** EVENT_NAME instrument index. */
363 uint m_index;
364 /** Statement statistic collected. */
365 PFS_statement_stat m_stat;
366};
367
368/**
369 A concrete connection visitor that aggregates
370 statement statistics for all events.
371*/
372class PFS_connection_all_statement_visitor : public PFS_connection_visitor
373{
374public:
375 /** Constructor. */
376 PFS_connection_all_statement_visitor();
377 virtual ~PFS_connection_all_statement_visitor();
378 virtual void visit_global();
379 virtual void visit_host(PFS_host *pfs);
380 virtual void visit_account(PFS_account *pfs);
381 virtual void visit_user(PFS_user *pfs);
382 virtual void visit_thread(PFS_thread *pfs);
383
384 /** Statement statistic collected. */
385 PFS_statement_stat m_stat;
386
387private:
388 void visit_connection_slice(PFS_connection_slice *pfs);
389};
390
391/**
392 A concrete connection visitor that aggregates
393 connection statistics.
394*/
395class PFS_connection_stat_visitor : public PFS_connection_visitor
396{
397public:
398 /** Constructor. */
399 PFS_connection_stat_visitor();
400 virtual ~PFS_connection_stat_visitor();
401 virtual void visit_global();
402 virtual void visit_host(PFS_host *pfs);
403 virtual void visit_account(PFS_account *pfs);
404 virtual void visit_user(PFS_user *pfs);
405 virtual void visit_thread(PFS_thread *pfs);
406
407 /** Connection statistic collected. */
408 PFS_connection_stat m_stat;
409};
410
411/**
412 A concrete instance visitor that aggregates
413 wait statistics.
414*/
415class PFS_instance_wait_visitor : public PFS_instance_visitor
416{
417public:
418 PFS_instance_wait_visitor();
419 virtual ~PFS_instance_wait_visitor();
420 virtual void visit_mutex_class(PFS_mutex_class *pfs);
421 virtual void visit_rwlock_class(PFS_rwlock_class *pfs);
422 virtual void visit_cond_class(PFS_cond_class *pfs);
423 virtual void visit_file_class(PFS_file_class *pfs);
424 virtual void visit_socket_class(PFS_socket_class *pfs);
425 virtual void visit_mutex(PFS_mutex *pfs);
426 virtual void visit_rwlock(PFS_rwlock *pfs);
427 virtual void visit_cond(PFS_cond *pfs);
428 virtual void visit_file(PFS_file *pfs);
429 virtual void visit_socket(PFS_socket *pfs);
430
431 /** Wait statistic collected. */
432 PFS_single_stat m_stat;
433};
434
435/**
436 A concrete object visitor that aggregates
437 object wait statistics.
438*/
439class PFS_object_wait_visitor : public PFS_object_visitor
440{
441public:
442 PFS_object_wait_visitor();
443 virtual ~PFS_object_wait_visitor();
444 virtual void visit_global();
445 virtual void visit_table_share(PFS_table_share *pfs);
446 virtual void visit_table(PFS_table *pfs);
447
448 /** Object wait statistic collected. */
449 PFS_single_stat m_stat;
450};
451
452/**
453 A concrete object visitor that aggregates
454 table io wait statistics.
455*/
456class PFS_table_io_wait_visitor : public PFS_object_visitor
457{
458public:
459 PFS_table_io_wait_visitor();
460 virtual ~PFS_table_io_wait_visitor();
461 virtual void visit_global();
462 virtual void visit_table_share(PFS_table_share *pfs);
463 virtual void visit_table(PFS_table *pfs);
464
465 /** Table io wait statistic collected. */
466 PFS_single_stat m_stat;
467};
468
469/**
470 A concrete object visitor that aggregates
471 table io statistics.
472*/
473class PFS_table_io_stat_visitor : public PFS_object_visitor
474{
475public:
476 PFS_table_io_stat_visitor();
477 virtual ~PFS_table_io_stat_visitor();
478 virtual void visit_table_share(PFS_table_share *pfs);
479 virtual void visit_table(PFS_table *pfs);
480
481 /** Table io statistic collected. */
482 PFS_table_io_stat m_stat;
483};
484
485/**
486 A concrete object visitor that aggregates
487 index io statistics.
488*/
489class PFS_index_io_stat_visitor : public PFS_object_visitor
490{
491public:
492 PFS_index_io_stat_visitor();
493 virtual ~PFS_index_io_stat_visitor();
494 virtual void visit_table_share_index(PFS_table_share *pfs, uint index);
495 virtual void visit_table_index(PFS_table *pfs, uint index);
496
497 /** Index io statistic collected. */
498 PFS_table_io_stat m_stat;
499};
500
501/**
502 A concrete object visitor that aggregates
503 table lock wait statistics.
504*/
505class PFS_table_lock_wait_visitor : public PFS_object_visitor
506{
507public:
508 PFS_table_lock_wait_visitor();
509 virtual ~PFS_table_lock_wait_visitor();
510 virtual void visit_global();
511 virtual void visit_table_share(PFS_table_share *pfs);
512 virtual void visit_table(PFS_table *pfs);
513
514 /** Table lock wait statistic collected. */
515 PFS_single_stat m_stat;
516};
517
518/**
519 A concrete object visitor that aggregates
520 table lock statistics.
521*/
522class PFS_table_lock_stat_visitor : public PFS_object_visitor
523{
524public:
525 PFS_table_lock_stat_visitor();
526 virtual ~PFS_table_lock_stat_visitor();
527 virtual void visit_table_share(PFS_table_share *pfs);
528 virtual void visit_table(PFS_table *pfs);
529
530 /** Table lock statistic collected. */
531 PFS_table_lock_stat m_stat;
532};
533
534/**
535 A concrete instance visitor that aggregates
536 socket wait and byte count statistics.
537*/
538class PFS_instance_socket_io_stat_visitor : public PFS_instance_visitor
539{
540public:
541 PFS_instance_socket_io_stat_visitor();
542 virtual ~PFS_instance_socket_io_stat_visitor();
543 virtual void visit_socket_class(PFS_socket_class *pfs);
544 virtual void visit_socket(PFS_socket *pfs);
545
546 /** Wait and byte count statistics collected. */
547 PFS_socket_io_stat m_socket_io_stat;
548};
549
550/**
551 A concrete instance visitor that aggregates
552 file wait and byte count statistics.
553*/
554class PFS_instance_file_io_stat_visitor : public PFS_instance_visitor
555{
556public:
557 PFS_instance_file_io_stat_visitor();
558 virtual ~PFS_instance_file_io_stat_visitor();
559 virtual void visit_file_class(PFS_file_class *pfs);
560 virtual void visit_file(PFS_file *pfs);
561
562 /** Wait and byte count statistics collected. */
563 PFS_file_io_stat m_file_io_stat;
564};
565
566/** @} */
567#endif
568
569