~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
4
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.
8
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.
12
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
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/*****************************************************************//**
20
@file ut/ut0dbg.c
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Debug utilities for Innobase.
22
23
Created 1/30/1994 Heikki Tuuri
24
**********************************************************************/
25
26
#include "univ.i"
27
#include "ut0dbg.h"
28
29
#if defined(__GNUC__) && (__GNUC__ > 2)
30
#else
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
31
/** This is used to eliminate compiler warnings */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
32
UNIV_INTERN ulint	ut_dbg_zero	= 0;
33
#endif
34
35
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
36
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
37
will stop at the next ut_a() or ut_ad(). */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
38
UNIV_INTERN ibool	ut_dbg_stop_threads	= FALSE;
39
#endif
40
#ifdef __NETWARE__
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
41
/** Flag for ignoring further assertion failures.  This is set to TRUE
42
when on NetWare there happens an InnoDB assertion failure or other
43
fatal error condition that requires an immediate shutdown. */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
44
UNIV_INTERN ibool panic_shutdown = FALSE;
45
#elif !defined(UT_DBG_USE_ABORT)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
46
/** A null pointer that will be dereferenced to trigger a memory trap */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
47
UNIV_INTERN ulint*	ut_dbg_null_ptr		= NULL;
48
#endif
49
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
50
/*************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
51
Report a failed assertion. */
52
UNIV_INTERN
53
void
54
ut_dbg_assertion_failed(
55
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
56
	const char* expr,	/*!< in: the failed assertion (optional) */
57
	const char* file,	/*!< in: source file containing the assertion */
58
	ulint line)		/*!< in: line number of the assertion */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
59
{
60
	ut_print_timestamp(stderr);
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
61
#ifdef UNIV_HOTBACKUP
62
	fprintf(stderr, "  InnoDB: Assertion failure in file %s line %lu\n",
63
		file, line);
64
#else /* UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
65
	fprintf(stderr,
66
		"  InnoDB: Assertion failure in thread %lu"
67
		" in file %s line %lu\n",
68
		os_thread_pf(os_thread_get_curr_id()), file, line);
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
69
#endif /* UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
70
	if (expr) {
71
		fprintf(stderr,
72
			"InnoDB: Failing assertion: %s\n", expr);
73
	}
74
75
	fputs("InnoDB: We intentionally generate a memory trap.\n"
76
	      "InnoDB: Submit a detailed bug report"
77
	      " to http://bugs.mysql.com.\n"
78
	      "InnoDB: If you get repeated assertion failures"
79
	      " or crashes, even\n"
80
	      "InnoDB: immediately after the mysqld startup, there may be\n"
81
	      "InnoDB: corruption in the InnoDB tablespace. Please refer to\n"
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
82
	      "InnoDB: " REFMAN "forcing-recovery.html\n"
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
83
	      "InnoDB: about forcing recovery.\n", stderr);
84
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
85
	ut_dbg_stop_threads = TRUE;
86
#endif
87
}
88
89
#ifdef __NETWARE__
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
90
/*************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
91
Shut down MySQL/InnoDB after assertion failure. */
92
UNIV_INTERN
93
void
94
ut_dbg_panic(void)
95
/*==============*/
96
{
97
	if (!panic_shutdown) {
98
		panic_shutdown = TRUE;
99
		innobase_shutdown_for_mysql();
100
	}
101
	exit(1);
102
}
103
#else /* __NETWARE__ */
104
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
105
/*************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
106
Stop a thread after assertion failure. */
107
UNIV_INTERN
108
void
109
ut_dbg_stop_thread(
110
/*===============*/
111
	const char*	file,
112
	ulint		line)
113
{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
114
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
115
	fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
116
		os_thread_pf(os_thread_get_curr_id()), file, line);
117
	os_thread_sleep(1000000000);
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
118
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
119
}
120
# endif
121
#endif /* __NETWARE__ */
122
123
#ifdef UNIV_COMPILE_TEST_FUNCS
124
125
#include <sys/types.h>
126
#include <sys/time.h>
127
#include <sys/resource.h>
128
129
#include <unistd.h>
130
131
#ifndef timersub
132
#define timersub(a, b, r)						\
133
	do {								\
134
		(r)->tv_sec = (a)->tv_sec - (b)->tv_sec;		\
135
		(r)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
136
		if ((r)->tv_usec < 0) {					\
137
			(r)->tv_sec--;					\
138
			(r)->tv_usec += 1000000;			\
139
		}							\
140
	} while (0)
141
#endif /* timersub */
142
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
143
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
144
Resets a speedo (records the current time in it). */
145
UNIV_INTERN
146
void
147
speedo_reset(
148
/*=========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
149
	speedo_t*	speedo)	/*!< out: speedo */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
150
{
151
	gettimeofday(&speedo->tv, NULL);
152
153
	getrusage(RUSAGE_SELF, &speedo->ru);
154
}
155
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
156
/*******************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
157
Shows the time elapsed and usage statistics since the last reset of a
158
speedo. */
159
UNIV_INTERN
160
void
161
speedo_show(
162
/*========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
163
	const speedo_t*	speedo)	/*!< in: speedo */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
164
{
165
	struct rusage	ru_now;
166
	struct timeval	tv_now;
167
	struct timeval	tv_diff;
168
169
	getrusage(RUSAGE_SELF, &ru_now);
170
171
	gettimeofday(&tv_now, NULL);
172
173
#define PRINT_TIMEVAL(prefix, tvp)		\
174
	fprintf(stderr, "%s% 5ld.%06ld sec\n",	\
175
		prefix, (tvp)->tv_sec, (tvp)->tv_usec)
176
177
	timersub(&tv_now, &speedo->tv, &tv_diff);
178
	PRINT_TIMEVAL("real", &tv_diff);
179
180
	timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
181
	PRINT_TIMEVAL("user", &tv_diff);
182
183
	timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
184
	PRINT_TIMEVAL("sys ", &tv_diff);
185
}
186
187
#endif /* UNIV_COMPILE_TEST_FUNCS */