#include <string>
#include <thread>
#include <assert.h>
#include <ratio>
#include <chrono>
#include <sstream>
#include "VrLog.h"


/// \brief
/// 输出运行时间
class CVuDebugTimer
{
public:
	CVuDebugTimer(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());
	}

	~CVuDebugTimer()
	{
		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 VZDEBUG_PRINT_TIME(_desc) CVuDebugTimer oFuncDebugTime(_desc)
