1
/*********************************************************************
2
Debug utilities for Innobase.
4
(c) 1994, 1995 Innobase Oy
6
Created 1/30/1994 Heikki Tuuri
7
**********************************************************************/
12
#if defined(__GNUC__) && (__GNUC__ > 2)
14
/* This is used to eliminate compiler warnings */
15
UNIV_INTERN ulint ut_dbg_zero = 0;
18
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
19
/* If this is set to TRUE all threads will stop into the next assertion
21
UNIV_INTERN ibool ut_dbg_stop_threads = FALSE;
24
/* This is set to TRUE when on NetWare there happens an InnoDB
25
assertion failure or other fatal error condition that requires an
26
immediate shutdown. */
27
UNIV_INTERN ibool panic_shutdown = FALSE;
28
#elif !defined(UT_DBG_USE_ABORT)
29
/* Null pointer used to generate memory trap */
30
UNIV_INTERN ulint* ut_dbg_null_ptr = NULL;
33
/*****************************************************************
34
Report a failed assertion. */
37
ut_dbg_assertion_failed(
38
/*====================*/
39
const char* expr, /* in: the failed assertion (optional) */
40
const char* file, /* in: source file containing the assertion */
41
ulint line) /* in: line number of the assertion */
43
ut_print_timestamp(stderr);
45
" InnoDB: Assertion failure in thread %lu"
46
" in file %s line %lu\n",
47
os_thread_pf(os_thread_get_curr_id()), file, line);
50
"InnoDB: Failing assertion: %s\n", expr);
53
fputs("InnoDB: We intentionally generate a memory trap.\n"
54
"InnoDB: Submit a detailed bug report"
55
" to http://bugs.mysql.com.\n"
56
"InnoDB: If you get repeated assertion failures"
58
"InnoDB: immediately after the mysqld startup, there may be\n"
59
"InnoDB: corruption in the InnoDB tablespace. Please refer to\n"
60
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
61
"forcing-recovery.html\n"
62
"InnoDB: about forcing recovery.\n", stderr);
63
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
64
ut_dbg_stop_threads = TRUE;
69
/*****************************************************************
70
Shut down MySQL/InnoDB after assertion failure. */
76
if (!panic_shutdown) {
77
panic_shutdown = TRUE;
78
innobase_shutdown_for_mysql();
82
#else /* __NETWARE__ */
83
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
84
/*****************************************************************
85
Stop a thread after assertion failure. */
93
fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
94
os_thread_pf(os_thread_get_curr_id()), file, line);
95
os_thread_sleep(1000000000);
98
#endif /* __NETWARE__ */
100
#ifdef UNIV_COMPILE_TEST_FUNCS
102
#include <sys/types.h>
103
#include <sys/time.h>
104
#include <sys/resource.h>
109
#define timersub(a, b, r) \
111
(r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
112
(r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
113
if ((r)->tv_usec < 0) { \
115
(r)->tv_usec += 1000000; \
118
#endif /* timersub */
120
/***********************************************************************
121
Resets a speedo (records the current time in it). */
126
speedo_t* speedo) /* out: speedo */
128
gettimeofday(&speedo->tv, NULL);
130
getrusage(RUSAGE_SELF, &speedo->ru);
133
/***********************************************************************
134
Shows the time elapsed and usage statistics since the last reset of a
140
const speedo_t* speedo) /* in: speedo */
142
struct rusage ru_now;
143
struct timeval tv_now;
144
struct timeval tv_diff;
146
getrusage(RUSAGE_SELF, &ru_now);
148
gettimeofday(&tv_now, NULL);
150
#define PRINT_TIMEVAL(prefix, tvp) \
151
fprintf(stderr, "%s% 5ld.%06ld sec\n", \
152
prefix, (tvp)->tv_sec, (tvp)->tv_usec)
154
timersub(&tv_now, &speedo->tv, &tv_diff);
155
PRINT_TIMEVAL("real", &tv_diff);
157
timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
158
PRINT_TIMEVAL("user", &tv_diff);
160
timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
161
PRINT_TIMEVAL("sys ", &tv_diff);
164
#endif /* UNIV_COMPILE_TEST_FUNCS */