-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiming.cpp
More file actions
49 lines (40 loc) · 1.97 KB
/
Copy pathtiming.cpp
File metadata and controls
49 lines (40 loc) · 1.97 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
#include "timing.hpp"
RaytracingTimer *RaytracingTimer::instance = nullptr;
std::map<RaytracingTimer::Component, std::string> RaytracingTimer::componentNames = {
{Component::SCENE_LOADING, "Scene Loading"},
{Component::ENCODING, "Encoding"},
{Component::RAYTRACING, "Raytracing"},
};
RaytracingTimer *RaytracingTimer::getInstance() {
if (instance == nullptr) {
instance = new RaytracingTimer();
}
return instance;
}
void RaytracingTimer::start(RayTracing::RayTracer *tracer, Component component) {
std::string tracerName = tracer->identifier();
startTimings[tracerName][component] = std::chrono::high_resolution_clock::now();
}
void RaytracingTimer::end(RayTracing::RayTracer *tracer, Component component) {
std::string tracerName = tracer->identifier();
auto endTime = std::chrono::high_resolution_clock::now();
auto startTime = startTimings[tracerName][component];
double duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
timings[tracerName][component] += duration;
}
void RaytracingTimer::log(RayTracing::RayTracer *tracer, Component component, std::string humanText) {
std::string tracerName = tracer->identifier();
double duration = timings[tracerName][component];
std::cout << "[" << tracerName << "] " << ((humanText.empty()) ? componentNames[component] : humanText) << " took "
<< duration << " ms\n";
}
void RaytracingTimer::logDuration(RayTracing::RayTracer *tracer, Component component, double duration,
std::string humanText) {
std::string tracerName = tracer->identifier();
timings[tracerName][component] += duration;
std::cout << "[" << tracerName << "] " << ((humanText.empty()) ? componentNames[component] : humanText) << " took "
<< duration << " ms\n";
}
double RaytracingTimer::getDuration(RayTracing::RayTracer *tracer, Component component) {
return timings[tracer->identifier()][component];
}