~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/ut/ut0dbg.c

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************
 
2
Debug utilities for Innobase.
 
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
 
6
Created 1/30/1994 Heikki Tuuri
 
7
**********************************************************************/
 
8
 
 
9
#include "univ.i"
 
10
#include "ut0dbg.h"
 
11
 
 
12
#if defined(__GNUC__) && (__GNUC__ > 2)
 
13
#else
 
14
/* This is used to eliminate compiler warnings */
 
15
UNIV_INTERN ulint       ut_dbg_zero     = 0;
 
16
#endif
 
17
 
 
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
 
20
and assert */
 
21
UNIV_INTERN ibool       ut_dbg_stop_threads     = FALSE;
 
22
#endif
 
23
#ifdef __NETWARE__
 
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;
 
31
#endif
 
32
 
 
33
/*****************************************************************
 
34
Report a failed assertion. */
 
35
UNIV_INTERN
 
36
void
 
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 */
 
42
{
 
43
        ut_print_timestamp(stderr);
 
44
        fprintf(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);
 
48
        if (expr) {
 
49
                fprintf(stderr,
 
50
                        "InnoDB: Failing assertion: %s\n", expr);
 
51
        }
 
52
 
 
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"
 
57
              " or crashes, even\n"
 
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;
 
65
#endif
 
66
}
 
67
 
 
68
#ifdef __NETWARE__
 
69
/*****************************************************************
 
70
Shut down MySQL/InnoDB after assertion failure. */
 
71
UNIV_INTERN
 
72
void
 
73
ut_dbg_panic(void)
 
74
/*==============*/
 
75
{
 
76
        if (!panic_shutdown) {
 
77
                panic_shutdown = TRUE;
 
78
                innobase_shutdown_for_mysql();
 
79
        }
 
80
        exit(1);
 
81
}
 
82
#else /* __NETWARE__ */
 
83
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
 
84
/*****************************************************************
 
85
Stop a thread after assertion failure. */
 
86
UNIV_INTERN
 
87
void
 
88
ut_dbg_stop_thread(
 
89
/*===============*/
 
90
        const char*     file,
 
91
        ulint           line)
 
92
{
 
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);
 
96
}
 
97
# endif
 
98
#endif /* __NETWARE__ */
 
99
 
 
100
#ifdef UNIV_COMPILE_TEST_FUNCS
 
101
 
 
102
#include <sys/types.h>
 
103
#include <sys/time.h>
 
104
#include <sys/resource.h>
 
105
 
 
106
#include <unistd.h>
 
107
 
 
108
#ifndef timersub
 
109
#define timersub(a, b, r)                                               \
 
110
        do {                                                            \
 
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) {                                 \
 
114
                        (r)->tv_sec--;                                  \
 
115
                        (r)->tv_usec += 1000000;                        \
 
116
                }                                                       \
 
117
        } while (0)
 
118
#endif /* timersub */
 
119
 
 
120
/***********************************************************************
 
121
Resets a speedo (records the current time in it). */
 
122
UNIV_INTERN
 
123
void
 
124
speedo_reset(
 
125
/*=========*/
 
126
        speedo_t*       speedo) /* out: speedo */
 
127
{
 
128
        gettimeofday(&speedo->tv, NULL);
 
129
 
 
130
        getrusage(RUSAGE_SELF, &speedo->ru);
 
131
}
 
132
 
 
133
/***********************************************************************
 
134
Shows the time elapsed and usage statistics since the last reset of a
 
135
speedo. */
 
136
UNIV_INTERN
 
137
void
 
138
speedo_show(
 
139
/*========*/
 
140
        const speedo_t* speedo) /* in: speedo */
 
141
{
 
142
        struct rusage   ru_now;
 
143
        struct timeval  tv_now;
 
144
        struct timeval  tv_diff;
 
145
 
 
146
        getrusage(RUSAGE_SELF, &ru_now);
 
147
 
 
148
        gettimeofday(&tv_now, NULL);
 
149
 
 
150
#define PRINT_TIMEVAL(prefix, tvp)              \
 
151
        fprintf(stderr, "%s% 5ld.%06ld sec\n",  \
 
152
                prefix, (tvp)->tv_sec, (tvp)->tv_usec)
 
153
 
 
154
        timersub(&tv_now, &speedo->tv, &tv_diff);
 
155
        PRINT_TIMEVAL("real", &tv_diff);
 
156
 
 
157
        timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
 
158
        PRINT_TIMEVAL("user", &tv_diff);
 
159
 
 
160
        timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
 
161
        PRINT_TIMEVAL("sys ", &tv_diff);
 
162
}
 
163
 
 
164
#endif /* UNIV_COMPILE_TEST_FUNCS */