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