Debian Codegraph @

build_vxworks/test/micro/b_get.c

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 #include "bench.h"
9
10 static int b_get_usage(void);
11
12 u_int32_t part_callback(dbp, dbt)
13 DB *dbp;
14 DBT *dbt;
15 {
16 extern u_int32_t __ham_func2(DB *, const void *, u_int32_t);
17 return (__ham_func2(dbp, dbt->data, dbt->size));
18 }
19
20 int
21 b_get(int argc, char *argv[])
22 {
23 extern char *optarg;
24 extern int optind, __db_getopt_reset;
25 DB *dbp;
26 DBTYPE type;
27 DBT key, data;
28 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
29 DB_HEAP_RID rid;
30 #endif
31 db_recno_t recno;
32 u_int32_t cachesize;
33 int ch, i, count;
34 char *ts;
35
36 type = DB_BTREE;
37 cachesize = MEGABYTE;
38 count = 100000;
39 ts = "Btree";
40 __db_getopt_reset = 1;
41 while ((ch = getopt(argc, argv, "C:c:t:")) != EOF)
42 switch (ch) {
43 case 'C':
44 cachesize = (u_int32_t)atoi(optarg);
45 break;
46 case 'c':
47 count = atoi(optarg);
48 break;
49 case 't':
50 switch (optarg[0]) {
51 case 'B': case 'b':
52 ts = "Btree";
53 type = DB_BTREE;
54 break;
55 case 'H': case 'h':
56 if (optarg[1] == 'E' || optarg[1] == 'e') {
57 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
58 if (b_util_have_heap())
59 return (0);
60 ts = "Heap";
61 type = DB_HEAP;
62 #else
63 fprintf(stderr,
64 "b_curwalk: Heap is not supported! \n");
65 return (EXIT_SUCCESS);
66 #endif
67 } else {
68 if (b_util_have_hash())
69 return (0);
70 ts = "Hash";
71 type = DB_HASH;
72 }
73 break;
74 case 'Q': case 'q':
75 if (b_util_have_queue())
76 return (0);
77 ts = "Queue";
78 type = DB_QUEUE;
79 break;
80 case 'R': case 'r':
81 ts = "Recno";
82 type = DB_RECNO;
83 break;
84 default:
85 return (b_get_usage());
86 }
87 break;
88 case '?':
89 default:
90 return (b_get_usage());
91 }
92 argc -= optind;
93 argv += optind;
94 if (argc != 0)
95 return (b_get_usage());
96
97 /* Create the database. */
98 DB_BENCH_ASSERT(db_create(&dbp, NULL, 0) == 0);
99 DB_BENCH_ASSERT(dbp->set_cachesize(dbp, 0, cachesize, 0) == 0);
100 dbp->set_errfile(dbp, stderr);
101
102 /* Set record length for Queue. */
103 if (type == DB_QUEUE)
104 DB_BENCH_ASSERT(dbp->set_re_len(dbp, 10) == 0);
105 #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 7 && DB_VERSION_PATCH == 30
106 if (type == DB_BTREE) {
107 DBT keys[3];
108
109 memset(keys, 0, sizeof(keys));
110 keys[0].data = "a";
111 keys[0].size = 1;
112 keys[1].data = "b";
113 keys[1].size = 1;
114 keys[2].data = "c";
115 keys[2].size = 1;
116
117 DB_BENCH_ASSERT(
118 dbp->set_partition_keys(dbp, 4, keys, NULL) == 0);
119 }
120
121 if (type == DB_HASH) {
122 DB_BENCH_ASSERT(
123 dbp->set_partition_callback(dbp, 4, part_callback) == 0);
124 }
125 #endif
126
127 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
128 DB_BENCH_ASSERT(
129 dbp->open(dbp, NULL, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
130 #else
131 DB_BENCH_ASSERT(
132 dbp->open(dbp, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
133 #endif
134
135 /* Store a key/data pair. */
136 memset(&key, 0, sizeof(key));
137 memset(&data, 0, sizeof(data));
138 switch (type) {
139 case DB_BTREE:
140 case DB_HASH:
141 key.data = "aaaaa";
142 key.size = 5;
143 break;
144 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
145 case DB_HEAP:
146 key.data = &rid;
147 key.size = sizeof(rid);
148 break;
149 #endif
150 case DB_QUEUE:
151 case DB_RECNO:
152 recno = 1;
153 key.data = &recno;
154 key.size = sizeof(recno);
155 break;
156 case DB_UNKNOWN:
157 b_util_abort();
158 break;
159 }
160 data.data = "bbbbb";
161 data.size = 5;
162
163 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
164 DB_BENCH_ASSERT(dbp->put(
165 dbp, NULL, &key, &data, type == DB_HEAP ? DB_APPEND : 0) == 0);
166 #else
167 DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);
168 #endif
169 /* Retrieve the key/data pair count times. */
170 TIMER_START;
171 for (i = 0; i < count; ++i)
172 DB_BENCH_ASSERT(dbp->get(dbp, NULL, &key, &data, 0) == 0);
173 TIMER_STOP;
174
175 printf("# %d %s database get of cached key/data item\n", count, ts);
176 TIMER_DISPLAY(count);
177
178 DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
179
180 return (0);
181 }
182
183 static int
184 b_get_usage()
185 {
186 (void)fprintf(stderr,
187 "usage: b_get [-C cachesz] [-c count] [-t type]\n");
188 return (EXIT_FAILURE);
189 }