1/* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
2 Copyright (c) 2017, MariaDB Corporation.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
16
17#ifndef MYSQL_TABLE_H
18#define MYSQL_TABLE_H
19
20/**
21 @file mysql/psi/mysql_table.h
22 Instrumentation helpers for table io.
23*/
24
25#include "mysql/psi/psi.h"
26
27/**
28 @defgroup Table_instrumentation Table Instrumentation
29 @ingroup Instrumentation_interface
30 @{
31*/
32
33#ifdef HAVE_PSI_TABLE_INTERFACE
34#define MYSQL_UNBIND_TABLE(handler) (handler)->unbind_psi()
35#define MYSQL_REBIND_TABLE(handler) (handler)->rebind_psi()
36
37#define PSI_CALL_unbind_table PSI_TABLE_CALL(unbind_table)
38#define PSI_CALL_rebind_table PSI_TABLE_CALL(rebind_table)
39#define PSI_CALL_open_table PSI_TABLE_CALL(open_table)
40#define PSI_CALL_close_table PSI_TABLE_CALL(close_table)
41#define PSI_CALL_get_table_share PSI_TABLE_CALL(get_table_share)
42#define PSI_CALL_release_table_share PSI_TABLE_CALL(release_table_share)
43#define PSI_CALL_drop_table_share PSI_TABLE_CALL(drop_table_share)
44#else
45#define MYSQL_UNBIND_TABLE(handler) do { } while(0)
46#define MYSQL_REBIND_TABLE(handler) do { } while(0)
47
48#define PSI_CALL_unbind_table(A1) do { } while(0)
49#define PSI_CALL_rebind_table(A1,A2,A3) NULL
50#define PSI_CALL_close_table(A1) do { } while(0)
51#define PSI_CALL_open_table(A1,A2) NULL
52#define PSI_CALL_get_table_share(A1,A2) NULL
53#define PSI_CALL_release_table_share(A1) do { } while(0)
54#define PSI_CALL_drop_table_share(A1,A2,A3,A4,A5) do { } while(0)
55#endif
56
57/**
58 @def MYSQL_TABLE_WAIT_VARIABLES
59 Instrumentation helper for table waits.
60 This instrumentation declares local variables.
61 Do not use a ';' after this macro
62 @param LOCKER the locker
63 @param STATE the locker state
64 @sa MYSQL_START_TABLE_IO_WAIT.
65 @sa MYSQL_END_TABLE_IO_WAIT.
66 @sa MYSQL_START_TABLE_LOCK_WAIT.
67 @sa MYSQL_END_TABLE_LOCK_WAIT.
68*/
69#ifdef HAVE_PSI_TABLE_INTERFACE
70 #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE) \
71 struct PSI_table_locker* LOCKER; \
72 PSI_table_locker_state STATE;
73#else
74 #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE)
75#endif
76
77/**
78 @def MYSQL_TABLE_IO_WAIT
79 Instrumentation helper for table io_waits.
80 This instrumentation marks the start of a wait event.
81 @param PSI the instrumented table
82 @param OP the table operation to be performed
83 @param INDEX the table index used if any, or MAY_KEY.
84 @param FLAGS per table operation flags.
85 @sa MYSQL_END_TABLE_WAIT.
86*/
87#ifdef HAVE_PSI_TABLE_INTERFACE
88 #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
89 { \
90 if (psi_likely(PSI != NULL)) \
91 { \
92 PSI_table_locker *locker; \
93 PSI_table_locker_state state; \
94 locker= PSI_TABLE_CALL(start_table_io_wait) \
95 (& state, PSI, OP, INDEX, __FILE__, __LINE__); \
96 PAYLOAD \
97 if (locker != NULL) \
98 PSI_TABLE_CALL(end_table_io_wait)(locker); \
99 } \
100 else \
101 { \
102 PAYLOAD \
103 } \
104 }
105#else
106 #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
107 PAYLOAD
108#endif
109
110/**
111 @def MYSQL_TABLE_LOCK_WAIT
112 Instrumentation helper for table io_waits.
113 This instrumentation marks the start of a wait event.
114 @param PSI the instrumented table
115 @param OP the table operation to be performed
116 @param INDEX the table index used if any, or MAY_KEY.
117 @param FLAGS per table operation flags.
118 @sa MYSQL_END_TABLE_WAIT.
119*/
120#ifdef HAVE_PSI_TABLE_INTERFACE
121 #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
122 { \
123 if (psi_likely(PSI != NULL)) \
124 { \
125 PSI_table_locker *locker; \
126 PSI_table_locker_state state; \
127 locker= PSI_TABLE_CALL(start_table_lock_wait) \
128 (& state, PSI, OP, FLAGS, __FILE__, __LINE__); \
129 PAYLOAD \
130 if (locker != NULL) \
131 PSI_TABLE_CALL(end_table_lock_wait)(locker); \
132 } \
133 else \
134 { \
135 PAYLOAD \
136 } \
137 }
138#else
139 #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
140 PAYLOAD
141#endif
142
143/**
144 @def MYSQL_START_TABLE_LOCK_WAIT
145 Instrumentation helper for table lock waits.
146 This instrumentation marks the start of a wait event.
147 @param LOCKER the locker
148 @param STATE the locker state
149 @param PSI the instrumented table
150 @param OP the table operation to be performed
151 @param FLAGS per table operation flags.
152 @sa MYSQL_END_TABLE_LOCK_WAIT.
153*/
154#ifdef HAVE_PSI_TABLE_INTERFACE
155 #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
156 LOCKER= inline_mysql_start_table_lock_wait(STATE, PSI, \
157 OP, FLAGS, __FILE__, __LINE__)
158#else
159 #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
160 do {} while (0)
161#endif
162
163/**
164 @def MYSQL_END_TABLE_LOCK_WAIT
165 Instrumentation helper for table lock waits.
166 This instrumentation marks the end of a wait event.
167 @param LOCKER the locker
168 @sa MYSQL_START_TABLE_LOCK_WAIT.
169*/
170#ifdef HAVE_PSI_TABLE_INTERFACE
171 #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
172 inline_mysql_end_table_lock_wait(LOCKER)
173#else
174 #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
175 do {} while (0)
176#endif
177
178#ifdef HAVE_PSI_TABLE_INTERFACE
179/**
180 Instrumentation calls for MYSQL_START_TABLE_LOCK_WAIT.
181 @sa MYSQL_END_TABLE_LOCK_WAIT.
182*/
183static inline struct PSI_table_locker *
184inline_mysql_start_table_lock_wait(PSI_table_locker_state *state,
185 struct PSI_table *psi,
186 enum PSI_table_lock_operation op,
187 ulong flags, const char *src_file, uint src_line)
188{
189 if (psi_likely(psi != NULL))
190 {
191 struct PSI_table_locker *locker;
192 locker= PSI_TABLE_CALL(start_table_lock_wait)
193 (state, psi, op, flags, src_file, src_line);
194 return locker;
195 }
196 return NULL;
197}
198
199/**
200 Instrumentation calls for MYSQL_END_TABLE_LOCK_WAIT.
201 @sa MYSQL_START_TABLE_LOCK_WAIT.
202*/
203static inline void
204inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker)
205{
206 if (psi_likely(locker != NULL))
207 PSI_TABLE_CALL(end_table_lock_wait)(locker);
208}
209#endif
210
211/** @} (end of group Table_instrumentation) */
212
213#endif
214
215