~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-12-08 22:35:56 UTC
  • mfrom: (1819.9.158 update-innobase)
  • Revision ID: brian@tangent.org-20101208223556-37mi4omqg7lkjzf3
Merge in Stewart's changes, 1.3 changes.

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., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/*****************************************************************//**
 
20
@file ut/ut0dbg.c
 
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
 
31
/** This is used to eliminate compiler warnings */
 
32
UNIV_INTERN ulint       ut_dbg_zero     = 0;
 
33
#endif
 
34
 
 
35
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
 
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(). */
 
38
UNIV_INTERN ibool       ut_dbg_stop_threads     = FALSE;
 
39
#endif
 
40
#ifndef UT_DBG_USE_ABORT
 
41
/** A null pointer that will be dereferenced to trigger a memory trap */
 
42
UNIV_INTERN ulint*      ut_dbg_null_ptr         = NULL;
 
43
#endif
 
44
 
 
45
/*************************************************************//**
 
46
Report a failed assertion. */
 
47
UNIV_INTERN
 
48
void
 
49
ut_dbg_assertion_failed(
 
50
/*====================*/
 
51
        const char* expr,       /*!< in: the failed assertion (optional) */
 
52
        const char* file,       /*!< in: source file containing the assertion */
 
53
        ulint line)             /*!< in: line number of the assertion */
 
54
{
 
55
        ut_print_timestamp(stderr);
 
56
#ifdef UNIV_HOTBACKUP
 
57
        fprintf(stderr, "  InnoDB: Assertion failure in file %s line %lu\n",
 
58
                file, line);
 
59
#else /* UNIV_HOTBACKUP */
 
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
#endif /* UNIV_HOTBACKUP */
 
65
        if (expr) {
 
66
                fprintf(stderr,
 
67
                        "InnoDB: Failing assertion: %s\n", expr);
 
68
        }
 
69
 
 
70
        fputs("InnoDB: We intentionally generate a memory trap.\n"
 
71
              "InnoDB: Submit a detailed bug report"
 
72
              " to http://bugs.mysql.com.\n"
 
73
              "InnoDB: If you get repeated assertion failures"
 
74
              " or crashes, even\n"
 
75
              "InnoDB: immediately after the mysqld startup, there may be\n"
 
76
              "InnoDB: corruption in the InnoDB tablespace. Please refer to\n"
 
77
              "InnoDB: " REFMAN "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
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
 
85
/*************************************************************//**
 
86
Stop a thread after assertion failure. */
 
87
UNIV_INTERN
 
88
void
 
89
ut_dbg_stop_thread(
 
90
/*===============*/
 
91
        const char*     file,
 
92
        ulint           line)
 
93
{
 
94
#ifndef UNIV_HOTBACKUP
 
95
        fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
 
96
                os_thread_pf(os_thread_get_curr_id()), file, line);
 
97
        os_thread_sleep(1000000000);
 
98
#endif /* !UNIV_HOTBACKUP */
 
99
}
 
100
#endif
 
101
 
 
102
#ifdef UNIV_COMPILE_TEST_FUNCS
 
103
 
 
104
#include <sys/types.h>
 
105
#include <sys/time.h>
 
106
#include <sys/resource.h>
 
107
 
 
108
#include <unistd.h>
 
109
 
 
110
#ifndef timersub
 
111
#define timersub(a, b, r)                                               \
 
112
        do {                                                            \
 
113
                (r)->tv_sec = (a)->tv_sec - (b)->tv_sec;                \
 
114
                (r)->tv_usec = (a)->tv_usec - (b)->tv_usec;             \
 
115
                if ((r)->tv_usec < 0) {                                 \
 
116
                        (r)->tv_sec--;                                  \
 
117
                        (r)->tv_usec += 1000000;                        \
 
118
                }                                                       \
 
119
        } while (0)
 
120
#endif /* timersub */
 
121
 
 
122
/*******************************************************************//**
 
123
Resets a speedo (records the current time in it). */
 
124
UNIV_INTERN
 
125
void
 
126
speedo_reset(
 
127
/*=========*/
 
128
        speedo_t*       speedo) /*!< out: speedo */
 
129
{
 
130
        gettimeofday(&speedo->tv, NULL);
 
131
 
 
132
        getrusage(RUSAGE_SELF, &speedo->ru);
 
133
}
 
134
 
 
135
/*******************************************************************//**
 
136
Shows the time elapsed and usage statistics since the last reset of a
 
137
speedo. */
 
138
UNIV_INTERN
 
139
void
 
140
speedo_show(
 
141
/*========*/
 
142
        const speedo_t* speedo) /*!< in: speedo */
 
143
{
 
144
        struct rusage   ru_now;
 
145
        struct timeval  tv_now;
 
146
        struct timeval  tv_diff;
 
147
 
 
148
        getrusage(RUSAGE_SELF, &ru_now);
 
149
 
 
150
        gettimeofday(&tv_now, NULL);
 
151
 
 
152
#define PRINT_TIMEVAL(prefix, tvp)              \
 
153
        fprintf(stderr, "%s% 5ld.%06ld sec\n",  \
 
154
                prefix, (tvp)->tv_sec, (tvp)->tv_usec)
 
155
 
 
156
        timersub(&tv_now, &speedo->tv, &tv_diff);
 
157
        PRINT_TIMEVAL("real", &tv_diff);
 
158
 
 
159
        timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
 
160
        PRINT_TIMEVAL("user", &tv_diff);
 
161
 
 
162
        timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
 
163
        PRINT_TIMEVAL("sys ", &tv_diff);
 
164
}
 
165
 
 
166
#endif /* UNIV_COMPILE_TEST_FUNCS */