GrabBag/VrUtils/Inc/VrDebugTime.h

52 lines
1.4 KiB
C++

#pragma once
#include <string>
#include <thread>
#include <assert.h>
#include <ratio>
#include <chrono>
#include <sstream>
#include "VrSimpleLog.h"
/// \brief
/// 输出运行时间
class CVrDebugTimer
{
public:
CVrDebugTimer(const char* szDesc)
: 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()
{
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
/// 打印运行时间
#define VRDEBUG_PRINT_TIME(_desc) CVrDebugTimer oFuncDebugTime(_desc)