forked from RedisLabs/memtier_benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_stats.h
169 lines (136 loc) · 5.72 KB
/
run_stats.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
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (C) 2011-2017 Redis Labs Ltd.
*
* This file is part of memtier_benchmark.
*
* memtier_benchmark 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, version 2.
*
* memtier_benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with memtier_benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MEMTIER_BENCHMARK_RUN_STATS_H
#define MEMTIER_BENCHMARK_RUN_STATS_H
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <string>
#include "memtier_benchmark.h"
#include "run_stats_types.h"
#include "JSON_handler.h"
typedef std::map<float, int> latency_map;
typedef std::map<float, int>::iterator latency_map_itr;
typedef std::map<float, int>::const_iterator latency_map_itr_const;
inline long long int ts_diff(struct timeval a, struct timeval b)
{
unsigned long long aval = a.tv_sec * 1000000 + a.tv_usec;
unsigned long long bval = b.tv_sec * 1000000 + b.tv_usec;
return bval - aval;
}
enum tabel_el_type {
string_el,
double_el
};
struct table_el {
tabel_el_type type;
std::string format;
std::string str_value;
double double_value;
table_el* init_str(std::string fmt, std::string val) {
type = string_el;
format = fmt;
str_value = val;
return this;
}
table_el* init_double(std::string fmt, double val) {
type = double_el;
format = fmt;
double_value = val;
return this;
}
};
struct table_column {
table_column() {}
table_column(unsigned int col_size) : column_size(col_size) {}
unsigned int column_size;
std::vector<table_el> elements;
};
class output_table {
private:
std::vector<table_column> columns;
public:
void print_header(FILE *out, const char * header);
void add_column(table_column& col);
void print(FILE *out, const char * header);
};
class run_stats {
protected:
friend bool one_second_stats_predicate(const one_second_stats& a, const one_second_stats& b);
benchmark_config *m_config;
struct timeval m_start_time;
struct timeval m_end_time;
totals m_totals;
std::vector<one_second_stats> m_stats;
one_second_stats m_cur_stats;
latency_map m_get_latency_map;
latency_map m_set_latency_map;
latency_map m_wait_latency_map;
std::vector<latency_map> m_ar_commands_latency_maps;
void roll_cur_stats(struct timeval* ts);
public:
run_stats(benchmark_config *config);
void setup_arbitrary_commands(size_t n_arbitrary_commands);
void set_start_time(struct timeval* start_time);
void set_end_time(struct timeval* end_time);
void update_get_op(struct timeval* ts, unsigned int bytes, unsigned int latency, unsigned int hits, unsigned int misses);
void update_set_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
void update_moved_get_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
void update_moved_set_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
void update_ask_get_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
void update_ask_set_op(struct timeval* ts, unsigned int bytes, unsigned int latency);
void update_wait_op(struct timeval* ts, unsigned int latency);
void update_arbitrary_op(struct timeval *ts, unsigned int bytes,
unsigned int latency, size_t arbitrary_index);
void aggregate_average(const std::vector<run_stats>& all_stats);
void summarize(totals& result) const;
void merge(const run_stats& other, int iteration);
void save_csv_one_sec(FILE *f,
unsigned long int& total_get_ops,
unsigned long int& total_set_ops,
unsigned long int& total_wait_ops);
void save_csv_one_sec_cluster(FILE *f);
void save_csv_set_get_commands(FILE *f, bool cluster_mode);
void save_csv_arbitrary_commands_one_sec(FILE *f,
arbitrary_command_list& command_list,
std::vector<unsigned long int>& total_arbitrary_commands_ops);
void save_csv_arbitrary_commands(FILE *f, arbitrary_command_list& command_list);
bool save_csv(const char *filename, benchmark_config *config);
void debug_dump(void);
// function to handle the results output
bool print_arbitrary_commands_results();
void print_type_column(output_table &table, arbitrary_command_list& command_list);
void print_ops_sec_column(output_table &table);
void print_hits_sec_column(output_table &table);
void print_missess_sec_column(output_table &table);
void print_moved_sec_column(output_table &table);
void print_ask_sec_column(output_table &table);
void print_latency_column(output_table &table);
void print_kb_sec_column(output_table &table);
void print_json(json_handler *jsonhandler, arbitrary_command_list& command_list, bool cluster_mode);
void print_histogram(FILE *out, json_handler* jsonhandler, arbitrary_command_list& command_list);
void print(FILE *file, benchmark_config *config,
const char* header = NULL, json_handler* jsonhandler = NULL);
unsigned int get_duration(void);
unsigned long int get_duration_usec(void);
unsigned long int get_total_bytes(void);
unsigned long int get_total_ops(void);
unsigned long int get_total_latency(void);
};
#endif //MEMTIER_BENCHMARK_RUN_STATS_H