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