-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileCompilationsExporter.cpp
More file actions
84 lines (68 loc) · 2.59 KB
/
FileCompilationsExporter.cpp
File metadata and controls
84 lines (68 loc) · 2.59 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
#include "FileCompilationsExporter.h"
#include <fstream>
#include <algorithm>
#include <chrono>
FileCompilationsExporter::FileCompilationsExporter(const TFileCompilationDataPerFile& data)
: m_data(data)
{
}
FileCompilationsExporter::~FileCompilationsExporter()
{
}
template<typename T>
bool FileCompilationsExporter::ExportTo(const std::string& path) const
{
std::ofstream out(path);
if (!out)
{
return false;
}
// create a vector with data
std::vector<const TFileCompilationDataPerFile::value_type*> dataPerFile;
for (auto&& pair : m_data)
{
dataPerFile.push_back(&pair);
}
// sort it (slowest compilations first)
std::sort(dataPerFile.begin(), dataPerFile.end(), [](const TFileCompilationDataPerFile::value_type* lhs,
const TFileCompilationDataPerFile::value_type* rhs)
{
std::chrono::nanoseconds lhsTotalDuration = lhs->second.BackEnd.Stop - lhs->second.FrontEnd.Start;
std::chrono::nanoseconds rhsTotalDuration = rhs->second.BackEnd.Stop - rhs->second.FrontEnd.Start;
return lhsTotalDuration > rhsTotalDuration;
});
std::string timeType = "nanoseconds";
if (std::is_same<T, std::chrono::seconds>::value)
{
timeType = "seconds";
}
else if (std::is_same<T, std::chrono::milliseconds>::value)
{
timeType = "miliseconds";
}
// write data header to stream
out << "File path" << ";"
<< "Compilation time (" << timeType << ")" << ";"
<< "Front-end time (" << timeType << ")" << ";"
<< "Back-end time (" << timeType << ")" << std::endl;
// write data to stream
for (auto&& data : dataPerFile)
{
const FileCompilationData& perFile = data->second;
T compileTime = std::chrono::duration_cast<T>(perFile.BackEnd.Stop - perFile.FrontEnd.Start);
T frontEndTime = std::chrono::duration_cast<T>(perFile.FrontEnd.Stop - perFile.FrontEnd.Start);
T backEndTime = std::chrono::duration_cast<T>(perFile.BackEnd.Stop - perFile.BackEnd.Start);
out << data->first << ";"
<< compileTime.count() << ";"
<< frontEndTime.count() << ";"
<< backEndTime.count() << std::endl;
}
out.close();
return true;
}
template
bool FileCompilationsExporter::ExportTo<std::chrono::seconds>(const std::string& path) const;
template
bool FileCompilationsExporter::ExportTo<std::chrono::milliseconds>(const std::string& path) const;
template
bool FileCompilationsExporter::ExportTo<std::chrono::nanoseconds>(const std::string& path) const;