mysql_table.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* Copyright (c) 2010, 2012, 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 Foundation,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
  12. #ifndef MYSQL_TABLE_H
  13. #define MYSQL_TABLE_H
  14. /**
  15. @file mysql/psi/mysql_table.h
  16. Instrumentation helpers for table io.
  17. */
  18. #include "mysql/psi/psi.h"
  19. /**
  20. @defgroup Table_instrumentation Table Instrumentation
  21. @ingroup Instrumentation_interface
  22. @{
  23. */
  24. #ifdef HAVE_PSI_TABLE_INTERFACE
  25. #define MYSQL_UNBIND_TABLE(handler) (handler)->unbind_psi()
  26. #define MYSQL_REBIND_TABLE(handler) (handler)->rebind_psi()
  27. #define PSI_CALL_unbind_table PSI_TABLE_CALL(unbind_table)
  28. #define PSI_CALL_rebind_table PSI_TABLE_CALL(rebind_table)
  29. #define PSI_CALL_open_table PSI_TABLE_CALL(open_table)
  30. #define PSI_CALL_close_table PSI_TABLE_CALL(close_table)
  31. #define PSI_CALL_get_table_share PSI_TABLE_CALL(get_table_share)
  32. #define PSI_CALL_release_table_share PSI_TABLE_CALL(release_table_share)
  33. #define PSI_CALL_drop_table_share PSI_TABLE_CALL(drop_table_share)
  34. #else
  35. #define MYSQL_UNBIND_TABLE(handler) do { } while(0)
  36. #define MYSQL_REBIND_TABLE(handler) do { } while(0)
  37. #define PSI_CALL_unbind_table(A1) do { } while(0)
  38. #define PSI_CALL_rebind_table(A1,A2,A3) NULL
  39. #define PSI_CALL_close_table(A1) do { } while(0)
  40. #define PSI_CALL_open_table(A1,A2) NULL
  41. #define PSI_CALL_get_table_share(A1,A2) NULL
  42. #define PSI_CALL_release_table_share(A1) do { } while(0)
  43. #define PSI_CALL_drop_table_share(A1,A2,A3,A4,A5) do { } while(0)
  44. #endif
  45. /**
  46. @def MYSQL_TABLE_WAIT_VARIABLES
  47. Instrumentation helper for table waits.
  48. This instrumentation declares local variables.
  49. Do not use a ';' after this macro
  50. @param LOCKER the locker
  51. @param STATE the locker state
  52. @sa MYSQL_START_TABLE_IO_WAIT.
  53. @sa MYSQL_END_TABLE_IO_WAIT.
  54. @sa MYSQL_START_TABLE_LOCK_WAIT.
  55. @sa MYSQL_END_TABLE_LOCK_WAIT.
  56. */
  57. #ifdef HAVE_PSI_TABLE_INTERFACE
  58. #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE) \
  59. struct PSI_table_locker* LOCKER; \
  60. PSI_table_locker_state STATE;
  61. #else
  62. #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE)
  63. #endif
  64. /**
  65. @def MYSQL_TABLE_IO_WAIT
  66. Instrumentation helper for table io_waits.
  67. This instrumentation marks the start of a wait event.
  68. @param PSI the instrumented table
  69. @param OP the table operation to be performed
  70. @param INDEX the table index used if any, or MAY_KEY.
  71. @param FLAGS per table operation flags.
  72. @sa MYSQL_END_TABLE_WAIT.
  73. */
  74. #ifdef HAVE_PSI_TABLE_INTERFACE
  75. #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
  76. { \
  77. if (PSI != NULL) \
  78. { \
  79. PSI_table_locker *locker; \
  80. PSI_table_locker_state state; \
  81. locker= PSI_TABLE_CALL(start_table_io_wait) \
  82. (& state, PSI, OP, INDEX, __FILE__, __LINE__); \
  83. PAYLOAD \
  84. if (locker != NULL) \
  85. PSI_TABLE_CALL(end_table_io_wait)(locker); \
  86. } \
  87. else \
  88. { \
  89. PAYLOAD \
  90. } \
  91. }
  92. #else
  93. #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
  94. PAYLOAD
  95. #endif
  96. /**
  97. @def MYSQL_TABLE_LOCK_WAIT
  98. Instrumentation helper for table io_waits.
  99. This instrumentation marks the start of a wait event.
  100. @param PSI the instrumented table
  101. @param OP the table operation to be performed
  102. @param INDEX the table index used if any, or MAY_KEY.
  103. @param FLAGS per table operation flags.
  104. @sa MYSQL_END_TABLE_WAIT.
  105. */
  106. #ifdef HAVE_PSI_TABLE_INTERFACE
  107. #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
  108. { \
  109. if (PSI != NULL) \
  110. { \
  111. PSI_table_locker *locker; \
  112. PSI_table_locker_state state; \
  113. locker= PSI_TABLE_CALL(start_table_lock_wait) \
  114. (& state, PSI, OP, FLAGS, __FILE__, __LINE__); \
  115. PAYLOAD \
  116. if (locker != NULL) \
  117. PSI_TABLE_CALL(end_table_lock_wait)(locker); \
  118. } \
  119. else \
  120. { \
  121. PAYLOAD \
  122. } \
  123. }
  124. #else
  125. #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
  126. PAYLOAD
  127. #endif
  128. /**
  129. @def MYSQL_START_TABLE_LOCK_WAIT
  130. Instrumentation helper for table lock waits.
  131. This instrumentation marks the start of a wait event.
  132. @param LOCKER the locker
  133. @param STATE the locker state
  134. @param PSI the instrumented table
  135. @param OP the table operation to be performed
  136. @param FLAGS per table operation flags.
  137. @sa MYSQL_END_TABLE_LOCK_WAIT.
  138. */
  139. #ifdef HAVE_PSI_TABLE_INTERFACE
  140. #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
  141. LOCKER= inline_mysql_start_table_lock_wait(STATE, PSI, \
  142. OP, FLAGS, __FILE__, __LINE__)
  143. #else
  144. #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
  145. do {} while (0)
  146. #endif
  147. /**
  148. @def MYSQL_END_TABLE_LOCK_WAIT
  149. Instrumentation helper for table lock waits.
  150. This instrumentation marks the end of a wait event.
  151. @param LOCKER the locker
  152. @sa MYSQL_START_TABLE_LOCK_WAIT.
  153. */
  154. #ifdef HAVE_PSI_TABLE_INTERFACE
  155. #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
  156. inline_mysql_end_table_lock_wait(LOCKER)
  157. #else
  158. #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
  159. do {} while (0)
  160. #endif
  161. #ifdef HAVE_PSI_TABLE_INTERFACE
  162. /**
  163. Instrumentation calls for MYSQL_START_TABLE_LOCK_WAIT.
  164. @sa MYSQL_END_TABLE_LOCK_WAIT.
  165. */
  166. static inline struct PSI_table_locker *
  167. inline_mysql_start_table_lock_wait(PSI_table_locker_state *state,
  168. struct PSI_table *psi,
  169. enum PSI_table_lock_operation op,
  170. ulong flags, const char *src_file, int src_line)
  171. {
  172. if (psi != NULL)
  173. {
  174. struct PSI_table_locker *locker;
  175. locker= PSI_TABLE_CALL(start_table_lock_wait)
  176. (state, psi, op, flags, src_file, src_line);
  177. return locker;
  178. }
  179. return NULL;
  180. }
  181. /**
  182. Instrumentation calls for MYSQL_END_TABLE_LOCK_WAIT.
  183. @sa MYSQL_START_TABLE_LOCK_WAIT.
  184. */
  185. static inline void
  186. inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker)
  187. {
  188. if (locker != NULL)
  189. PSI_TABLE_CALL(end_table_lock_wait)(locker);
  190. }
  191. #endif
  192. /** @} (end of group Table_instrumentation) */
  193. #endif