~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0dbg.h

  • Committer: Brian Aker
  • Date: 2009-01-07 00:04:25 UTC
  • Revision ID: brian@tangent.org-20090107000425-67n3f86rw6k423xe
Fixed index_merge_innodb test.

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 include/ut0dbg.h
 
1
/*********************************************************************
21
2
Debug utilities for Innobase
22
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
23
6
Created 1/30/1994 Heikki Tuuri
24
7
**********************************************************************/
25
8
 
31
14
#include "os0thread.h"
32
15
 
33
16
#if defined(__GNUC__) && (__GNUC__ > 2)
34
 
/** Test if an assertion fails.
35
 
@param EXPR     assertion expression
36
 
@return         nonzero if EXPR holds, zero if not */
37
17
# define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR)))
38
18
#else
39
 
/** This is used to eliminate compiler warnings */
40
 
extern ulint    ut_dbg_zero;
41
 
/** Test if an assertion fails.
42
 
@param EXPR     assertion expression
43
 
@return         nonzero if EXPR holds, zero if not */
 
19
extern ulint    ut_dbg_zero; /* This is used to eliminate
 
20
                                compiler warnings */
44
21
# define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
45
22
#endif
46
23
 
47
 
/*************************************************************//**
 
24
/*****************************************************************
48
25
Report a failed assertion. */
49
26
UNIV_INTERN
50
27
void
51
28
ut_dbg_assertion_failed(
52
29
/*====================*/
53
 
        const char* expr,       /*!< in: the failed assertion */
54
 
        const char* file,       /*!< in: source file containing the assertion */
55
 
        ulint line);            /*!< in: line number of the assertion */
56
 
 
57
 
#if defined(__WIN__) || defined(__INTEL_COMPILER)
58
 
# undef UT_DBG_USE_ABORT
59
 
#elif defined(__GNUC__) && (__GNUC__ > 2)
60
 
# define UT_DBG_USE_ABORT
61
 
#endif
62
 
 
63
 
#ifndef UT_DBG_USE_ABORT
64
 
/** A null pointer that will be dereferenced to trigger a memory trap */
 
30
        const char* expr,       /* in: the failed assertion */
 
31
        const char* file,       /* in: source file containing the assertion */
 
32
        ulint line);            /* in: line number of the assertion */
 
33
 
 
34
#ifdef __NETWARE__
 
35
/* Flag for ignoring further assertion failures.
 
36
On NetWare, have a graceful exit rather than a segfault to avoid abends. */
 
37
extern ibool    panic_shutdown;
 
38
/* Abort the execution. */
 
39
void ut_dbg_panic(void);
 
40
# define UT_DBG_PANIC ut_dbg_panic()
 
41
/* Stop threads in ut_a(). */
 
42
# define UT_DBG_STOP    while (0)       /* We do not do this on NetWare */
 
43
#else /* __NETWARE__ */
 
44
# if defined(__WIN__) || defined(__INTEL_COMPILER)
 
45
#  undef UT_DBG_USE_ABORT
 
46
# elif defined(__GNUC__) && (__GNUC__ > 2)
 
47
#  define UT_DBG_USE_ABORT
 
48
# endif
 
49
 
 
50
# ifndef UT_DBG_USE_ABORT
 
51
/* A null pointer that will be dereferenced to trigger a memory trap */
65
52
extern ulint*   ut_dbg_null_ptr;
66
 
#endif
 
53
# endif
67
54
 
68
 
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
69
 
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
70
 
will stop at the next ut_a() or ut_ad(). */
 
55
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
 
56
/* Flag for indicating that all threads should stop.  This will be set
 
57
by ut_dbg_assertion_failed(). */
71
58
extern ibool    ut_dbg_stop_threads;
72
59
 
73
 
/*************************************************************//**
 
60
/*****************************************************************
74
61
Stop a thread after assertion failure. */
75
62
UNIV_INTERN
76
63
void
78
65
/*===============*/
79
66
        const char*     file,
80
67
        ulint           line);
81
 
#endif
 
68
# endif
82
69
 
83
 
#ifdef UT_DBG_USE_ABORT
84
 
