Files
XCEngine/engine/src/Debug/Profiler.cpp

74 lines
1.8 KiB
C++
Raw Normal View History

#include "Debug/Profiler.h"
#include "Debug/Logger.h"
namespace XCEngine {
namespace Debug {
Profiler& Profiler::Get() {
static Profiler instance;
return instance;
}
void Profiler::Initialize() {
if (m_initialized) {
return;
}
m_initialized = true;
}
void Profiler::Shutdown() {
m_samples.clear();
m_profileStack.clear();
m_initialized = false;
}
void Profiler::BeginProfile(const char* name) {
ProfileNode node;
node.name = name;
node.startTime = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
node.threadId = static_cast<uint32_t>(std::hash<std::thread::id>{}(std::this_thread::get_id()));
m_profileStack.push_back(node);
}
void Profiler::EndProfile() {
if (m_profileStack.empty()) {
return;
}
uint64_t endTime = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
ProfileNode node = m_profileStack.back();
m_profileStack.pop_back();
node.endTime = endTime;
ProfileSample sample;
sample.name = node.name;
sample.duration = node.endTime - node.startTime;
sample.threadId = node.threadId;
m_samples.push_back(sample);
}
void Profiler::BeginFrame() {
m_frameStartTime = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
void Profiler::EndFrame() {
m_samples.clear();
}
void Profiler::MarkEvent(const char* name, uint64_t timestamp, uint32_t threadId) {
}
void Profiler::SetMarker(const char* name, uint32_t color) {
}
void Profiler::ExportChromeTracing(const Containers::String& filePath) {
}
} // namespace Debug
} // namespace XCEngine