1
/*****************************************************************************
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/*********************************************************************
20
Debug utilities for Innobase.
22
Created 1/30/1994 Heikki Tuuri
23
**********************************************************************/
28
#if defined(__GNUC__) && (__GNUC__ > 2)
30
/* This is used to eliminate compiler warnings */
31
UNIV_INTERN ulint ut_dbg_zero = 0;
34
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
35
/* If this is set to TRUE all threads will stop into the next assertion
37
UNIV_INTERN ibool ut_dbg_stop_threads = FALSE;
40
/* This is set to TRUE when on NetWare there happens an InnoDB
41
assertion failure or other fatal error condition that requires an
42
immediate shutdown. */
43
UNIV_INTERN ibool panic_shutdown = FALSE;
44
#elif !defined(UT_DBG_USE_ABORT)
45
/* Null pointer used to generate memory trap */
46
UNIV_INTERN ulint* ut_dbg_null_ptr = NULL;
49
/*****************************************************************
50
Report a failed assertion. */
53
ut_dbg_assertion_failed(
54
/*====================*/
55
const char* expr, /* in: the failed assertion (optional) */
56
const char* file, /* in: source file containing the assertion */
57
ulint line) /* in: line number of the assertion */
59
ut_print_timestamp(stderr);
61
" InnoDB: Assertion failure in thread %lu"
62
" in file %s line %lu\n",
63
os_thread_pf(os_thread_get_curr_id()), file, line);
66
"InnoDB: Failing assertion: %s\n", expr);
69
fputs("InnoDB: We intentionally generate a memory trap.\n"
70
"InnoDB: Submit a detailed bug report"
71
" to http://bugs.mysql.com.\n"
72
"InnoDB: If you get repeated assertion failures"
74
"InnoDB: immediately after the mysqld startup, there may be\n"
75
"InnoDB: corruption in the InnoDB tablespace. Please refer to\n"
76
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
77
"forcing-recovery.html\n"
78
"InnoDB: about forcing recovery.\n", stderr);
79
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
80
ut_dbg_stop_threads = TRUE;
85
/*****************************************************************
86
Shut down MySQL/InnoDB after assertion failure. */
92
if (!panic_shutdown) {
93
panic_shutdown = TRUE;
94
innobase_shutdown_for_mysql();
98
#else /* __NETWARE__ */
99
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
100
/*****************************************************************
101
Stop a thread after assertion failure. */
109
fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
110
os_thread_pf(os_thread_get_curr_id()), file, line);
111
os_thread_sleep(1000000000);
114
#endif /* __NETWARE__ */
116
#ifdef UNIV_COMPILE_TEST_FUNCS
118
#include <sys/types.h>
119
#include <sys/time.h>
120
#include <sys/resource.h>
125
#define timersub(a, b, r) \
127
(r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
128
(r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
129
if ((r)->tv_usec < 0) { \
131
(r)->tv_usec += 1000000; \
134
#endif /* timersub */
136
/***********************************************************************
137
Resets a speedo (records the current time in it). */
142
speedo_t* speedo) /* out: speedo */
144
gettimeofday(&speedo->tv, NULL);
146
getrusage(RUSAGE_SELF, &speedo->ru);
149
/***********************************************************************
150
Shows the time elapsed and usage statistics since the last reset of a
156
const speedo_t* speedo) /* in: speedo */
158
struct rusage ru_now;
159
struct timeval tv_now;
160
struct timeval tv_diff;
162
getrusage(RUSAGE_SELF, &ru_now);
164
gettimeofday(&tv_now, NULL);
166
#define PRINT_TIMEVAL(prefix, tvp) \
167
fprintf(stderr, "%s% 5ld.%06ld sec\n", \
168
prefix, (tvp)->tv_sec, (tvp)->tv_usec)
170
timersub(&tv_now, &speedo->tv, &tv_diff);
171
PRINT_TIMEVAL("real", &tv_diff);
173
timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
174
PRINT_TIMEVAL("user", &tv_diff);
176
timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
177
PRINT_TIMEVAL("sys ", &tv_diff);
180
#endif /* UNIV_COMPILE_TEST_FUNCS */