|
| 1 | +/* Copyright (c) 2010, 2011 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 as published by |
| 5 | + the Free Software Foundation; version 2 of the License. |
| 6 | +
|
| 7 | + This program is distributed in the hope that it will be useful, |
| 8 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + GNU General Public License for more details. |
| 11 | +
|
| 12 | + You should have received a copy of the GNU General Public License |
| 13 | + along with this program; if not, write to the Free Software |
| 14 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 15 | + |
| 16 | +#ifndef MYSQL_STATEMENT_H |
| 17 | +#define MYSQL_STATEMENT_H |
| 18 | + |
| 19 | +/** |
| 20 | + @file mysql/psi/mysql_statement.h |
| 21 | + Instrumentation helpers for statements. |
| 22 | +*/ |
| 23 | + |
| 24 | +#include "mysql/psi/psi.h" |
| 25 | + |
| 26 | +/** |
| 27 | + @defgroup Statement_instrumentation Statement Instrumentation |
| 28 | + @ingroup Instrumentation_interface |
| 29 | + @{ |
| 30 | +*/ |
| 31 | + |
| 32 | +#ifdef HAVE_PSI_INTERFACE |
| 33 | + #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN) \ |
| 34 | + inline_mysql_start_statement(STATE, K, DB, DB_LEN, __FILE__, __LINE__) |
| 35 | +#else |
| 36 | + #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN) \ |
| 37 | + NULL |
| 38 | +#endif |
| 39 | + |
| 40 | +#ifdef HAVE_PSI_INTERFACE |
| 41 | + #define MYSQL_REFINE_STATEMENT(LOCKER, K) \ |
| 42 | + inline_mysql_refine_statement(LOCKER, K) |
| 43 | +#else |
| 44 | + #define MYSQL_REFINE_STATEMENT(LOCKER, K) \ |
| 45 | + NULL |
| 46 | +#endif |
| 47 | + |
| 48 | +#ifdef HAVE_PSI_INTERFACE |
| 49 | + #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \ |
| 50 | + inline_mysql_set_statement_text(LOCKER, P1, P2) |
| 51 | +#else |
| 52 | + #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \ |
| 53 | + do {} while (0) |
| 54 | +#endif |
| 55 | + |
| 56 | +#ifdef HAVE_PSI_INTERFACE |
| 57 | + #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \ |
| 58 | + inline_mysql_set_statement_lock_time(LOCKER, P1) |
| 59 | +#else |
| 60 | + #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \ |
| 61 | + do {} while (0) |
| 62 | +#endif |
| 63 | + |
| 64 | +#ifdef HAVE_PSI_INTERFACE |
| 65 | + #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \ |
| 66 | + inline_mysql_set_statement_rows_sent(LOCKER, P1) |
| 67 | +#else |
| 68 | + #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \ |
| 69 | + do {} while (0) |
| 70 | +#endif |
| 71 | + |
| 72 | +#ifdef HAVE_PSI_INTERFACE |
| 73 | + #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \ |
| 74 | + inline_mysql_set_statement_rows_examined(LOCKER, P1) |
| 75 | +#else |
| 76 | + #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \ |
| 77 | + do {} while (0) |
| 78 | +#endif |
| 79 | + |
| 80 | +#ifdef HAVE_PSI_INTERFACE |
| 81 | + #define MYSQL_END_STATEMENT(LOCKER, DA) \ |
| 82 | + inline_mysql_end_statement(LOCKER, DA) |
| 83 | +#else |
| 84 | + #define MYSQL_END_STATEMENT(LOCKER, DA) \ |
| 85 | + do {} while (0) |
| 86 | +#endif |
| 87 | + |
| 88 | +#ifdef HAVE_PSI_INTERFACE |
| 89 | +static inline struct PSI_statement_locker * |
| 90 | +inline_mysql_start_statement(PSI_statement_locker_state *state, |
| 91 | + PSI_statement_key key, |
| 92 | + const char *db, uint db_len, |
| 93 | + const char *src_file, int src_line) |
| 94 | +{ |
| 95 | + PSI_statement_locker *locker= NULL; |
| 96 | + if (likely(PSI_server != NULL)) |
| 97 | + { |
| 98 | + locker= PSI_server->get_thread_statement_locker(state, key); |
| 99 | + if (likely(locker != NULL)) |
| 100 | + PSI_server->start_statement(locker, db, db_len, src_file, src_line); |
| 101 | + } |
| 102 | + return locker; |
| 103 | +} |
| 104 | + |
| 105 | +static inline struct PSI_statement_locker * |
| 106 | +inline_mysql_refine_statement(PSI_statement_locker *locker, |
| 107 | + PSI_statement_key key) |
| 108 | +{ |
| 109 | + if (likely(PSI_server && locker)) |
| 110 | + { |
| 111 | + locker= PSI_server->refine_statement(locker, key); |
| 112 | + } |
| 113 | + return locker; |
| 114 | +} |
| 115 | + |
| 116 | +static inline void |
| 117 | +inline_mysql_set_statement_text(PSI_statement_locker *locker, |
| 118 | + const char *text, uint text_len) |
| 119 | +{ |
| 120 | + if (likely(PSI_server && locker)) |
| 121 | + { |
| 122 | + PSI_server->set_statement_text(locker, text, text_len); |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +static inline void |
| 127 | +inline_mysql_set_statement_lock_time(PSI_statement_locker *locker, |
| 128 | + ulonglong count) |
| 129 | +{ |
| 130 | + if (likely(PSI_server && locker)) |
| 131 | + { |
| 132 | + PSI_server->set_statement_lock_time(locker, count); |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +static inline void |
| 137 | +inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker, |
| 138 | + ulonglong count) |
| 139 | +{ |
| 140 | + if (likely(PSI_server && locker)) |
| 141 | + { |
| 142 | + PSI_server->set_statement_rows_sent(locker, count); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +static inline void |
| 147 | +inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker, |
| 148 | + ulonglong count) |
| 149 | +{ |
| 150 | + if (likely(PSI_server && locker)) |
| 151 | + { |
| 152 | + PSI_server->set_statement_rows_examined(locker, count); |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +static inline void |
| 157 | +inline_mysql_end_statement(struct PSI_statement_locker *locker, |
| 158 | + Diagnostics_area *stmt_da) |
| 159 | +{ |
| 160 | + if (likely(PSI_server != NULL)) |
| 161 | + { |
| 162 | + PSI_server->end_stage(); |
| 163 | + if (likely(locker != NULL)) |
| 164 | + PSI_server->end_statement(locker, stmt_da); |
| 165 | + } |
| 166 | +} |
| 167 | +#endif |
| 168 | + |
| 169 | +/** @} (end of group Statement_instrumentation) */ |
| 170 | + |
| 171 | +#endif |
| 172 | + |
0 commit comments