forked from mohamadkav/HMMsim-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCounter.cpp
More file actions
executable file
·136 lines (113 loc) · 3.33 KB
/
Counter.cpp
File metadata and controls
executable file
·136 lines (113 loc) · 3.33 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
/*
* Copyright (c) 2015 Santiago Bock
*
* See the file LICENSE.txt for copying permission.
*/
#include "Counter.H"
#include "Error.H"
#include <iterator>
Counter::Counter() : value(0), totalValue(0), handler(0), interruptValue(0) {
}
void Counter::add(uint64 amount){
value += amount;
if (handler != 0 && value >= interruptValue){
handler->processInterrupt(this);
}
}
void Counter::reset(){
totalValue += value;
value = 0;
}
void Counter::setInterrupt(uint64 interruptValueArg, IInterruptHandler* handlerArg){
handler = handlerArg;
interruptValue = interruptValueArg;
}
CycleCounter::CycleCounter(Engine *engineArg) : engine(engineArg), lastCycleCount(0){
}
CycleCounter::CycleCounter(const CycleCounter& counter) : engine(counter.engine), lastCycleCount(counter.lastCycleCount){
}
void CycleCounter::reset(){
lastCycleCount = engine->getTimestamp();
}
uint64 CycleCounter::getValue(){
return engine->getTimestamp() - lastCycleCount;
}
CounterTraceReader::CounterTraceReader(string fileName) {
ifstream file(fileName.c_str());
if(file.fail()){
error("Could not open counter trace file %s", fileName.c_str());
}
string line;
while(getline(file, line)){
istringstream iss(line);
string line2;
map<uint64, map<string, uint64> >::iterator it;
while(getline(iss, line2, ',')) {
istringstream iss2(line2);
string key;
uint64 value;
iss2 >> key >> value;
if (key == "instructions"){
it = mapa.emplace(value, map<string, uint64>()).first;
} else {
it->second.emplace(key, value);
}
}
}
}
uint64 CounterTraceReader::getValue(uint64 instr, string key){
map<uint64, map<string, uint64> >::iterator it = mapa.find(instr);
if (it == mapa.end()){
return 0;
} else {
map<string, uint64>::iterator it2 = it->second.find(key);
if (it2 == it->second.end()){
return 0;
} else {
return it2->second;
}
}
}
uint64 CounterTraceReader::getValue(uint64 instrStart, uint64 instrEnd, string key){
if (instrEnd < instrStart){
return 0;
}
uint64 value = 0;
map<uint64, map<string, uint64> >::iterator itStart = mapa.lower_bound(instrStart);
map<uint64, map<string, uint64> >::iterator itEnd = mapa.lower_bound(instrEnd);
while(itStart != itEnd){
map<string, uint64>::iterator it2 = itStart->second.find(key);
if (it2 != itStart->second.end()){
value += it2->second;
}
++itStart;
}
return value;
}
void CounterTraceReader::print(ostream& os){
string orderStr("cycles dram_reads dram_writes pcm_reads pcm_writes dram_read_time dram_write_time pcm_read_time pcm_write_time dram_migrations pcm_migrations dram_migration_time pcm_migration_time");
stringstream strstr(orderStr);
istream_iterator<string> itStr(strstr);
istream_iterator<string> end;
vector<string> order(itStr, end);
for(map<uint64, map<string, uint64> >::iterator it = mapa.begin(); it != mapa.end(); ++it){
os << "instructions " << it->first << ", ";
for (unsigned i = 0; i < order.size(); i++){
map<string, uint64>::iterator it2 = it->second.find(order[i]);
if (it2 != it->second.end()){
os << it2->first << " " << it2->second;
if (i == order.size() - 1){
os << endl;
} else {
os << ", ";
}
}
}
}
}
void CounterTraceReader::getKeyList(vector<uint64>* list){
list->clear();
for(map<uint64, map<string, uint64> >::iterator it = mapa.begin(); it != mapa.end(); ++it){
list->emplace_back(it->first);
}
}