mysql_statement.h 6.9 KB

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