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, as
5 // 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
11 // additional permission to link the program and your derivative works
12 // with the separately licensed software that they have included with
13 // MySQL.
14 //
15 // Without limiting anything contained in the foregoing, this file,
16 // which is part of MySQL Server, is also subject to the
17 // Universal FOSS Exception, version 1.0, a copy of which can be found at
18 // http://oss.oracle.com/licenses/universal-foss-exception.
19 //
20 // This program is distributed in the hope that it will be useful, but
21 // WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 // See the GNU General Public License, version 2.0, for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with this program; if not, write to the Free Software Foundation, Inc.,
27 // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
29 #ifndef MYSQL_STATEMENT_H
30 #define MYSQL_STATEMENT_H
31
32 /**
33 @file mysql/psi/mysql_statement.h
34 Instrumentation helpers for statements.
35 */
36
37 #include "mysql/psi/psi.h"
38
39 class Diagnostics_area;
40 typedef struct charset_info_st CHARSET_INFO;
41
42 #ifndef PSI_STATEMENT_CALL
43 #define PSI_STATEMENT_CALL(M) PSI_DYNAMIC_CALL(M)
44 #endif
45
46 #ifndef PSI_DIGEST_CALL
47 #define PSI_DIGEST_CALL(M) PSI_DYNAMIC_CALL(M)
48 #endif
49
50 /**
51 @defgroup Statement_instrumentation Statement Instrumentation
52 @ingroup Instrumentation_interface
53 @{
54 */
55
56 /**
57 @def mysql_statement_register(P1, P2, P3)
58 Statement registration.
59 */
60 #ifdef HAVE_PSI_STATEMENT_INTERFACE
61 #define mysql_statement_register(P1, P2, P3) \
62 inline_mysql_statement_register(P1, P2, P3)
63 #else
64 #define mysql_statement_register(P1, P2, P3) \
65 do {} while (0)
66 #endif
67
68 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
69 #define MYSQL_DIGEST_START(LOCKER) \
70 inline_mysql_digest_start(LOCKER)
71 #else
72 #define MYSQL_DIGEST_START(LOCKER) \
73 NULL
74 #endif
75
76 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
77 #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
78 inline_mysql_digest_end(LOCKER, DIGEST)
79 #else
80 #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
81 do {} while (0)
82 #endif
83
84 #ifdef HAVE_PSI_STATEMENT_INTERFACE
85 #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS, SPS) \
86 inline_mysql_start_statement(STATE, K, DB, DB_LEN, CS, SPS, __FILE__, __LINE__)
87 #else
88 #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS, SPS) \
89 NULL
90 #endif
91
92 #ifdef HAVE_PSI_STATEMENT_INTERFACE
93 #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
94 inline_mysql_refine_statement(LOCKER, K)
95 #else
96 #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
97 NULL
98 #endif
99
100 #ifdef HAVE_PSI_STATEMENT_INTERFACE
101 #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
102 inline_mysql_set_statement_text(LOCKER, P1, P2)
103 #else
104 #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
105 do {} while (0)
106 #endif
107
108 #ifdef HAVE_PSI_STATEMENT_INTERFACE
109 #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
110 inline_mysql_set_statement_lock_time(LOCKER, P1)
111 #else
112 #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
113 do {} while (0)
114 #endif
115
116 #ifdef HAVE_PSI_STATEMENT_INTERFACE
117 #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
118 inline_mysql_set_statement_rows_sent(LOCKER, P1)
119 #else
120 #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
121 do {} while (0)
122 #endif
123
124 #ifdef HAVE_PSI_STATEMENT_INTERFACE
125 #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
126 inline_mysql_set_statement_rows_examined(LOCKER, P1)
127 #else
128 #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
129 do {} while (0)
130 #endif
131
132 #ifdef HAVE_PSI_STATEMENT_INTERFACE
133 #define MYSQL_END_STATEMENT(LOCKER, DA) \
134 inline_mysql_end_statement(LOCKER, DA)
135 #else
136 #define MYSQL_END_STATEMENT(LOCKER, DA) \
137 do {} while (0)
138 #endif
139
140 #ifdef HAVE_PSI_STATEMENT_INTERFACE
inline_mysql_statement_register(const char * category,PSI_statement_info * info,int count)141 static inline void inline_mysql_statement_register(
142 const char *category, PSI_statement_info *info, int count)
143 {
144 PSI_STATEMENT_CALL(register_statement)(category, info, count);
145 }
146
147 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
148 static inline struct PSI_digest_locker *
inline_mysql_digest_start(PSI_statement_locker * locker)149 inline_mysql_digest_start(PSI_statement_locker *locker)
150 {
151 PSI_digest_locker* digest_locker= NULL;
152
153 if (likely(locker != NULL))
154 digest_locker= PSI_DIGEST_CALL(digest_start)(locker);
155 return digest_locker;
156 }
157 #endif
158
159 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
160 static inline void
inline_mysql_digest_end(PSI_digest_locker * locker,const sql_digest_storage * digest)161 inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest)
162 {
163 if (likely(locker != NULL))
164 PSI_DIGEST_CALL(digest_end)(locker, digest);
165 }
166 #endif
167
168 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,PSI_sp_share * sp_share,const char * src_file,int src_line)169 inline_mysql_start_statement(PSI_statement_locker_state *state,
170 PSI_statement_key key,
171 const char *db, uint db_len,
172 const CHARSET_INFO *charset,
173 PSI_sp_share *sp_share,
174 const char *src_file, int src_line)
175 {
176 PSI_statement_locker *locker;
177 locker= PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset,
178 sp_share);
179 if (likely(locker != NULL))
180 PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
181 return locker;
182 }
183
184 static inline struct PSI_statement_locker *
inline_mysql_refine_statement(PSI_statement_locker * locker,PSI_statement_key key)185 inline_mysql_refine_statement(PSI_statement_locker *locker,
186 PSI_statement_key key)
187 {
188 if (likely(locker != NULL))
189 {
190 locker= PSI_STATEMENT_CALL(refine_statement)(locker, key);
191 }
192 return locker;
193 }
194
195 static inline void
inline_mysql_set_statement_text(PSI_statement_locker * locker,const char * text,uint text_len)196 inline_mysql_set_statement_text(PSI_statement_locker *locker,
197 const char *text, uint text_len)
198 {
199 if (likely(locker != NULL))
200 {
201 PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
202 }
203 }
204
205 static inline void
inline_mysql_set_statement_lock_time(PSI_statement_locker * locker,ulonglong count)206 inline_mysql_set_statement_lock_time(PSI_statement_locker *locker,
207 ulonglong count)
208 {
209 if (likely(locker != NULL))
210 {
211 PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
212 }
213 }
214
215 static inline void
inline_mysql_set_statement_rows_sent(PSI_statement_locker * locker,ulonglong count)216 inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker,
217 ulonglong count)
218 {
219 if (likely(locker != NULL))
220 {
221 PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
222 }
223 }
224
225 static inline void
inline_mysql_set_statement_rows_examined(PSI_statement_locker * locker,ulonglong count)226 inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker,
227 ulonglong count)
228 {
229 if (likely(locker != NULL))
230 {
231 PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
232 }
233 }
234
235 static inline void
inline_mysql_end_statement(struct PSI_statement_locker * locker,Diagnostics_area * stmt_da)236 inline_mysql_end_statement(struct PSI_statement_locker *locker,
237 Diagnostics_area *stmt_da)
238 {
239 PSI_STAGE_CALL(end_stage)();
240 if (likely(locker != NULL))
241 PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
242 }
243 #endif
244
245 /** @} (end of group Statement_instrumentation) */
246
247 #endif
248
249