From 19c07c441d5598cfff77f8fae6a67a841bcefd34 Mon Sep 17 00:00:00 2001 From: xinyang <895639507@qq.com> Date: Wed, 7 Aug 2019 02:36:01 +0800 Subject: [PATCH] =?UTF-8?q?log.h=E6=9B=B4=E5=8A=A0=E9=AB=98=E7=BA=A7?= =?UTF-8?q?=E7=9A=84CNT=5FTIME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- others/include/log.h | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/others/include/log.h b/others/include/log.h index 0a33c0a..5b03c6c 100644 --- a/others/include/log.h +++ b/others/include/log.h @@ -6,6 +6,7 @@ #define _LOG_H_ #include +#include /************** Define the control code *************/ #define START_CTR "\033[0" @@ -130,28 +131,22 @@ /******************** the time counter API ************************/ #if !defined(DO_NOT_CNT_TIME) && LOG_LEVEL > LOG_NONE - #ifdef Windows - #include - #define CNT_TIME(tag, codes, ...) do{ \ - static SYSTEMTIME ts, te; \ - GetLocalTime(&ts); \ - codes; \ - GetLocalTime(&te); \ - LOGM(tag": %dms", (te.wSecond-ts.wSecond)*1000+(te.wMilliseconds-ts.wMilliseconds)); \ - }while (0) - #elif defined(Linux) - #include - #define CNT_TIME(tag, codes, ...) do{ \ - static timeval ts, te; \ - gettimeofday(&ts, NULL); \ - codes; \ - gettimeofday(&te, NULL); \ - LOGM(tag": %.1lfms", ##__VA_ARGS__, (te.tv_sec-ts.tv_sec)*1000.0+(te.tv_usec-ts.tv_usec)/1000.0); \ - }while (0) - #else - #warning "Unsupport plantform for CNT_TIME" - #define CNT_TIME(tag, codes, ...) codes - #endif + #define CNT_TIME(tag, codes, ...) do{ \ + class TimeCounter{ \ + private: \ + systime begin; \ + public: \ + TimeCounter(){ \ + getsystime(begin); \ + } \ + ~TimeCounter(){ \ + systime end; \ + getsystime(end); \ + LOGM(tag": %.1lfms", ##__VA_ARGS__, getTimeIntervalms(end, begin)); \ + } \ + } time_cnt; \ + codes; \ + }while (0) #else #define CNT_TIME(tag, codes, ...) codes #endif