mysql_statement.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. #ifndef MYSQL_STATEMENT_H
  13. #define MYSQL_STATEMENT_H
  14. /**
  15. @file mysql/psi/mysql_statement.h
  16. Instrumentation helpers for statements.
  17. */
  18. #include "mysql/psi/psi.h"
  19. /**
  20. @defgroup Statement_instrumentation Statement Instrumentation
  21. @ingroup Instrumentation_interface
  22. @{
  23. */
  24. /**
  25. @def mysql_statement_register(P1, P2, P3)
  26. Statement registration.
  27. */
  28. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  29. #define mysql_statement_register(P1, P2, P3) \
  30. inline_mysql_statement_register(P1, P2, P3)
  31. #else
  32. #define mysql_statement_register(P1, P2, P3) \
  33. do {} while (0)
  34. #endif
  35. #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
  36. #define MYSQL_DIGEST_START(LOCKER) \
  37. inline_mysql_digest_start(LOCKER)
  38. #else
  39. #define MYSQL_DIGEST_START(LOCKER) \
  40. NULL
  41. #endif
  42. #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
  43. #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
  44. inline_mysql_digest_end(LOCKER, DIGEST)
  45. #else
  46. #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
  47. do {} while (0)
  48. #endif
  49. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  50. #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS) \
  51. inline_mysql_start_statement(STATE, K, DB, DB_LEN, CS, __FILE__, __LINE__)
  52. #else
  53. #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS) \
  54. NULL
  55. #endif
  56. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  57. #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
  58. inline_mysql_refine_statement(LOCKER, K)
  59. #else
  60. #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
  61. NULL
  62. #endif
  63. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  64. #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
  65. inline_mysql_set_statement_text(LOCKER, P1, P2)
  66. #else
  67. #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
  68. do {} while (0)
  69. #endif
  70. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  71. #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
  72. inline_mysql_set_statement_lock_time(LOCKER, P1)
  73. #else
  74. #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
  75. do {} while (0)
  76. #endif
  77. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  78. #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
  79. inline_mysql_set_statement_rows_sent(LOCKER, P1)
  80. #else
  81. #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
  82. do {} while (0)
  83. #endif
  84. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  85. #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
  86. inline_mysql_set_statement_rows_examined(LOCKER, P1)
  87. #else
  88. #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
  89. do {} while (0)
  90. #endif
  91. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  92. #define MYSQL_END_STATEMENT(LOCKER, DA) \
  93. inline_mysql_end_statement(LOCKER, DA)
  94. #else
  95. #define MYSQL_END_STATEMENT(LOCKER, DA) \
  96. do {} while (0)
  97. #endif
  98. #ifdef HAVE_PSI_STATEMENT_INTERFACE
  99. static inline void inline_mysql_statement_register(
  100. const char *category, PSI_statement_info *info, int count)
  101. {
  102. PSI_STATEMENT_CALL(register_statement)(category, info, count);
  103. }
  104. #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
  105. static inline struct PSI_digest_locker *
  106. inline_mysql_digest_start(PSI_statement_locker *locker)
  107. {
  108. PSI_digest_locker* digest_locker= NULL;
  109. if (likely(locker != NULL))
  110. digest_locker= PSI_DIGEST_CALL(digest_start)(locker);
  111. return digest_locker;
  112. }
  113. #endif
  114. #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
  115. static inline void
  116. inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest)
  117. {
  118. if (likely(locker != NULL))
  119. PSI_DIGEST_CALL(digest_end)(locker, digest);
  120. }
  121. #endif
  122. static inline struct PSI_statement_locker *
  123. inline_mysql_start_statement(PSI_statement_locker_state *state,
  124. PSI_statement_key key,
  125. const char *db, uint db_len,
  126. const CHARSET_INFO *charset,
  127. const char *src_file, int src_line)
  128. {
  129. PSI_statement_locker *locker;
  130. locker= PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset);
  131. if (likely(locker != NULL))
  132. PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
  133. return locker;
  134. }
  135. static inline struct PSI_statement_locker *
  136. inline_mysql_refine_statement(PSI_statement_locker *locker,
  137. PSI_statement_key key)
  138. {
  139. if (likely(locker != NULL))
  140. {
  141. locker= PSI_STATEMENT_CALL(refine_statement)(locker, key);
  142. }
  143. return locker;
  144. }
  145. static inline void
  146. inline_mysql_set_statement_text(PSI_statement_locker *locker,
  147. const char *text, uint text_len)
  148. {
  149. if (likely(locker != NULL))
  150. {
  151. PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
  152. }
  153. }
  154. static inline void
  155. inline_mysql_set_statement_lock_time(PSI_statement_locker *locker,
  156. ulonglong count)
  157. {
  158. if (likely(locker != NULL))
  159. {
  160. PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
  161. }
  162. }
  163. static inline void
  164. inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker,
  165. ulonglong count)
  166. {
  167. if (likely(locker != NULL))
  168. {
  169. PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
  170. }
  171. }
  172. static inline void
  173. inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker,
  174. ulonglong count)
  175. {
  176. if (likely(locker != NULL))
  177. {
  178. PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
  179. }
  180. }
  181. static inline void
  182. inline_mysql_end_statement(struct PSI_statement_locker *locker,
  183. Diagnostics_area *stmt_da)
  184. {
  185. PSI_STAGE_CALL(end_stage)();
  186. if (likely(locker != NULL))
  187. PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
  188. }
  189. #endif
  190. /** @} (end of group Statement_instrumentation) */
  191. #endif