feat: 实现日志与调试系统(Debug模块)
- LogLevel: 日志级别枚举 (Verbose, Debug, Info, Warning, Error, Fatal) - LogCategory: 日志分类 (General, Rendering, Physics, Memory, Threading等) - ILogSink: 日志输出接口 - ConsoleLogSink: 控制台输出, 支持Windows颜色 - FileLogSink: 文件日志输出 - FileWriter: 文件写入器 - Logger: 日志管理器, 支持多sink, 分类控制 - Profiler: 性能分析器 - 单元测试覆盖
This commit is contained in:
73
engine/src/Debug/Profiler.cpp
Normal file
73
engine/src/Debug/Profiler.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user