forked from 1a1a11a/libCacheSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttl.h
More file actions
56 lines (45 loc) · 1.37 KB
/
ttl.h
File metadata and controls
56 lines (45 loc) · 1.37 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
#pragma once
#include <algorithm>
#include <fstream>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include "libCacheSim/request.h"
namespace traceAnalyzer {
class TtlStat {
public:
TtlStat() = default;
~TtlStat() = default;
void add_req(request_t* req);
friend std::ostream& operator<<(std::ostream& os, const TtlStat& ttl) {
std::stringstream stat_ss;
std::cout << "TTL: " << ttl.ttl_cnt_.size() << " different TTLs, ";
uint64_t n_req = std::accumulate(
std::begin(ttl.ttl_cnt_), std::end(ttl.ttl_cnt_), 0ULL,
[](uint64_t value,
const std::unordered_map<int32_t, uint32_t>::value_type& p) {
return value + p.second;
});
if (ttl.ttl_cnt_.size() > 1) {
stat_ss << "TTL: " << ttl.ttl_cnt_.size() << " different TTLs, ";
for (auto it : ttl.ttl_cnt_) {
if (it.second > (size_t)((double)n_req * 0.01)) {
stat_ss << it.first << ":" << it.second << "("
<< (double)it.second / (double)n_req << "), ";
}
}
stat_ss << "\n";
}
os << stat_ss.str();
return os;
}
void dump(const std::string& filename);
private:
/* the number of requests have ttl value */
std::unordered_map<int32_t, uint32_t> ttl_cnt_{};
bool too_many_ttl_ = false;
};
} // namespace traceAnalyzer