/** Abort the execution. */
85
 
# define UT_DBG_PANIC abort()
86
 
/** Stop threads (null operation) */
87
 
# define UT_DBG_STOP do {} while (0)
88
 
#else /* UT_DBG_USE_ABORT */
89
 
/** Abort the execution. */
90
 
# define UT_DBG_PANIC                                   \
 
70
# ifdef UT_DBG_USE_ABORT
 
71
/* Abort the execution. */
 
72
#  define UT_DBG_PANIC abort()
 
73
/* Stop threads (null operation) */
 
74
#  define UT_DBG_STOP while (0) {}
 
75
# else /* UT_DBG_USE_ABORT */
 
76
/* Abort the execution. */
 
77
#  define UT_DBG_PANIC                                  \
91
78
        if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
92
 
/** Stop threads in ut_a(). */
93
 
# define UT_DBG_STOP do                                         \
 
79
/* Stop threads in ut_a(). */
 
80
#  define UT_DBG_STOP do                                                \
94
81
        if (UNIV_UNLIKELY(ut_dbg_stop_threads)) {               \
95
82
                ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
96
83
        } while (0)
97
 
#endif /* UT_DBG_USE_ABORT */
 
84
# endif /* UT_DBG_USE_ABORT */
 
85
#endif /* __NETWARE__ */
98
86
 
99
 
/** Abort execution if EXPR does not evaluate to nonzero.
100
 
@param EXPR     assertion expression that should hold */
 
87
/* Abort execution if EXPR does not evaluate to nonzero. */
101
88
#define ut_a(EXPR) do {                                         \
102
89
        if (UT_DBG_FAIL(EXPR)) {                                \
103
90
                ut_dbg_assertion_failed(#EXPR,                  \
107
94
        UT_DBG_STOP;                                            \
108
95
} while (0)
109
96
 
110
 
/** Abort execution. */
 
97
/* Abort execution. */
111
98
#define ut_error do {                                           \
112
99
        ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
113
100
        UT_DBG_PANIC;                                           \
114
101
} while (0)
115
102
 
116
103
#ifdef UNIV_DEBUG
117
 
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
118
104
#define ut_ad(EXPR)     ut_a(EXPR)
119
 
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
120
105
#define ut_d(EXPR)      do {EXPR;} while (0)
121
106
#else
122
 
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
123
107
#define ut_ad(EXPR)
124
 
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
125
108
#define ut_d(EXPR)
126
109
#endif
127
110
 
128
 
/** Silence warnings about an unused variable by doing a null assignment.
129
 
@param A        the unused variable */
130
111
#define UT_NOT_USED(A)  A = A
131
112
 
132
113
#ifdef UNIV_COMPILE_TEST_FUNCS
135
116
#include <sys/time.h>
136
117
#include <sys/resource.h>
137
118
 
138
 
/** structure used for recording usage statistics */
 
119
/* structure used for recording usage statistics */
139
120
typedef struct speedo_struct {
140
 
        struct rusage   ru;     /*!< getrusage() result */
141
 
        struct timeval  tv;     /*!< gettimeofday() result */
 
121
        struct rusage   ru;
 
122
        struct timeval  tv;
142
123
} speedo_t;
143
124
 
144
 
/*******************************************************************//**
 
125
/***********************************************************************
145
126
Resets a speedo (records the current time in it). */
146
127
UNIV_INTERN
147
128
void
148
129
speedo_reset(
149
130
/*=========*/
150
 
        speedo_t*       speedo);        /*!< out: speedo */
 
131
        speedo_t*       speedo);        /* out: speedo */
151
132
 
152
 
/*******************************************************************//**
 
133
/***********************************************************************
153
134
Shows the time elapsed and usage statistics since the last reset of a
154
135
speedo. */
155
136
UNIV_INTERN
156
137
void
157
138
speedo_show(
158
139
/*========*/
159
 
        const speedo_t* speedo);        /*!< in: speedo */
 
140
        const speedo_t* speedo);        /* in: speedo */
160
141
 
161
142
#endif /* UNIV_COMPILE_TEST_FUNCS */
162
143