forked from 1a1a11a/libCacheSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttl.cpp
More file actions
47 lines (40 loc) · 1.03 KB
/
ttl.cpp
File metadata and controls
47 lines (40 loc) · 1.03 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
#include "ttl.h"
#include <fstream>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include "libCacheSim/request.h"
namespace traceAnalyzer {
using namespace std;
void TtlStat::add_req(request_t *req) {
printf("req->ttl: %d\n", req->ttl);
if (req->ttl > 0) {
auto it = ttl_cnt_.find(req->ttl);
if (it == ttl_cnt_.end()) {
ttl_cnt_[req->ttl] = 1;
if ((!too_many_ttl_) && ttl_cnt_.size() > 1000000) {
too_many_ttl_ = true;
WARN("there are too many TTLs (%zu) in the trace\n", ttl_cnt_.size());
}
} else {
it->second += 1;
}
}
}
void TtlStat::dump(const string &path_base) {
ofstream ofs(path_base + ".ttl", ios::out | ios::trunc);
ofs << "# " << path_base << "\n";
if (too_many_ttl_) {
ofs << "# there are too many TTLs in the trace\n";
return;
} else {
ofs << "# TTL: req_cnt\n";
for (auto &p : ttl_cnt_) {
ofs << p.first << ":" << p.second << "\n";
}
}
ofs.close();
}
}; // namespace traceAnalyzer