-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart4.cpp
55 lines (50 loc) · 1.67 KB
/
part4.cpp
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
/*
* Copyright (c) 2019, Aditya Rohan
* Copyright (c) 2019, Aniket Pandey
*
* Submitted to:
* CS622A: 2019-20 Fall Semester. Assignment 2
*/
#include <experimental/filesystem>
#include <iostream>
#include <fstream>
#include <map>
#include <sstream>
#include <unordered_set>
#define BLOCK_OFFSET 6
#define THREAD_NUM 8
using namespace std;
namespace fs = std::experimental::filesystem;
typedef unsigned long long int_t;
int main(int argc, char *argv[]) {
int_t tid, block;
string line, folder = "traces";
for (const auto& tracefile : fs::directory_iterator(folder)) {
map <int_t, unordered_set<int> > matrix;
map <int, int> profile;
ifstream tracestrm (tracefile.path());
if (!tracestrm.is_open())
cerr << "Tracefile " << tracefile.path().filename().string()
<< " could not be opened\n";
cout << "Processing file " << tracefile.path().filename().string()
<< endl;
while (getline(tracestrm, line)) {
stringstream line_(line);
line_ >> tid >> block;
block = block >> BLOCK_OFFSET;
matrix[block].emplace(tid);
}
// Segregate all blocks into their respective profiles
map <int_t, unordered_set <int> > :: iterator itr;
for (itr = matrix.begin(); itr != matrix.end(); ++itr) {
profile[itr->second.size()]++;
}
// Result compilation
cout << "Number of private blocks: " << profile[1] << endl;
for (int i = 2; i <= THREAD_NUM; ++i) {
cout << "Number of " << i << " shared blocks: "
<< profile[i] << endl;
}
}
return 0;
}