GrabBag/VrUtils/Inc/VrDebugTime.h

52 lines
1.3 KiB
C
Raw Normal View History

#pragma once
2025-06-08 12:48:04 +08:00
#include <string>
#include <thread>
#include <assert.h>
#include <ratio>
#include <chrono>
#include <sstream>
#include "VrSimpleLog.h"
2025-06-08 12:48:04 +08:00
/// \brief
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
class CVrDebugTimer
2025-06-08 12:48:04 +08:00
{
public:
CVrDebugTimer(const char* szDesc)
2025-06-08 12:48:04 +08:00
: m_strFunName(szDesc)
{
m_tBegin = std::chrono::high_resolution_clock::now();
m_tRecordTime = m_tBegin;
LOG_DEBUG("===[%s Runtime]===\n", m_strFunName.c_str());
}
~CVrDebugTimer()
2025-06-08 12:48:04 +08:00
{
std::chrono::high_resolution_clock::time_point tCur = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::ratio<1, 1000>> duration_ms(tCur - m_tBegin);
LOG_DEBUG("===[%s Runtime %f ms]===\n", m_strFunName.c_str(), duration_ms.count());
}
void RecordTime(const char* szDesc)
{
std::chrono::high_resolution_clock::time_point tCur = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::ratio<1, 1000>> duration_ms(tCur - m_tRecordTime);
m_tRecordTime = tCur;
LOG_INFO("===[%s Runtime %f ms]===\n", szDesc, duration_ms.count());
}
private:
std::string m_strFunName;
std::chrono::high_resolution_clock::time_point m_tBegin;
std::chrono::high_resolution_clock::time_point m_tRecordTime;
};
/// \brief
/// <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
#define VRDEBUG_PRINT_TIME(_desc) CVrDebugTimer oFuncDebugTime(_desc)