• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/db-4.8.30/build_vxworks/test_micro/
1/*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2005-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8#include "bench.h"
9
10static int b_get_usage(void);
11
12u_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
20int
21b_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	db_recno_t recno;
29	u_int32_t cachesize;
30	int ch, i, count;
31	char *ts;
32
33	type = DB_BTREE;
34	cachesize = MEGABYTE;
35	count = 100000;
36	ts = "Btree";
37	__db_getopt_reset = 1;
38	while ((ch = getopt(argc, argv, "C:c:t:")) != EOF)
39		switch (ch) {
40		case 'C':
41			cachesize = (u_int32_t)atoi(optarg);
42			break;
43		case 'c':
44			count = atoi(optarg);
45			break;
46		case 't':
47			switch (optarg[0]) {
48			case 'B': case 'b':
49				ts = "Btree";
50				type = DB_BTREE;
51				break;
52			case 'H': case 'h':
53				if (b_util_have_hash())
54					return (0);
55				ts = "Hash";
56				type = DB_HASH;
57				break;
58			case 'Q': case 'q':
59				if (b_util_have_queue())
60					return (0);
61				ts = "Queue";
62				type = DB_QUEUE;
63				break;
64			case 'R': case 'r':
65				ts = "Recno";
66				type = DB_RECNO;
67				break;
68			default:
69				return (b_get_usage());
70			}
71			break;
72		case '?':
73		default:
74			return (b_get_usage());
75		}
76	argc -= optind;
77	argv += optind;
78	if (argc != 0)
79		return (b_get_usage());
80
81	/* Create the database. */
82	DB_BENCH_ASSERT(db_create(&dbp, NULL, 0) == 0);
83	DB_BENCH_ASSERT(dbp->set_cachesize(dbp, 0, cachesize, 0) == 0);
84	dbp->set_errfile(dbp, stderr);
85
86	/* Set record length for Queue. */
87	if (type == DB_QUEUE)
88		DB_BENCH_ASSERT(dbp->set_re_len(dbp, 10) == 0);
89#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 7 && DB_VERSION_PATCH == 30
90	if (type == DB_BTREE) {
91		DBT keys[3];
92
93		memset(keys, 0, sizeof(keys));
94		keys[0].data = "a";
95		keys[0].size = 1;
96		keys[1].data = "b";
97		keys[1].size = 1;
98		keys[2].data = "c";
99		keys[2].size = 1;
100
101		DB_BENCH_ASSERT(
102		     dbp->set_partition_keys(dbp, 4, keys, NULL) == 0);
103	}
104
105	if (type == DB_HASH) {
106		DB_BENCH_ASSERT(
107		    dbp->set_partition_callback(dbp, 4, part_callback) == 0);
108	}
109#endif
110
111#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 1
112	DB_BENCH_ASSERT(
113	    dbp->open(dbp, NULL, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
114#else
115	DB_BENCH_ASSERT(
116	    dbp->open(dbp, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
117#endif
118
119	/* Store a key/data pair. */
120	memset(&key, 0, sizeof(key));
121	memset(&data, 0, sizeof(data));
122	switch (type) {
123	case DB_BTREE:
124	case DB_HASH:
125		key.data = "aaaaa";
126		key.size = 5;
127		break;
128	case DB_QUEUE:
129	case DB_RECNO:
130		recno = 1;
131		key.data = &recno;
132		key.size = sizeof(recno);
133		break;
134	case DB_UNKNOWN:
135		b_util_abort();
136		break;
137	}
138	data.data = "bbbbb";
139	data.size = 5;
140
141	DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);
142
143	/* Retrieve the key/data pair count times. */
144	TIMER_START;
145	for (i = 0; i < count; ++i)
146		DB_BENCH_ASSERT(dbp->get(dbp, NULL, &key, &data, 0) == 0);
147	TIMER_STOP;
148
149	printf("# %d %s database get of cached key/data item\n", count, ts);
150	TIMER_DISPLAY(count);
151
152	DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
153
154	return (0);
155}
156
157static int
158b_get_usage()
159{
160	(void)fprintf(stderr,
161	    "usage: b_get [-C cachesz] [-c count] [-t type]\n");
162	return (EXIT_FAILURE);
163}
164