1 /* Copyright (c) 2010, 2015, 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_STATEMENT_H
24 #define MYSQL_STATEMENT_H
25
26 /**
27 @file mysql/psi/mysql_statement.h
28 Instrumentation helpers for statements.
29 */
30
31 #include "mysql/psi/psi.h"
32
33 /**
34 @defgroup Statement_instrumentation Statement Instrumentation
35 @ingroup Instrumentation_interface
36 @{
37 */
38
39 /**
40 @def mysql_statement_register(P1, P2, P3)
41 Statement registration.
42 */
43 #ifdef HAVE_PSI_STATEMENT_INTERFACE
44 #define mysql_statement_register(P1, P2, P3) \
45 inline_mysql_statement_register(P1, P2, P3)
46 #else
47 #define mysql_statement_register(P1, P2, P3) \
48 do {} while (0)
49 #endif
50
51 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
52 #define MYSQL_DIGEST_START(LOCKER) \
53 inline_mysql_digest_start(LOCKER)
54 #else
55 #define MYSQL_DIGEST_START(LOCKER) \
56 NULL
57 #endif
58
59 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
60 #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
61 inline_mysql_digest_end(LOCKER, DIGEST)
62 #else
63 #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
64 do {} while (0)
65 #endif
66
67 #ifdef HAVE_PSI_STATEMENT_INTERFACE
68 #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS) \
69 inline_mysql_start_statement(STATE, K, DB, DB_LEN, CS, __FILE__, __LINE__)
70 #else
71 #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS) \
72 NULL
73 #endif
74
75 #ifdef HAVE_PSI_STATEMENT_INTERFACE
76 #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
77 inline_mysql_refine_statement(LOCKER, K)
78 #else
79 #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
80 NULL
81 #endif
82
83 #ifdef HAVE_PSI_STATEMENT_INTERFACE
84 #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
85 inline_mysql_set_statement_text(LOCKER, P1, P2)
86 #else
87 #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
88 do {} while (0)
89 #endif
90
91 #ifdef HAVE_PSI_STATEMENT_INTERFACE
92 #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
93 inline_mysql_set_statement_lock_time(LOCKER, P1)
94 #else
95 #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
96 do {} while (0)
97 #endif
98
99 #ifdef HAVE_PSI_STATEMENT_INTERFACE
100 #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
101 inline_mysql_set_statement_rows_sent(LOCKER, P1)
102 #else
103 #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
104 do {} while (0)
105 #endif
106
107 #ifdef HAVE_PSI_STATEMENT_INTERFACE
108 #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
109 inline_mysql_set_statement_rows_examined(LOCKER, P1)
110 #else
111 #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
112 do {} while (0)
113 #endif
114
115 #ifdef HAVE_PSI_STATEMENT_INTERFACE
116 #define MYSQL_END_STATEMENT(LOCKER, DA) \
117 inline_mysql_end_statement(LOCKER, DA)
118 #else
119 #define MYSQL_END_STATEMENT(LOCKER, DA) \
120 do {} while (0)
121 #endif
122
123 #ifdef HAVE_PSI_STATEMENT_INTERFACE
inline_mysql_statement_register(const char * category,PSI_statement_info * info,int count)124 static inline void inline_mysql_statement_register(
125 const char *category, PSI_statement_info *info, int count)
126 {
127 PSI_STATEMENT_CALL(register_statement)(category, info, count);
128 }
129
130 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
131 static inline struct PSI_digest_locker *
inline_mysql_digest_start(PSI_statement_locker * locker)132 inline_mysql_digest_start(PSI_statement_locker *locker)
133 {
134 PSI_digest_locker* digest_locker= NULL;
135
136 if (likely(locker != NULL))
137 digest_locker= PSI_DIGEST_CALL(digest_start)(locker);
138 return digest_locker;
139 }
140 #endif
141
142 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
143 static inline void
inline_mysql_digest_end(PSI_digest_locker * locker,const sql_digest_storage * digest)144 inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest)
145 {
146 if (likely(locker != NULL))
147 PSI_DIGEST_CALL(digest_end)(locker, digest);
148 }
149 #endif
150
151 static inline struct PSI_statement_locker *
inline_mysql_start_statement(PSI_statement_locker_state * state,PSI_statement_key key,const char * db,uint db_len,const CHARSET_INFO * charset,const char * src_file,int src_line)152 inline_mysql_start_statement(PSI_statement_locker_state *state,
153 PSI_statement_key key,
154 const char *db, uint db_len,
155 const CHARSET_INFO *charset,
156 const char *src_file, int src_line)
157 {
158 PSI_statement_locker *locker;
159 locker= PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset);
160 if (likely(locker != NULL))
161 PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
162 return locker;
163 }
164
165 static inline struct PSI_statement_locker *
inline_mysql_refine_statement(PSI_statement_locker * locker,PSI_statement_key key)166 inline_mysql_refine_statement(PSI_statement_locker *locker,
167 PSI_statement_key key)
168 {
169 if (likely(locker != NULL))
170 {
171 locker= PSI_STATEMENT_CALL(refine_statement)(locker, key);
172 }
173 return locker;
174 }
175
176 static inline void
inline_mysql_set_statement_text(PSI_statement_locker * locker,const char * text,uint text_len)177 inline_mysql_set_statement_text(PSI_statement_locker *locker,
178 const char *text, uint text_len)
179 {
180 if (likely(locker != NULL))
181 {
182 PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
183 }
184 }
185
186 static inline void
inline_mysql_set_statement_lock_time(PSI_statement_locker * locker,ulonglong count)187 inline_mysql_set_statement_lock_time(PSI_statement_locker *locker,
188 ulonglong count)
189 {
190 if (likely(locker != NULL))
191 {
192 PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
193 }
194 }
195
196 static inline void
inline_mysql_set_statement_rows_sent(PSI_statement_locker * locker,ulonglong count)197 inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker,
198 ulonglong count)
199 {
200 if (likely(locker != NULL))
201 {
202 PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
203 }
204 }
205
206 static inline void
inline_mysql_set_statement_rows_examined(PSI_statement_locker * locker,ulonglong count)207 inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker,
208 ulonglong count)
209 {
210 if (likely(locker != NULL))
211 {
212 PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
213 }
214 }
215
216 static inline void
inline_mysql_end_statement(struct PSI_statement_locker * locker,Diagnostics_area * stmt_da)217 inline_mysql_end_statement(struct PSI_statement_locker *locker,
218 Diagnostics_area *stmt_da)
219 {
220 PSI_STAGE_CALL(end_stage)();
221 if (likely(locker != NULL))
222 PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
223 }
224 #endif
225
226 /** @} (end of group Statement_instrumentation) */
227
228 #endif
229
230