~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-04-27 14:36:40 UTC
  • Revision ID: brian@gaz-20090427143640-f6zjmtt9vm55qgm2
Patch on show processlist from  davi@apache.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
/*********************************************************************
 
20
Debug utilities for Innobase.
 
21
 
 
22
Created 1/30/1994 Heikki Tuuri
 
23
**********************************************************************/
 
24
 
 
25
#include "univ.i"
 
26
#include "ut0dbg.h"
 
27
 
 
28
#if defined(__GNUC__) && (__GNUC__ > 2)
 
29
#else
 
30
/* This is used to eliminate compiler warnings */
 
31
UNIV_INTERN ulint       ut_dbg_zero     = 0;
 
32
#endif
 
33
 
 
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
 
36
and assert */
 
37
UNIV_INTERN ibool       ut_dbg_stop_threads     = FALSE;
 
38
#endif
 
39
#ifdef __NETWARE__
 
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;
 
47
#endif
 
48
 
 
49
/*****************************************************************
 
50
Report a failed assertion. */
 
51
UNIV_INTERN
 
52
void
 
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 */
 
58
{
 
59
        ut_print_timestamp(stderr);
 
60
        fprintf(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);
 
64
        if (expr) {
 
65
                fprintf(stderr,
 
66
                        "InnoDB: Failing assertion: %s\n", expr);
 
67
        }
 
68
 
 
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"
 
73
              " or crashes, even\n"
 
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;
 
81
#endif
 
82
}
 
83
 
 
84
#ifdef __NETWARE__
 
85
/*****************************************************************
 
86
Shut down MySQL/InnoDB after assertion failure. */
 
87
UNIV_INTERN
 
88
void
 
89
ut_dbg_panic(void)
 
90
/*==============*/
 
91
{
 
92
        if (!panic_shutdown) {
 
93
                panic_shutdown = TRUE;
 
94
                innobase_shutdown_for_mysql();
 
95
        }
 
96
        exit(1);
 
97
}
 
98
#else /* __NETWARE__ */
 
99
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
 
100
/*****************************************************************
 
101
Stop a thread after assertion failure. */
 
102
UNIV_INTERN
 
103
void
 
104
ut_dbg_stop_thread(
 
105
/*===============*/
 
106
        const char*     file,
 
107
        ulint           line)
 
108
{
 
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);
 
112
}
 
113
# endif
 
114
#endif /* __NETWARE__ */
 
115
 
 
116
#ifdef UNIV_COMPILE_TEST_FUNCS
 
117
 
 
118
#include <sys/types.h>
 
119
#include <sys/time.h>
 
120
#include <sys/resource.h>
 
121
 
 
122
#include <unistd.h>
 
123
 
 
124
#ifndef timersub
 
125
#define timersub(a, b, r)                                               \
 
126
        do {                                                            \
 
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) {                                 \
 
130
                        (r)->tv_sec--;                                  \
 
131
                        (r)->tv_usec += 1000000;                        \
 
132
                }                                                       \
 
133
        } while (0)
 
134
#endif /* timersub */
 
135
 
 
136
/***********************************************************************
 
137
Resets a speedo (records the current time in it). */
 
138
UNIV_INTERN
 
139
void
 
140
speedo_reset(
 
141
/*=========*/
 
142
        speedo_t*       speedo) /* out: speedo */
 
143
{
 
144
        gettimeofday(&speedo->tv, NULL);
 
145
 
 
146
        getrusage(RUSAGE_SELF, &speedo->ru);
 
147
}
 
148
 
 
149
/***********************************************************************
 
150
Shows the time elapsed and usage statistics since the last reset of a
 
151
speedo. */
 
152
UNIV_INTERN
 
153
void
 
154
speedo_show(
 
155
/*========*/
 
156
        const speedo_t* speedo) /* in: speedo */
 
157
{
 
158
        struct rusage   ru_now;
 
159
        struct timeval  tv_now;
 
160
        struct timeval  tv_diff;
 
161
 
 
162
        getrusage(RUSAGE_SELF, &ru_now);
 
163
 
 
164
        gettimeofday(&tv_now, NULL);
 
165
 
 
166
#define PRINT_TIMEVAL(prefix, tvp)              \
 
167
        fprintf(stderr, "%s% 5ld.%06ld sec\n",  \
 
168
                prefix, (tvp)->tv_sec, (tvp)->tv_usec)
 
169
 
 
170
        timersub(&tv_now, &speedo->tv, &tv_diff);
 
171
        PRINT_TIMEVAL("real", &tv_diff);
 
172
 
 
173
        timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
 
174
        PRINT_TIMEVAL("user", &tv_diff);
 
175
 
 
176
        timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
 
177
        PRINT_TIMEVAL("sys ", &tv_diff);
 
178
}
 
179
 
 
180
#endif /* UNIV_COMPILE_TEST_FUNCS */