-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.cpp
More file actions
52 lines (40 loc) · 2.03 KB
/
Copy pathlogger.cpp
File metadata and controls
52 lines (40 loc) · 2.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
48
49
50
#include "logger.h"
// Define static members
const std::string Logger::outfile = "output.txt";
void Logger::processLog(unsigned int clk, int pid, std::string cmd, std::string varid, int val) {
static std::mutex f_lk;
std::scoped_lock lock(f_lk);
std::ofstream out(outfile, std::ofstream::app);
if (!out) {
std::cout << "Error opening log file from processLog" << std::endl;
}
if (cmd == "Release" ) {
std::cout << "Clock: " << clk << ", Process " << pid << ": " << cmd << ": Variable " << varid << std::endl;
out << "Clock: " << clk << ", Process " << pid << ": " << cmd << ": Variable " << varid << std::endl;
} else {
std::cout << "Clock: " << clk << ", Process " << pid << ": " << cmd <<
": Variable " << varid << ", Value: " << val << std::endl;
out << "Clock: " << clk << ", Process " << pid << ": " << cmd <<
": Variable " << varid << ", Value: " << val << std::endl;
}
}
void Logger::processStatusLog(unsigned int clk, int pid, std::string status) {
static std::mutex f_lk;
std::scoped_lock lock(f_lk);
std::ofstream out(outfile, std::ofstream::app);
if (!out) {
std::cout << "Error opening log file from processStatusLog" << std::endl;
}
std::cout << "Clock: " << clk << ", Process " << pid << ": " << status << std::endl;
out << "Clock: " << clk << ", Process " << pid << ": " << status << std::endl;
}
void Logger::memManagerSwapLog(unsigned int clk, std::string event, std::string varid1, std::string varid2) {
static std::mutex f_lk;
std::scoped_lock lock(f_lk);
std::ofstream out(outfile, std::ofstream::app);
if (!out) {
std::cout << "Error opening log file from memManagerSwapLog" << std::endl;
}
std::cout << "Clock: " << clk << ", Memory Manager, " << event << ": Variable " << varid1 << " with Variable " << varid2 << std::endl;
out << "Clock: " << clk << ", Memory Manager, " << event << ": Variable " << varid1 << " with Variable " << varid2 << std::endl;
}