-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstatistics.h
More file actions
193 lines (168 loc) · 8.23 KB
/
statistics.h
File metadata and controls
193 lines (168 loc) · 8.23 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
// Created by Ravil Galiev on 03.08.2023.
//
#pragma once
#include "define_global_statistics.h"
#include "gstats_global.h"
#include "debugprinting.h"
#include "nlohmann/json.hpp"
#include "globals_extern.h"
struct Statistic {
int64_t totalAll = 0;
int64_t totalGets;
int64_t totalRQs;
int64_t totalQueries;
int64_t totalInserts;
int64_t totalRemoves;
int64_t totalUpdates;
int64_t totalSuccessfulGets;
int64_t totalSuccessfulInserts;
int64_t totalSuccessfulRemoves;
int64_t totalSuccessfulUpdates;
int64_t totalFailGets;
int64_t totalFailInserts;
int64_t totalFailRemoves;
int64_t totalFailUpdates;
double SECONDS_TO_RUN;
int64_t throughputSearches;
int64_t throughputRQs;
int64_t throughputQueries;
int64_t throughputUpdates;
int64_t throughputAll;
explicit Statistic(double seconds_to_run) {
totalGets = GSTATS_GET_STAT_METRICS(num_searches, TOTAL)[0].sum;
totalRQs = GSTATS_GET_STAT_METRICS(num_rq, TOTAL)[0].sum;
totalQueries = totalGets + totalRQs;
totalInserts = GSTATS_GET_STAT_METRICS(num_inserts, TOTAL)[0].sum;
totalRemoves = GSTATS_GET_STAT_METRICS(num_removes, TOTAL)[0].sum;
totalUpdates = totalInserts + totalRemoves;
totalSuccessfulGets = GSTATS_GET_STAT_METRICS(num_successful_searches, TOTAL)[0].sum;
totalSuccessfulInserts = GSTATS_GET_STAT_METRICS(num_successful_inserts, TOTAL)[0].sum;
totalSuccessfulRemoves = GSTATS_GET_STAT_METRICS(num_successful_removes, TOTAL)[0].sum;
totalSuccessfulUpdates = totalSuccessfulInserts + totalSuccessfulRemoves;
totalFailGets = GSTATS_GET_STAT_METRICS(num_fail_searches, TOTAL)[0].sum;
totalFailInserts = GSTATS_GET_STAT_METRICS(num_fail_inserts, TOTAL)[0].sum;
totalFailRemoves = GSTATS_GET_STAT_METRICS(num_fail_removes, TOTAL)[0].sum;
totalFailUpdates = totalFailInserts + totalFailRemoves;
SECONDS_TO_RUN = seconds_to_run; // (MILLIS_TO_RUN)/1000.;
totalAll = totalUpdates + totalQueries;
throughputSearches = (int64_t)(totalGets / SECONDS_TO_RUN);
throughputRQs = (int64_t)(totalRQs / SECONDS_TO_RUN);
throughputQueries = (int64_t)(totalQueries / SECONDS_TO_RUN);
throughputUpdates = (int64_t)(totalUpdates / SECONDS_TO_RUN);
throughputAll = (int64_t)(totalAll / SECONDS_TO_RUN);
}
void print_total_statistic_short(bool detail = false) const {
COUTATOMIC(std::endl);
COUTATOMIC("total_gets=" << totalGets << std::endl)
if (detail) {
COUTATOMIC("total_successful_gets=" << totalSuccessfulGets << std::endl)
COUTATOMIC("total_fail_gets=" << totalFailGets << std::endl)
}
COUTATOMIC("total_rq=" << totalRQs << std::endl)
COUTATOMIC("total_inserts=" << totalInserts << std::endl)
if (detail) {
COUTATOMIC("total_successful_inserts=" << totalSuccessfulInserts << std::endl)
COUTATOMIC("total_fail_inserts=" << totalFailInserts << std::endl)
}
COUTATOMIC("total_removes=" << totalRemoves << std::endl)
if (detail) {
COUTATOMIC("total_successful_removes=" << totalSuccessfulRemoves << std::endl)
COUTATOMIC("total_fail_removes=" << totalFailRemoves << std::endl)
}
COUTATOMIC("total_updates=" << totalUpdates << std::endl)
if (detail) {
COUTATOMIC("total_successful_updates=" << totalSuccessfulUpdates << std::endl)
COUTATOMIC("total_fail_updates=" << totalFailUpdates << std::endl)
}
COUTATOMIC("total_queries=" << totalQueries << std::endl)
COUTATOMIC("total_ops=" << totalAll << std::endl)
COUTATOMIC("find_throughput=" << throughputSearches << std::endl)
COUTATOMIC("rq_throughput=" << throughputRQs << std::endl)
COUTATOMIC("update_throughput=" << throughputUpdates << std::endl)
COUTATOMIC("query_throughput=" << throughputQueries << std::endl)
COUTATOMIC("total_throughput=" << throughputAll << std::endl)
COUTATOMIC(std::endl);
}
void print_total_statistic(bool detail = false) const {
COUTATOMIC(std::endl)
COUTATOMIC(indented_title_with_data("total gets", totalGets, 1, 32))
if (detail) {
COUTATOMIC(
indented_title_with_data("total successful gets", totalSuccessfulGets, 2, 32))
COUTATOMIC(indented_title_with_data("total fail gets", totalFailGets, 2, 32))
}
COUTATOMIC(indented_title_with_data("total rq", totalRQs, 1, 32))
COUTATOMIC(indented_title_with_data("total inserts", totalInserts, 1, 32))
if (detail) {
COUTATOMIC(
indented_title_with_data("total successful inserts", totalSuccessfulInserts, 2, 32))
COUTATOMIC(indented_title_with_data("total fail inserts", totalFailInserts, 2, 32))
}
COUTATOMIC(indented_title_with_data("total removes", totalRemoves, 1, 32))
if (detail) {
COUTATOMIC(
indented_title_with_data("total successful removes", totalSuccessfulRemoves, 2, 32))
COUTATOMIC(indented_title_with_data("total fail removes", totalFailRemoves, 2, 32))
}
COUTATOMIC(indented_title_with_data("total updates", totalUpdates, 1, 32))
if (detail) {
COUTATOMIC(
indented_title_with_data("total successful updates", totalSuccessfulUpdates, 2, 32))
COUTATOMIC(indented_title_with_data("total fail updates", totalFailUpdates, 2, 32))
}
COUTATOMIC(indented_title_with_data("total queries", totalQueries, 1, 32))
COUTATOMIC(indented_title_with_data("total ops", totalAll, 1, 32))
COUTATOMIC(indented_title_with_data("find throughput", throughputSearches, 1, 32))
COUTATOMIC(indented_title_with_data("rq throughput", throughputRQs, 1, 32))
COUTATOMIC(indented_title_with_data("update throughput", throughputUpdates, 1, 32))
COUTATOMIC(indented_title_with_data("query throughput", throughputQueries, 1, 32))
COUTATOMIC(indented_title_with_data("total throughput", throughputAll, 1, 32))
COUTATOMIC(std::endl)
}
};
void to_json(nlohmann::json& json, const Statistic& s) {
json["total_gets"] = s.totalGets;
json["total_successful_gets"] = s.totalSuccessfulGets;
json["total_fail_gets"] = s.totalFailGets;
json["total_rq"] = s.totalRQs;
json["total_inserts"] = s.totalInserts;
json["total_successful_inserts"] = s.totalSuccessfulInserts;
json["total_fail_inserts"] = s.totalFailInserts;
json["total_removes"] = s.totalRemoves;
json["total_successful_removes"] = s.totalSuccessfulRemoves;
json["total_fail_removes"] = s.totalFailRemoves;
json["total_updates"] = s.totalUpdates;
json["total_successful_updates"] = s.totalSuccessfulUpdates;
json["total_fail_updates"] = s.totalFailUpdates;
json["total_queries"] = s.totalQueries;
json["total_ops"] = s.totalAll;
json["find_throughput"] = s.throughputSearches;
json["rq_throughput"] = s.throughputRQs;
json["update_throughput"] = s.throughputUpdates;
json["query_throughput"] = s.throughputQueries;
json["total_throughput"] = s.throughputAll;
}
void from_json(const nlohmann::json& json, Statistic& s) {
s.totalGets = json["total_gets"];
s.totalSuccessfulGets = json["total_successful_gets"];
s.totalFailGets = json["total_fail_gets"];
s.totalRQs = json["total_rq"];
s.totalInserts = json["total_inserts"];
s.totalSuccessfulInserts = json["total_successful_inserts"];
s.totalFailInserts = json["total_fail_inserts"];
s.totalRemoves = json["total_deletes"];
s.totalSuccessfulRemoves = json["total_successful_removes"];
s.totalFailRemoves = json["total_fail_removes"];
s.totalUpdates = json["total_updates"];
s.totalSuccessfulUpdates = json["total_successful_updates"];
s.totalFailUpdates = json["total_fail_updates"];
s.totalQueries = json["total_queries"];
s.totalAll = json["total_ops"];
s.throughputSearches = json["find_throughput"];
s.throughputRQs = json["rq_throughput"];
s.throughputUpdates = json["update_throughput"];
s.throughputQueries = json["query_throughput"];
s.throughputAll = json["total_throughput"];
}
struct ThreadStatistic {};