You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.9 KiB

17 years ago
17 years ago
17 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1994, 2009, Oracle and/or its affiliates. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  12. *****************************************************************************/
  13. /*****************************************************************//**
  14. @file include/ut0dbg.h
  15. Debug utilities for Innobase
  16. Created 1/30/1994 Heikki Tuuri
  17. **********************************************************************/
  18. #ifndef ut0dbg_h
  19. #define ut0dbg_h
  20. #ifdef UNIV_INNOCHECKSUM
  21. #define ut_a assert
  22. #define ut_ad assert
  23. #define ut_error assert(0)
  24. #else /* !UNIV_INNOCHECKSUM */
  25. #include "univ.i"
  26. #include <stdlib.h>
  27. #include "os0thread.h"
  28. #if defined(__GNUC__) && (__GNUC__ > 2)
  29. /** Test if an assertion fails.
  30. @param EXPR assertion expression
  31. @return nonzero if EXPR holds, zero if not */
  32. # define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR)))
  33. #else
  34. /** This is used to eliminate compiler warnings */
  35. extern ulint ut_dbg_zero;
  36. /** Test if an assertion fails.
  37. @param EXPR assertion expression
  38. @return nonzero if EXPR holds, zero if not */
  39. # define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
  40. #endif
  41. /*************************************************************//**
  42. Report a failed assertion. */
  43. UNIV_INTERN
  44. void
  45. ut_dbg_assertion_failed(
  46. /*====================*/
  47. const char* expr, /*!< in: the failed assertion */
  48. const char* file, /*!< in: source file containing the assertion */
  49. ulint line) /*!< in: line number of the assertion */
  50. UNIV_COLD __attribute__((nonnull(2)));
  51. /** Abort the execution. */
  52. # define UT_DBG_PANIC abort()
  53. /** Abort execution if EXPR does not evaluate to nonzero.
  54. @param EXPR assertion expression that should hold */
  55. #define ut_a(EXPR) do { \
  56. if (UT_DBG_FAIL(EXPR)) { \
  57. ut_dbg_assertion_failed(#EXPR, \
  58. __FILE__, (ulint) __LINE__); \
  59. UT_DBG_PANIC; \
  60. } \
  61. } while (0)
  62. /** Abort execution. */
  63. #define ut_error do { \
  64. ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
  65. UT_DBG_PANIC; \
  66. } while (0)
  67. #ifdef UNIV_DEBUG
  68. /** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
  69. #define ut_ad(EXPR) ut_a(EXPR)
  70. /** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
  71. #define ut_d(EXPR) do {EXPR;} while (0)
  72. #else
  73. /** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
  74. #define ut_ad(EXPR)
  75. /** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
  76. #define ut_d(EXPR)
  77. #endif
  78. /** Silence warnings about an unused variable by doing a null assignment.
  79. @param A the unused variable */
  80. #define UT_NOT_USED(A) A = A
  81. #ifdef UNIV_COMPILE_TEST_FUNCS
  82. #include <sys/types.h>
  83. #include <sys/time.h>
  84. #include <sys/resource.h>
  85. /** structure used for recording usage statistics */
  86. struct speedo_t {
  87. struct rusage ru; /*!< getrusage() result */
  88. struct timeval tv; /*!< gettimeofday() result */
  89. };
  90. /*******************************************************************//**
  91. Resets a speedo (records the current time in it). */
  92. UNIV_INTERN
  93. void
  94. speedo_reset(
  95. /*=========*/
  96. speedo_t* speedo); /*!< out: speedo */
  97. /*******************************************************************//**
  98. Shows the time elapsed and usage statistics since the last reset of a
  99. speedo. */
  100. UNIV_INTERN
  101. void
  102. speedo_show(
  103. /*========*/
  104. const speedo_t* speedo); /*!< in: speedo */
  105. #endif /* UNIV_COMPILE_TEST_FUNCS */
  106. #endif /* !UNIV_INNOCHECKSUM */
  107. #endif