forked from 0xShug0/audio.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiler.cpp
More file actions
26 lines (21 loc) · 748 Bytes
/
Copy pathprofiler.cpp
File metadata and controls
26 lines (21 loc) · 748 Bytes
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
#include "engine/framework/debug/profiler.h"
#include <string>
namespace engine::debug {
ScopeTimer::ScopeTimer(
LogLevel level,
std::string_view category,
std::string_view name)
: active_(log_enabled()),
level_(level),
category_(category),
name_(name),
started_(active_ ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{}) {}
ScopeTimer::~ScopeTimer() {
if (!active_) {
return;
}
const auto ended = std::chrono::steady_clock::now();
const auto micros = std::chrono::duration_cast<std::chrono::microseconds>(ended - started_).count();
log_message(level_, category_, name_ + " took " + std::to_string(micros) + " us");
}
} // namespace engine::debug