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