1 /* Copyright (c) 2010, 2012, 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, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef MYSQL_TABLE_H
24 #define MYSQL_TABLE_H
25 
26 /**
27   @file mysql/psi/mysql_table.h
28   Instrumentation helpers for table io.
29 */
30 
31 #include "mysql/psi/psi.h"
32 
33 /**
34   @defgroup Table_instrumentation Table Instrumentation
35   @ingroup Instrumentation_interface
36   @{
37 */
38 
39 /**
40   @def MYSQL_TABLE_WAIT_VARIABLES
41   Instrumentation helper for table waits.
42   This instrumentation declares local variables.
43   Do not use a ';' after this macro
44   @param LOCKER the locker
45   @param STATE the locker state
46   @sa MYSQL_START_TABLE_IO_WAIT.
47   @sa MYSQL_END_TABLE_IO_WAIT.
48   @sa MYSQL_START_TABLE_LOCK_WAIT.
49   @sa MYSQL_END_TABLE_LOCK_WAIT.
50 */
51 #ifdef HAVE_PSI_TABLE_INTERFACE
52   #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE) \
53     struct PSI_table_locker* LOCKER; \
54     PSI_table_locker_state STATE;
55 #else
56   #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE)
57 #endif
58 
59 /**
60   @def MYSQL_TABLE_IO_WAIT
61   Instrumentation helper for table io_waits.
62   This instrumentation marks the start of a wait event.
63   @param PSI the instrumented table
64   @param OP the table operation to be performed
65   @param INDEX the table index used if any, or MAY_KEY.
66   @param FLAGS per table operation flags.
67   @sa MYSQL_END_TABLE_WAIT.
68 */
69 #ifdef HAVE_PSI_TABLE_INTERFACE
70   #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
71     {                                                         \
72       if (PSI != NULL)                                        \
73       {                                                       \
74         PSI_table_locker *locker;                             \
75         PSI_table_locker_state state;                         \
76         locker= PSI_TABLE_CALL(start_table_io_wait)           \
77           (& state, PSI, OP, INDEX, __FILE__, __LINE__);      \
78         PAYLOAD                                               \
79         if (locker != NULL)                                   \
80           PSI_TABLE_CALL(end_table_io_wait)(locker);          \
81       }                                                       \
82       else                                                    \
83       {                                                       \
84         PAYLOAD                                               \
85       }                                                       \
86     }
87 #else
88   #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
89     PAYLOAD
90 #endif
91 
92 /**
93   @def MYSQL_TABLE_LOCK_WAIT
94   Instrumentation helper for table io_waits.
95   This instrumentation marks the start of a wait event.
96   @param PSI the instrumented table
97   @param OP the table operation to be performed
98   @param INDEX the table index used if any, or MAY_KEY.
99   @param FLAGS per table operation flags.
100   @sa MYSQL_END_TABLE_WAIT.
101 */
102 #ifdef HAVE_PSI_TABLE_INTERFACE
103   #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
104     {                                                    \
105       if (PSI != NULL)                                   \
106       {                                                  \
107         PSI_table_locker *locker;                        \
108         PSI_table_locker_state state;                    \
109         locker= PSI_TABLE_CALL(start_table_lock_wait)    \
110           (& state, PSI, OP, FLAGS, __FILE__, __LINE__); \
111         PAYLOAD                                          \
112         if (locker != NULL)                              \
113           PSI_TABLE_CALL(end_table_lock_wait)(locker);   \
114       }                                                  \
115       else                                               \
116       {                                                  \
117         PAYLOAD                                          \
118       }                                                  \
119     }
120 #else
121   #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
122     PAYLOAD
123 #endif
124 
125 /**
126   @def MYSQL_START_TABLE_LOCK_WAIT
127   Instrumentation helper for table lock waits.
128   This instrumentation marks the start of a wait event.
129   @param LOCKER the locker
130   @param STATE the locker state
131   @param PSI the instrumented table
132   @param OP the table operation to be performed
133   @param FLAGS per table operation flags.
134   @sa MYSQL_END_TABLE_LOCK_WAIT.
135 */
136 #ifdef HAVE_PSI_TABLE_INTERFACE
137   #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
138     LOCKER= inline_mysql_start_table_lock_wait(STATE, PSI, \
139                                                OP, FLAGS, __FILE__, __LINE__)
140 #else
141   #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
142     do {} while (0)
143 #endif
144 
145 /**
146   @def MYSQL_END_TABLE_LOCK_WAIT
147   Instrumentation helper for table lock waits.
148   This instrumentation marks the end of a wait event.
149   @param LOCKER the locker
150   @sa MYSQL_START_TABLE_LOCK_WAIT.
151 */
152 #ifdef HAVE_PSI_TABLE_INTERFACE
153   #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
154     inline_mysql_end_table_lock_wait(LOCKER)
155 #else
156   #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
157     do {} while (0)
158 #endif
159 
160 #ifdef HAVE_PSI_TABLE_INTERFACE
161 /**
162   Instrumentation calls for MYSQL_START_TABLE_LOCK_WAIT.
163   @sa MYSQL_END_TABLE_LOCK_WAIT.
164 */
165 static inline struct PSI_table_locker *
inline_mysql_start_table_lock_wait(PSI_table_locker_state * state,struct PSI_table * psi,enum PSI_table_lock_operation op,ulong flags,const char * src_file,int src_line)166 inline_mysql_start_table_lock_wait(PSI_table_locker_state *state,
167                                    struct PSI_table *psi,
168                                    enum PSI_table_lock_operation op,
169                                    ulong flags, const char *src_file, int src_line)
170 {
171   if (psi != NULL)
172   {
173     struct PSI_table_locker *locker;
174     locker= PSI_TABLE_CALL(start_table_lock_wait)
175       (state, psi, op, flags, src_file, src_line);
176     return locker;
177   }
178   return NULL;
179 }
180 
181 /**
182   Instrumentation calls for MYSQL_END_TABLE_LOCK_WAIT.
183   @sa MYSQL_START_TABLE_LOCK_WAIT.
184 */
185 static inline void
inline_mysql_end_table_lock_wait(struct PSI_table_locker * locker)186 inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker)
187 {
188   if (locker != NULL)
189     PSI_TABLE_CALL(end_table_lock_wait)(locker);
190 }
191 #endif
192 
193 /** @} (end of group Table_instrumentation) */
194 
195 #endif
196 
197