-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBenchmarkRunner.h
85 lines (67 loc) · 2.18 KB
/
BenchmarkRunner.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
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <vector>
struct TaskConfig;
// exit due to failure
[[noreturn]] void fail(std::string_view msg);
// exit because we're skipping the benchmark (e.g. has version# this runner doesn't support yet)
[[noreturn]] void skip(std::string_view msg);
uint64_t bytesFromKiB(uint64_t kibibytes);
uint64_t bytesFromMiB(uint64_t mebibytes);
uint64_t bytesFromGiB(uint64_t gibibytes);
double bytesToKiB(uint64_t bytes);
double bytesToMiB(uint64_t bytes);
double bytesToGiB(uint64_t bytes);
double bytesToKilobit(uint64_t bytes);
double bytesToMegabit(uint64_t bytes);
double bytesToGigabit(uint64_t bytes);
// use standardized part-size across all benchmarks
#define PART_SIZE (8 * 1024 * 1024)
// struct for a benchmark config, loaded from JSON
struct BenchmarkConfig
{
// loaded from workload json...
int maxRepeatCount;
int maxRepeatSecs;
std::string checksum;
bool filesOnDisk;
std::vector<TaskConfig> tasks;
// passed on cmdline...
std::string bucket;
std::string region;
double targetThroughputGbps;
BenchmarkConfig(
std::string_view jsonFilepath,
std::string_view bucket,
std::string_view region,
double targetThroughputGbps);
uint64_t bytesPerRun() const;
};
// struct for a task in the benchmark's JSON config
struct TaskConfig
{
std::string action;
std::string key;
uint64_t size;
};
// Base class for runnable benchmark
class BenchmarkRunner
{
protected:
BenchmarkConfig config;
// if uploading, and filesOnDisk is false, then upload this
std::vector<uint8_t> randomDataForUpload;
public:
BenchmarkRunner(const BenchmarkConfig &config);
virtual ~BenchmarkRunner();
BenchmarkRunner(const BenchmarkRunner &) = delete;
BenchmarkRunner &operator=(const BenchmarkRunner &) = delete;
// A benchmark can be run repeatedly
virtual void run() = 0;
};
using CreateRunnerFromNameFn =
std::function<std::unique_ptr<BenchmarkRunner>(std::string_view id, const BenchmarkConfig &config)>;
// common main() function
int benchmarkRunnerMain(int argc, char *argv[], const CreateRunnerFromNameFn &createRunnerFromName);