-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraceReplayer.cpp
More file actions
69 lines (55 loc) · 1.53 KB
/
TraceReplayer.cpp
File metadata and controls
69 lines (55 loc) · 1.53 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
#include <fstream>
#include <iostream>
#include <iterator>
#include <iomanip>
#include <utility>
#include "TraceReplayer.h"
using namespace std;
TraceReplayer::TraceReplayer(const string& filename) : trace_file(filename, ios::binary), clean_eof(false)
{
if (trace_file.fail())
throw ios_base::failure("Could not open trace file " + filename);
next_record = read_next_record();
}
record_type TraceReplayer::next(void)
{
record_type old_record = next_record;
next_record = read_next_record();
return old_record;
}
TraceReplayer::operator bool() const
{
return !clean_eof;
}
void print_pair(const record_type& interleaving)
{
cout << "Instructions: " << interleaving.first << endl;
cout << "Memory address(es): ";
if (interleaving.second.empty())
cout << "None" << endl;
else
{
cout << hex;
for (auto address : interleaving.second)
cout << address << ' ';
cout << dec << endl;
}
}
//TODO:Check for premature EOF
record_type TraceReplayer::read_next_record(void)
{
record_type record;
clean_eof = trace_file.peek() == EOF;
if (!clean_eof)
{
const uint64_t instruction_count = read<uint64_t>(trace_file);
const uint64_t nb_mem_accesses = read<uint64_t>(trace_file);
record.first = instruction_count;
for (uint64_t i = 0; i < nb_mem_accesses; ++i)
{
const uint64_t address = read<uint64_t>(trace_file);
record.second.push_back(address);
}
}
return record;
}