1 /* Copyright (c) 2011, 2020, 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
21   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef MYSQL_IDLE_H
24 #define MYSQL_IDLE_H
25 
26 /**
27   @file include/mysql/psi/mysql_idle.h
28   Instrumentation helpers for idle waits.
29 */
30 
31 #include "mysql/psi/psi_idle.h"
32 
33 #include "pfs_idle_provider.h"
34 
35 #ifndef PSI_IDLE_CALL
36 #define PSI_IDLE_CALL(M) psi_idle_service->M
37 #endif
38 
39 /**
40   @defgroup psi_api_idle Idle Instrumentation (API)
41   @ingroup psi_api
42   @{
43 */
44 
45 /**
46   @def MYSQL_START_IDLE_WAIT
47   Instrumentation helper for table io_waits.
48   This instrumentation marks the start of a wait event.
49   @param LOCKER the locker
50   @param STATE the locker state
51   @sa MYSQL_END_IDLE_WAIT.
52 */
53 #ifdef HAVE_PSI_IDLE_INTERFACE
54 #define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
55   LOCKER = inline_mysql_start_idle_wait(STATE, __FILE__, __LINE__)
56 #else
57 #define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
58   do {                                       \
59   } while (0)
60 #endif
61 
62 /**
63   @def MYSQL_END_IDLE_WAIT
64   Instrumentation helper for idle waits.
65   This instrumentation marks the end of a wait event.
66   @param LOCKER the locker
67   @sa MYSQL_START_IDLE_WAIT.
68 */
69 #ifdef HAVE_PSI_IDLE_INTERFACE
70 #define MYSQL_END_IDLE_WAIT(LOCKER) inline_mysql_end_idle_wait(LOCKER)
71 #else
72 #define MYSQL_END_IDLE_WAIT(LOCKER) \
73   do {                              \
74   } while (0)
75 #endif
76 
77 #ifdef HAVE_PSI_IDLE_INTERFACE
78 /**
79   Instrumentation calls for MYSQL_START_IDLE_WAIT.
80   @sa MYSQL_END_IDLE_WAIT.
81 */
inline_mysql_start_idle_wait(PSI_idle_locker_state * state,const char * src_file,int src_line)82 static inline struct PSI_idle_locker *inline_mysql_start_idle_wait(
83     PSI_idle_locker_state *state, const char *src_file, int src_line) {
84   struct PSI_idle_locker *locker;
85   locker = PSI_IDLE_CALL(start_idle_wait)(state, src_file, src_line);
86   return locker;
87 }
88 
89 /**
90   Instrumentation calls for MYSQL_END_IDLE_WAIT.
91   @sa MYSQL_START_IDLE_WAIT.
92 */
inline_mysql_end_idle_wait(struct PSI_idle_locker * locker)93 static inline void inline_mysql_end_idle_wait(struct PSI_idle_locker *locker) {
94   if (likely(locker != nullptr)) {
95     PSI_IDLE_CALL(end_idle_wait)(locker);
96   }
97 }
98 #endif
99 
100 /** @} (end of group psi_api_idle) */
101 
102 #endif
103