Debian Codegraph @

build_vxworks/test/micro/bench.h

raw
1 /*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * $Id$
7 */
8 #ifndef _BENCH_H_
9 #define _BENCH_H_
10 #include "db_config.h"
11
12 #include "db_int.h"
13
14 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5
15 /*
16 * Older releases of Berkeley DB don't include standard include files in
17 * db_int.h.
18 */
19 #ifdef DB_WIN32
20 #define WIN32_LEAN_AND_MEAN 1
21 #include <windows.h>
22 #include <direct.h>
23 #include <sys/timeb.h>
24 #else
25 #include <sys/stat.h>
26 #include <sys/time.h>
27
28 #include <limits.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <unistd.h>
32 #endif
33 #endif
34
35 #define TESTDIR "TESTDIR"
36 #define TESTFILE "test_micro.db"
37
38 /*
39 * Implement a custom assert to allow consistent behavior across builds and
40 * platforms.
41 *
42 * The BDB library DB_ASSERT implementation is only enabled in diagnostic
43 * builds -- so is not suitable here.
44 */
45 #define DB_BENCH_ASSERT(e) do { \
46 (e) ? (void)0 : \
47 (fprintf(stderr, \
48 "assert failure: %s/%d: \"%s\"\n", __FILE__, __LINE__, #e), \
49 b_util_abort()); \
50 } while (0)
51
52 #ifndef NS_PER_SEC
53 #define NS_PER_SEC 1000000000 /* Nanoseconds in a second */
54 #endif
55 #ifndef NS_PER_US
56 #define NS_PER_US 1000 /* Nanoseconds in a microsecond */
57 #endif
58 #ifndef MS_PER_NS
59 #define MS_PER_NS 1000000 /* Milliseconds in a nanosecond */
60 #endif
61
62 #ifdef DB_TIMEOUT_TO_TIMESPEC
63 /*
64 * We have the timer routines in the Berkeley DB library after their conversion
65 * to the POSIX timespec interfaces. We'd rather use something that gives us
66 * better information than elapsed wallclock time, so use getrusage instead if
67 * it's available.
68 */
69 #ifdef HAVE_GETRUSAGE
70 #include <sys/resource.h>
71
72 #define SET_TIMER_FROM_GETRUSAGE(tp) do { \
73 struct rusage __usage; \
74 DB_BENCH_ASSERT(getrusage(RUSAGE_SELF, &__usage) == 0); \
75 (tp)->tv_sec = \
76 __usage.ru_utime.tv_sec + __usage.ru_stime.tv_sec; \
77 (tp)->tv_nsec = NS_PER_US * \
78 (__usage.ru_utime.tv_usec + __usage.ru_stime.tv_usec); \
79 } while (0);
80
81 #define TIMER_START SET_TIMER_FROM_GETRUSAGE(&__start_time);
82 #define TIMER_STOP SET_TIMER_FROM_GETRUSAGE(&__end_time);
83
84 #elif defined(DB_WIN32) && !defined(DB_WINCE)
85
86 #define SET_TIMER_FROM_GETPROCESSTIMES(tp) do { \
87 FILETIME lpCreationTime, lpExitTime, lpKernelTime, lpUserTIme; \
88 LARGE_INTEGER large_int; \
89 LONGLONG __ns_since_epoch; \
90 DB_BENCH_ASSERT( \
91 GetProcessTimes(GetCurrentProcess(), &lpCreationTime, \
92 &lpExitTime, &lpKernelTime, &lpUserTIme) != 0); \
93 memcpy(&large_int, &lpKernelTime, sizeof(lpKernelTime)); \
94 __ns_since_epoch = (large_int.QuadPart * 100); \
95 (tp)->tv_sec = (time_t)(__ns_since_epoch / NS_PER_SEC); \
96 (tp)->tv_nsec = (long)(__ns_since_epoch % NS_PER_SEC); \
97 memcpy(&large_int, &lpUserTIme, sizeof(lpUserTIme)); \
98 __ns_since_epoch = (large_int.QuadPart * 100); \
99 (tp)->tv_sec += (time_t)(__ns_since_epoch / NS_PER_SEC); \
100 (tp)->tv_nsec += (long)(__ns_since_epoch % NS_PER_SEC); \
101 } while (0);
102
103 #define TIMER_START SET_TIMER_FROM_GETPROCESSTIMES(&__start_time);
104 #define TIMER_STOP SET_TIMER_FROM_GETPROCESSTIMES(&__end_time);
105
106 #else /* !HAVEGETRUSAGE && !DB_WIN32 */
107
108 #if DB_VERSION_MAJOR > 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 6
109 #define TIMER_START __os_gettime(NULL, &__start_time, 1)
110 #define TIMER_STOP __os_gettime(NULL, &__end_time, 1)
111 #else
112 #define TIMER_START __os_gettime(NULL, &__start_time)
113 #define TIMER_STOP __os_gettime(NULL, &__end_time)
114 #endif
115 #endif /* !HAVE_GETRUSAGE */
116
117 #else /* !DB_TIMEOUT_TO_TIMESPEC */
118
119 #if defined(HAVE_CLOCK_GETTIME)
120 typedef struct timespec db_timespec;
121 #else
122 typedef struct {
123 time_t tv_sec; /* seconds */
124 long tv_nsec; /* nanoseconds */
125 } db_timespec;
126 #endif
127
128 #define timespecadd(vvp, uvp) \
129 do { \
130 (vvp)->tv_sec += (uvp)->tv_sec; \
131 (vvp)->tv_nsec += (uvp)->tv_nsec; \
132 if ((vvp)->tv_nsec >= NS_PER_SEC) { \
133 (vvp)->tv_sec++; \
134 (vvp)->tv_nsec -= NS_PER_SEC; \
135 } \
136 } while (0)
137 #define timespecsub(vvp, uvp) \
138 do { \
139 (vvp)->tv_sec -= (uvp)->tv_sec; \
140 (vvp)->tv_nsec -= (uvp)->tv_nsec; \
141 if ((vvp)->tv_nsec < 0) { \
142 (vvp)->tv_sec--; \
143 (vvp)->tv_nsec += NS_PER_SEC; \
144 } \
145 } while (0)
146
147 #define TIMER_START CLOCK(__start_time)
148 #define TIMER_STOP CLOCK(__end_time)
149
150 #if defined(HAVE_CLOCK_GETTIME)
151 #define CLOCK(tm) do { \
152 DB_BENCH_ASSERT(clock_gettime( \
153 CLOCK_REALTIME, (struct timespec *)&(tm)) == 0); \
154 } while (0)
155 #elif defined(DB_WIN32)
156 #define CLOCK(tm) do { \
157 struct _timeb __now; \
158 _ftime(&__now); \
159 (tm).tv_sec = __now.time; \
160 (tm).tv_nsec = __now.millitm * MS_PER_NS; \
161 } while (0)
162 #else
163 #define CLOCK(tm) do { \
164 struct timeval __tp; \
165 DB_BENCH_ASSERT(gettimeofday(&__tp, NULL) == 0); \
166 (tm).tv_sec = __tp.tv_sec; \
167 (tm).tv_nsec = __tp.tv_usec * NS_PER_US; \
168 } while (0)
169 #endif
170 #endif /* !DB_TIMEOUT_TO_TIMESPEC */
171
172 extern db_timespec __start_time, __end_time;
173
174 #define TIMER_GET(tm) do { \
175 tm = __end_time; \
176 timespecsub(&(tm), &__start_time); \
177 } while (0)
178 #define TIMER_DISPLAY(ops) do { \
179 db_timespec __tmp_time; \
180 __tmp_time = __end_time; \
181 timespecsub(&__tmp_time, &__start_time); \
182 TIME_DISPLAY(ops, __tmp_time); \
183 } while (0)
184 #define TIME_DISPLAY(ops, tm) do { \
185 double __secs; \
186 int __major, __minor, __patch; \
187 __secs = (tm).tv_sec + (double)(tm).tv_nsec / NS_PER_SEC; \
188 (void)db_version(&__major, &__minor, &__patch); \
189 printf("%d.%d.%d\t%.2f\n", __major, __minor, __patch, \
190 (__secs == 0) ? 0.0 : (ops) / __secs); \
191 } while (0)
192
193 extern char *progname; /* program name */
194
195 int b_curalloc __P((int, char *[]));
196 int b_curwalk __P((int, char *[]));
197 int b_del __P((int, char *[]));
198 int b_get __P((int, char *[]));
199 int b_inmem __P((int, char *[]));
200 int b_latch __P((int, char *[]));
201 int b_load __P((int, char *[]));
202 int b_open __P((int, char *[]));
203 int b_put __P((int, char *[]));
204 int b_recover __P((int, char *[]));
205 int b_txn __P((int, char *[]));
206 int b_txn_write __P((int, char *[]));
207 int b_uname __P((void));
208 void b_util_abort __P((void));
209 int b_util_dir_setup __P((void));
210 int b_util_dir_teardown __P((void));
211 int b_util_have_hash __P((void));
212 int b_util_have_heap __P((void));
213 int b_util_have_queue __P((void));
214 int b_util_unlink __P((char *));
215 int b_workload __P((int, char *[]));
216 u_int32_t part_callback __P((DB *, DBT *));
217
218 #endif /* !_BENCH_H_ */