Debian Codegraph @

build_vxworks/test/micro/b_txn.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_txn_usage(void);
11
12 int
13 b_txn(int argc, char *argv[])
14 {
15 extern char *optarg;
16 extern int optind, __db_getopt_reset;
17 DB_ENV *dbenv;
18 DB_TXN *txn;
19 int tabort, ch, i, count;
20
21 count = 1000;
22 tabort = 0;
23 __db_getopt_reset = 1;
24 while ((ch = getopt(argc, argv, "ac:")) != EOF)
25 switch (ch) {
26 case 'a':
27 tabort = 1;
28 break;
29 case 'c':
30 count = atoi(optarg);
31 break;
32 case '?':
33 default:
34 return (b_txn_usage());
35 }
36 argc -= optind;
37 argv += optind;
38 if (argc != 0)
39 return (b_txn_usage());
40
41 /* Create the environment. */
42 DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
43 dbenv->set_errfile(dbenv, stderr);
44 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR < 1
45 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR,
46 NULL, DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
47 DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE, 0666) == 0);
48 #else
49 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR,
50 DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
51 DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE, 0666) == 0);
52 #endif
53
54 /* Start and commit/abort a transaction count times. */
55 TIMER_START;
56 if (tabort)
57 for (i = 0; i < count; ++i) {
58 #if DB_VERSION_MAJOR < 4
59 DB_BENCH_ASSERT(txn_begin(dbenv, NULL, &txn, 0) == 0);
60 DB_BENCH_ASSERT(txn_abort(txn) == 0);
61 #else
62 DB_BENCH_ASSERT(
63 dbenv->txn_begin(dbenv, NULL, &txn, 0) == 0);
64 DB_BENCH_ASSERT(txn->abort(txn) == 0);
65 #endif
66 }
67 else
68 for (i = 0; i < count; ++i) {
69 #if DB_VERSION_MAJOR < 4
70 DB_BENCH_ASSERT(txn_begin(dbenv, NULL, &txn, 0) == 0);
71 DB_BENCH_ASSERT(txn_commit(txn, 0) == 0);
72 #else
73 DB_BENCH_ASSERT(
74 dbenv->txn_begin(dbenv, NULL, &txn, 0) == 0);
75 DB_BENCH_ASSERT(txn->commit(txn, 0) == 0);
76 #endif
77 }
78 TIMER_STOP;
79
80 printf("# %d empty transaction start/%s pairs\n",
81 count, tabort ? "abort" : "commit");
82 TIMER_DISPLAY(count);
83
84 DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
85
86 return (0);
87 }
88
89 static int
90 b_txn_usage()
91 {
92 (void)fprintf(stderr, "usage: b_txn [-a] [-c count]\n");
93 return (EXIT_FAILURE);
94 }