| 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 |
|
| 9 |
/* |
| 10 |
* Macros to help with initializing/assigning key dbts |
| 11 |
*/ |
| 12 |
|
| 13 |
#define KBUF_LEN 12 |
| 14 |
#define INIT_KEY(key, config) do { \ |
| 15 |
memset(&key, 0, sizeof(key)); \ |
| 16 |
if (config->orderedkeys) { \ |
| 17 |
key.size = sizeof (u_int32_t); \ |
| 18 |
} else if (config->ksize != 0) { \ |
| 19 |
DB_BENCH_ASSERT( \ |
| 20 |
(key.data = malloc(key.size = config->ksize)) != NULL); \ |
| 21 |
} else { \ |
| 22 |
key.data = kbuf; \ |
| 23 |
key.size = 10; \ |
| 24 |
} \ |
| 25 |
} while (0) |
| 26 |
|
| 27 |
#define GET_KEY_NEXT(key, config, kbuf, i) do { \ |
| 28 |
size_t tmp_int; \ |
| 29 |
if (config->orderedkeys) { \ |
| 30 |
/* Will be sorted on little-endian system. */ \ |
| 31 |
tmp_int = i; \ |
| 32 |
M_32_SWAP(tmp_int); \ |
| 33 |
key.data = &tmp_int; \ |
| 34 |
} else if (config->ksize == 0) { \ |
| 35 |
/* \ |
| 36 |
* This will produce duplicate keys. \ |
| 37 |
* That is not such a big deal, since we are \ |
| 38 |
* using the same seed to srand each time, \ |
| 39 |
* the scenario is reproducible. \ |
| 40 |
*/ \ |
| 41 |
(void)snprintf(kbuf, sizeof(kbuf), "%10d", rand()); \ |
| 42 |
} else { \ |
| 43 |
/* TODO: Not sure of the best approach here. */ \ |
| 44 |
(void)snprintf(key.data, config->ksize, "%10lu", (u_long)i); \ |
| 45 |
} \ |
| 46 |
} while (0) |
| 47 |
|
| 48 |
/* Taken from dbinc/db_swap.h */ |
| 49 |
#undef M_32_SWAP |
| 50 |
#define M_32_SWAP(a) { \ |
| 51 |
u_int32_t _tmp; \ |
| 52 |
_tmp = (u_int32_t)a; \ |
| 53 |
((u_int8_t *)&a)[0] = ((u_int8_t *)&_tmp)[3]; \ |
| 54 |
((u_int8_t *)&a)[1] = ((u_int8_t *)&_tmp)[2]; \ |
| 55 |
((u_int8_t *)&a)[2] = ((u_int8_t *)&_tmp)[1]; \ |
| 56 |
((u_int8_t *)&a)[3] = ((u_int8_t *)&_tmp)[0]; \ |
| 57 |
} |
| 58 |
|
| 59 |
/* |
| 60 |
* A singly linked list, that maintains a pointer |
| 61 |
* to the start and the end of the queue. |
| 62 |
* Should be possible to use a STAILQ, but this seemed easier |
| 63 |
*/ |
| 64 |
typedef struct bench_qentry { |
| 65 |
char data[KBUF_LEN]; |
| 66 |
struct bench_qentry *next; |
| 67 |
}bench_qentry; |
| 68 |
typedef struct bench_q { |
| 69 |
struct bench_qentry *head; |
| 70 |
struct bench_qentry *tail; |
| 71 |
} bench_q; |
| 72 |
#define BENCH_Q_TAIL_INSERT(queue, buf) do { \ |
| 73 |
struct bench_qentry *entry; \ |
| 74 |
DB_BENCH_ASSERT( \ |
| 75 |
(entry = malloc(sizeof(struct bench_qentry))) != NULL); \ |
| 76 |
memcpy(entry->data, buf, sizeof(entry->data)); \ |
| 77 |
if (queue.head == NULL) \ |
| 78 |
queue.head = queue.tail = entry; \ |
| 79 |
else { \ |
| 80 |
queue.tail->next = entry; \ |
| 81 |
queue.tail = entry; \ |
| 82 |
} \ |
| 83 |
} while (0) |
| 84 |
|
| 85 |
#define BENCH_Q_POP(queue, buf) do { \ |
| 86 |
struct bench_qentry *popped = queue.head; \ |
| 87 |
if (popped == NULL) \ |
| 88 |
break; \ |
| 89 |
if (queue.head->next == NULL) \ |
| 90 |
queue.head = queue.tail = NULL; \ |
| 91 |
else \ |
| 92 |
queue.head = queue.head->next; \ |
| 93 |
memcpy(buf, popped->data, sizeof(buf)); \ |
| 94 |
free(popped); \ |
| 95 |
} while (0) |
| 96 |
|
| 97 |
/* |
| 98 |
* Retrieve the head of the queue, save the data into user |
| 99 |
* buffer, and push the item back onto the end of the list. |
| 100 |
* Same functionality as pop/insert, but saves a malloc/free |
| 101 |
*/ |
| 102 |
#define BENCH_Q_POP_PUSH(queue, buf) do { \ |
| 103 |
struct bench_qentry *popped = queue.head; \ |
| 104 |
if (popped == NULL) \ |
| 105 |
break; \ |
| 106 |
if (queue.head->next == NULL) \ |
| 107 |
queue.head = queue.tail = NULL; \ |
| 108 |
else \ |
| 109 |
queue.head = queue.head->next; \ |
| 110 |
memcpy(buf, popped->data, sizeof(buf)); \ |
| 111 |
if (queue.head == NULL) \ |
| 112 |
queue.head = queue.tail = popped; \ |
| 113 |
else { \ |
| 114 |
queue.tail->next = popped; \ |
| 115 |
queue.tail = popped; \ |
| 116 |
} \ |
| 117 |
} while (0) |
| 118 |
|
| 119 |
typedef enum { |
| 120 |
T_PUT, |
| 121 |
T_GET, |
| 122 |
T_DELETE, |
| 123 |
T_PUT_GET, |
| 124 |
T_PUT_DELETE, |
| 125 |
T_PUT_GET_DELETE, |
| 126 |
T_GET_DELETE, |
| 127 |
T_MIXED |
| 128 |
} test_type; |
| 129 |
|
| 130 |
typedef struct |
| 131 |
{ |
| 132 |
u_int32_t ksize; |
| 133 |
u_int32_t dsize; |
| 134 |
size_t orderedkeys; |
| 135 |
size_t num_dups; |
| 136 |
u_int32_t pagesz; |
| 137 |
u_int32_t cachesz; |
| 138 |
u_int32_t pcount; |
| 139 |
size_t gcount; |
| 140 |
size_t cursor_del; |
| 141 |
size_t verbose; |
| 142 |
test_type workload; |
| 143 |
u_int32_t seed; |
| 144 |
size_t presize; |
| 145 |
DBTYPE type; |
| 146 |
char *ts; |
| 147 |
char *message; |
| 148 |
/* Fields used to store timing information */ |
| 149 |
db_timespec put_time; |
| 150 |
db_timespec get_time; |
| 151 |
db_timespec del_time; |
| 152 |
db_timespec tot_time; |
| 153 |
} CONFIG; |