From 16047eb2242649fb609bbf485c499500dfe58f56 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Sat, 18 Apr 2020 15:23:54 +0800 Subject: [PATCH] [mpp_time]: Add AUTO_TIMING for C++ function Signed-off-by: Herman Chen Change-Id: I1ec9f6307dce44f7aa086911477b27e523904cdc --- osal/inc/mpp_time.h | 23 ++++++++++++++++++++++- osal/mpp_time.cpp | 12 ++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/osal/inc/mpp_time.h b/osal/inc/mpp_time.h index 52a29659..2fee54a5 100644 --- a/osal/inc/mpp_time.h +++ b/osal/inc/mpp_time.h @@ -94,5 +94,26 @@ void mpp_timer_put(MppTimer timer); } #endif -#endif /*__MPP_TIME_H__*/ +#ifdef __cplusplus +class AutoTiming +{ +public: + AutoTiming(const char *name = __FUNCTION__); + ~AutoTiming(); +private: + const char *mName; + RK_S64 mStart; + RK_S64 mEnd; + AutoTiming(const AutoTiming &); + AutoTiming &operator = (const AutoTiming&); +}; + +#endif + +#define AUTO_TIMER_STRING(name, cnt) name ## cnt +#define AUTO_TIMER_NAME_STRING(name, cnt) AUTO_TIMER_STRING(name, cnt) +#define AUTO_TIMER_NAME(name) AUTO_TIMER_NAME_STRING(name, __COUNTER__) +#define AUTO_TIMING() AutoTiming AUTO_TIMER_NAME(auto_timing)(__FUNCTION__) + +#endif /*__MPP_TIME_H__*/ diff --git a/osal/mpp_time.cpp b/osal/mpp_time.cpp index 92945a97..05a82b7b 100644 --- a/osal/mpp_time.cpp +++ b/osal/mpp_time.cpp @@ -427,3 +427,15 @@ void mpp_timer_put(MppTimer timer) impl = NULL; } } + +AutoTiming::AutoTiming(const char *name) +{ + mStart = mpp_time(); + mName = name; +} + +AutoTiming::~AutoTiming() +{ + mEnd = mpp_time(); + mpp_log("%s timing %lld us\n", mName, mEnd - mStart); +}