-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator_runtime.h
158 lines (118 loc) · 3.64 KB
/
generator_runtime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Copyright (C) 2005-2013 Christoph Rupp (chris@crupp.de).
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See files COPYING.* for License information.
*/
#ifndef RUNTIME_GENERATOR_H__
#define RUNTIME_GENERATOR_H__
#include <iostream>
#include <fstream>
#include <boost/random.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/progress.hpp>
#include "metrics.h"
#include "timer.h"
#include "generator.h"
#include "datasource.h"
#include "database.h"
//
// generates data based on configuration settings
//
class RuntimeGenerator : public Generator
{
enum {
kStateRunning = 0,
kStateReopening,
kStateStopped
};
public:
// constructor
RuntimeGenerator(int id, Configuration *conf, Database *db,
bool show_progress);
// destructor
virtual ~RuntimeGenerator() {
assert(m_txn == 0);
assert(m_cursor == 0);
delete m_datasource;
delete m_progress;
}
// executes the next command from the Datasource
virtual bool execute();
// opens the Environment; used for 'reopen'
virtual void open();
// closes the Environment; used for 'reopen'
virtual void close();
// returns true if the test was successful
virtual bool was_successful() const {
return (m_success);
}
// returns the collected metrics/statistics
virtual void get_metrics(Metrics *metrics) {
m_db->get_metrics(&m_metrics);
m_metrics.name = m_db->get_name();
*metrics = m_metrics;
}
private:
// creates the Environment
void create();
// inserts a key/value pair
double insert();
// erases a key/value pair
double erase();
// lookup of a key/value pair
double find();
// begins a new transaction
void txn_begin();
// commits a transaction
double txn_commit();
// aborts a transaction
void txn_abort();
// generates a new key, based on the Datasource
ham_key_t generate_key();
// generates a new record
ham_record_t generate_record();
// which command to execute next?
int get_next_command();
// returs true if test should stop now
bool limit_reached();
// "tee"s the generated test data to a file (and/or to stdout
// if 'verbose' is enabled)
void tee(const char *foo, const ham_key_t *key = 0,
const ham_record_t *record = 0);
// the current state (running, reopening etc)
int m_state;
// counting the number of operations
uint64_t m_opcount;
// the datasource
Datasource *m_datasource;
// a vector which temporarily stores the data from the Datasource
std::vector<uint8_t> m_key_data;
// a vector which temporarily stores the data for the records
std::vector<uint8_t> m_record_data;
// rng
boost::mt19937 m_rng;
// uniform distribution from 0..1
boost::uniform_01<boost::mt19937> m_u01;
// start time
Timer<boost::chrono::system_clock> m_start;
// elapsed time
double m_elapsed_seconds;
// the currently active Transaction
Database::Transaction *m_txn;
// the currently used Cursor
Database::Cursor *m_cursor;
// boost progress bar, can be null if progress is not shown
boost::progress_display *m_progress;
// file to dump the generated test data ("tee")
std::ofstream m_tee;
// test was successful?
bool m_success;
// the collected metrics/statistics
Metrics m_metrics;
};
#endif /* RUNTIME_GENERATOR_H__ */