-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMatrixMeasurement.h
More file actions
120 lines (100 loc) · 3.67 KB
/
Copy pathMatrixMeasurement.h
File metadata and controls
120 lines (100 loc) · 3.67 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
//
// Created by liork on 8/22/18.
//
#ifndef MATRIXMEASUREMENT_H
#define MATRIXMEASUREMENT_H
#include <string>
#include <chrono>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
using namespace std::chrono;
class MatrixMeasurement
{
private:
string getcwdStr()
{
char buff[256];
auto res = getcwd(buff, 256);
if(NULL == res)
exit(-1);
return string(res);
}
int getTaskIdx(string name)
{
auto it = std::find(m_tasksNames.begin(), m_tasksNames.end(), name);
auto idx = distance(m_tasksNames.begin(), it);
return idx;
}
vector<vector<long>> m_cpuStartTimes;
vector<vector<long>> m_cpuEndTimes;
string m_arguments = "";
vector<string> m_tasksNames;
int m_partiesNumber = 0;
string m_logsPath;
public:
MatrixMeasurement(size_t argc, char* argv[], int partiesNumber, vector<string> tasksNames, int numberOfIterations,
string logsPath=""):
m_cpuStartTimes(vector<vector<long>>(tasksNames.size(), vector<long>(numberOfIterations))),
m_cpuEndTimes(vector<vector<long>>(tasksNames.size(), vector<long>(numberOfIterations)))
{
for(size_t idx = 0; idx < argc; ++idx)
{
string s(argv[idx]);
if (idx < argc - 1)
m_arguments += s + "*";
else
m_arguments += s;
}
m_tasksNames = tasksNames;
m_partiesNumber = partiesNumber;
m_logsPath=logsPath;
}
void startSubTask(string taskName, int currentIterationNumber)
{
int taskIdx = getTaskIdx(taskName);
auto now = system_clock::now();
//Cast the time point to ms, then get its duration, then get the duration's count.
auto ms = time_point_cast<milliseconds>(now).time_since_epoch().count();
m_cpuStartTimes[taskIdx][currentIterationNumber] = ms;
}
void endSubTask(string taskName, int currentIterationNumber)
{
int taskIdx = getTaskIdx(taskName);
auto now = system_clock::now();
//Cast the time point to ms, then get its duration, then get the duration's count.
auto ms = time_point_cast<milliseconds>(now).time_since_epoch().count();
m_cpuEndTimes[taskIdx][currentIterationNumber] = ms;
// if this is the last task and last iteration write the data to file
if (taskIdx == m_tasksNames.size() - 1 && currentIterationNumber == m_cpuEndTimes[0].size() - 1)
{
if(m_logsPath.length() == 0)
string logFileName = getcwdStr() + m_arguments + ".log";
else
string logFileName = m_logsPath + m_arguments + ".log";
ofstream logFile(logFileName);
if (logFile.is_open())
{
//write parties number to file
logfile << to_string(m_partiesNumber) + "\n";
//write to file
int numberOfIterations = m_cpuEndTimes[0].size();
for (size_t idx = 0; idx < m_tasksNames.size(); ++idx)
{
logFile << m_tasksNames[idx] + ":";
cout << "taskName : " << m_tasksNames[idx] << endl;
for (size_t idx2 = 0; idx2 < numberOfIterations; ++idx2)
{
cout << "value : " << m_cpuEndTimes[idx][idx2] << endl;
logFile << to_string(m_cpuEndTimes[idx][idx2] - m_cpuStartTimes[idx][idx2])
+ ",";
}
logFile << "\n";
}
logFile.close();
}
}
}
};
#endif //MATRIXMEASUREMENT_H