【方法之一】
CTime ctimestart = ::GetCurrentTime();//add by yuan.wang20171107
/****要测试的耗时代码*******/
CTime ctimeend = ::GetCurrentTime();
CTimeSpan span = ctimeend - ctimestart;
int sss = span.GetTotalSeconds();//系统函数,计算总的耗时单位为秒(s)
CString str;
str.Format(_T(" time: %d"), sss);
KXLOG_INFO(str,KXSZ_LOG_CATEGORY_COMMON);//将要显示的信息打印到mess中
【精确计算耗时宏】
KXBEGIN_TIMECOUNT( SingleStep );
if ( KVIO_OK != pOPCServer->SingleStep() )
{
Ret = 0;
bLoopFlag = FALSE;
}
KXEND_TIMECOUNT( SingleStep );
double DealTime = KX_GETTIMECOUNT( SingleStep );
if (DealTime > 500.0)//处理超过500ms进行输出
{
wchar_t Msg[MAX_TRACE_BUFFER] = {0};
swprintf_s( Msg, MAX_TRACE_BUFFER, WSTR( "SingleStep,cost %0.5f ms." ), DealTime);
KVLOG_INFO(KXLOG_CATEGORY_OPCCOLLECTOR, Msg);
}
对应的文件位置:
e:\Company project\00320台湾-新茂能源實業有限公司\KS31.05\04代码\Include\Common\kxCommon\kxCommon_inc.h