-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiagnostics.cpp
More file actions
35 lines (29 loc) · 1.06 KB
/
diagnostics.cpp
File metadata and controls
35 lines (29 loc) · 1.06 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
#include "diagnostics.h"
#include "logger.h"
using namespace std;
using namespace std::chrono;
PerformanceData::PerformanceData(const char * name) : name(name) {
_construct_time = system_clock::now();
}
MethodTracker::MethodTracker(PerformanceData & data) : _data(data) {
_start_time = system_clock::now();
}
MethodTracker::~MethodTracker() {
auto end_time = system_clock::now();
_data.total_duration += (end_time-_start_time);
++(_data.call_count);
if((_data.call_count % _data.report_every_n_calls) == 0) {
auto clock_elapsed = system_clock::now() - _data._construct_time;
float percent_wall = 100. * _data.total_duration.count() / clock_elapsed.count();
log_info(
_data.name
+ " call_count: "
+ to_string(_data.call_count)
+ " total_duration: "
+ to_string(_data.total_duration.count() / 1E6) + " ms"
+ " average_duration: "
+ to_string((_data.total_duration.count() / 1E6) / _data.call_count)+ " ms"
+ "% wall: " + to_string(percent_wall)
);
}
}