-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfiler.cc
More file actions
68 lines (53 loc) · 1.61 KB
/
Profiler.cc
File metadata and controls
68 lines (53 loc) · 1.61 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
#include "Profiler.hh"
#include <sys/time.h>
#include <sys/resource.h>
#include <omp.h>
map<string, double> Profiler::timer;
map<string, int> Profiler::counter;
float Profiler::start_time = -1;
Profiler::Profiler()
{
if (start_time < 0)
{
start_time = omp_get_wtime();
counter["N_Threads"] = omp_get_max_threads();
}
}
map<string,float> Profiler::GetTimes()
{
struct rusage ru;
getrusage(RUSAGE_SELF,&ru);
map<string,float> times;
times["user"] = ru.ru_utime.tv_sec + 1e-6*ru.ru_utime.tv_usec;
times["system"] = ru.ru_stime.tv_sec + 1e-6*ru.ru_stime.tv_usec;
times["real"] = omp_get_wtime() - start_time;
return times;
}
void Profiler::PrintTimes()
{
auto time_tot = GetTimes();
cout << "====================== TIMES (s) ====================" << endl;
cout.setf(ios::fixed);
for ( auto it : timer )
{
int nfill = (int) (20 * it.second / time_tot["real"]);
cout << setw(40) << std::left << it.first + ": " << setw(12) << setprecision(5) << std::right << it.second;
cout << " (" << setw(4) << setprecision(1) << 100*it.second / time_tot["real"] << "%) |";
for (int ifill=0; ifill<nfill; ifill++) cout << "*";
for (int ifill=nfill; ifill<20; ifill++) cout << " ";
cout << "|";
cout << endl;
}
}
void Profiler::PrintCounters()
{
cout << "===================== COUNTERS =====================" << endl;
cout.setf(ios::fixed);
for ( auto it : counter )
cout << setw(40) << std::left << it.first + ": " << setw(12) << setprecision(0) << std::right << it.second << endl;
}
void Profiler::PrintAll()
{
PrintCounters();
PrintTimes();
}