-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerformanceRecorder.cpp
44 lines (39 loc) · 1.63 KB
/
PerformanceRecorder.cpp
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
//
// Created by 胡磊 on 2021/5/7.
//
#ifdef PERFORMANCE_PROFILE
#include <vector>
#include <ostream>
#include <algorithm>
#include "PerformanceRecorder.hpp"
#include "PerformanceRecordTimer.hpp"
PerformanceRecorder g_performance_recorder;
void PerformanceRecorder::clear() { records.empty(); }
// Print formatted statistics into output_stream.
void PerformanceRecorder::print(std::ostream &output_stream) {
std::vector<PerformanceRecord> sorted_by_wall_time;
records_map::iterator iter = records.begin();
while (iter != records.end()) {
sorted_by_wall_time.emplace_back(iter->second);
iter++;
}
// Sort by wall clock time in descender order.
std::sort(
sorted_by_wall_time.begin(),
sorted_by_wall_time.end(),
[](PerformanceRecord &first, PerformanceRecord &second) {
return first.wall_clock_counter > second.wall_clock_counter;
});
std::vector<PerformanceRecord>::iterator viter = sorted_by_wall_time.begin();
while (viter != sorted_by_wall_time.end()) {
PerformanceRecord &performance_record = *(viter++);
output_stream << "["
<< performance_record.file << ":"
<< performance_record.line_number << "]"
<< performance_record.name << ": wall clock time["
<< performance_record.wall_clock_counter * 1.0 / PerformanceRecordTimer::get_counter_per_ms()
<< "ms], invocation count[" << performance_record.count << "].\n" << performance_record.wall_clock_counter;
}
output_stream.flush();
}
#endif // PERFORMANCE_PROFILE