forked from 1a1a11a/libCacheSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreqRate.h
More file actions
70 lines (60 loc) · 2.15 KB
/
reqRate.h
File metadata and controls
70 lines (60 loc) · 2.15 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
#pragma once
#include <algorithm>
#include <fstream>
#include <iostream>
#include <unordered_set>
#include <vector>
#include "libCacheSim/macro.h"
#include "libCacheSim/request.h"
namespace traceAnalyzer {
class ReqRate {
public:
ReqRate() = default;
explicit ReqRate(int time_window) : time_window_(time_window){};
~ReqRate() = default;
void add_req(request_t *req);
void dump(const std::string &path_base);
friend std::ostream &operator<<(std::ostream &os, const ReqRate &rr) {
if (rr.req_rate_.size() < 10) {
WARN("request rate not enough window (%zu window)\n",
rr.req_rate_.size());
if (rr.req_rate_.empty()) return os;
}
double max =
(double)*std::max_element(rr.req_rate_.cbegin(), rr.req_rate_.cend()) /
rr.time_window_;
double min =
(double)*std::min_element(rr.req_rate_.cbegin(), rr.req_rate_.cend()) /
rr.time_window_;
os << std::fixed << "request rate min " << min << " req/s, max " << max
<< " req/s, window " << rr.time_window_ << "s\n";
max =
(double)*std::max_element(rr.obj_rate_.cbegin(), rr.obj_rate_.cend()) /
rr.time_window_;
min =
(double)*std::min_element(rr.obj_rate_.cbegin(), rr.obj_rate_.cend()) /
rr.time_window_;
os << std::fixed << "object rate min " << min << " obj/s, max " << max
<< " obj/s, window " << rr.time_window_ << "s\n";
return os;
}
private:
const int time_window_ = 60;
/* objects have been seen in the time window */
// unordered_set<obj_id_t> window_seen_obj_{};
int64_t next_window_ts_ = -1;
/* how many requests in the window */
uint32_t window_n_req_ = 0;
/* how many bytes in the window */
uint64_t window_n_byte_ = 0;
/* how many objects in the window */
uint32_t window_n_obj_ = 0;
/* how many objects requested in the window are first-time in the trace */
uint32_t window_compulsory_miss_obj_ = 0;
std::vector<uint32_t> req_rate_{};
std::vector<uint64_t> byte_rate_{}; /* bytes/sec */
std::vector<uint32_t> obj_rate_{};
/* used to calculate cold miss ratio over time */
std::vector<uint32_t> first_seen_obj_rate_{};
};
} // namespace traceAnalyzer