Drizzled Public API Documentation

ut0dbg.cc
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 /*****************************************************************/
26 #include "univ.i"
27 #include "ut0dbg.h"
28 #include "ha_prototypes.h"
29 
30 #if defined(__GNUC__) && (__GNUC__ > 2)
31 #else
32 
33 UNIV_INTERN ulint ut_dbg_zero = 0;
34 #endif
35 
36 #if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
37 
39 UNIV_INTERN ibool ut_dbg_stop_threads = FALSE;
40 #endif
41 #ifndef UT_DBG_USE_ABORT
42 
43 UNIV_INTERN ulint* ut_dbg_null_ptr = NULL;
44 #endif
45 
46 /*************************************************************/
48 #ifdef __cplusplus
49 extern "C"
50 #endif
51 UNIV_INTERN
52 void
54 /*====================*/
55  const char* expr,
56  const char* file,
57  ulint line)
58 {
59  ut_print_timestamp(stderr);
60 #ifdef UNIV_HOTBACKUP
61  fprintf(stderr, " InnoDB: Assertion failure in file %s line %lu\n",
62  innobase_basename(file), line);
63 #else /* UNIV_HOTBACKUP */
64  fprintf(stderr,
65  " InnoDB: Assertion failure in thread %lu"
66  " in file %s line %lu\n",
68  innobase_basename(file), line);
69 #endif /* UNIV_HOTBACKUP */
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"
82  "InnoDB: " REFMAN "forcing-innodb-recovery.html\n"
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 #if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
90 /*************************************************************/
92 UNIV_INTERN
93 void
95 /*===============*/
96  const char* file,
97  ulint line)
98 {
99 #ifndef UNIV_HOTBACKUP
100  fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n",
102  innobase_basename(file), line);
103  os_thread_sleep(1000000000);
104 #endif /* !UNIV_HOTBACKUP */
105 }
106 #endif
107 
108 #ifdef UNIV_COMPILE_TEST_FUNCS
109 
110 #include <sys/types.h>
111 #include <sys/time.h>
112 #include <sys/resource.h>
113 
114 #include <unistd.h>
115 
116 #ifndef timersub
117 #define timersub(a, b, r) \
118  do { \
119  (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
120  (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
121  if ((r)->tv_usec < 0) { \
122  (r)->tv_sec--; \
123  (r)->tv_usec += 1000000; \
124  } \
125  } while (0)
126 #endif /* timersub */
127 
128 /*******************************************************************/
130 UNIV_INTERN
131 void
132 speedo_reset(
133 /*=========*/
134  speedo_t* speedo)
135 {
136  gettimeofday(&speedo->tv, NULL);
137 
138  getrusage(RUSAGE_SELF, &speedo->ru);
139 }
140 
141 /*******************************************************************/
144 UNIV_INTERN
145 void
146 speedo_show(
147 /*========*/
148  const speedo_t* speedo)
149 {
150  struct rusage ru_now;
151  struct timeval tv_now;
152  struct timeval tv_diff;
153 
154  getrusage(RUSAGE_SELF, &ru_now);
155 
156  gettimeofday(&tv_now, NULL);
157 
158 #define PRINT_TIMEVAL(prefix, tvp) \
159  fprintf(stderr, "%s% 5ld.%06ld sec\n", \
160  prefix, (tvp)->tv_sec, (tvp)->tv_usec)
161 
162  timersub(&tv_now, &speedo->tv, &tv_diff);
163  PRINT_TIMEVAL("real", &tv_diff);
164 
165  timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
166  PRINT_TIMEVAL("user", &tv_diff);
167 
168  timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
169  PRINT_TIMEVAL("sys ", &tv_diff);
170 }
171 
172 #endif /* UNIV_COMPILE_TEST_FUNCS */