[mpp_time]: Add AUTO_TIMING for C++ function

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I1ec9f6307dce44f7aa086911477b27e523904cdc
This commit is contained in:
Herman Chen
2020-04-18 15:23:54 +08:00
parent 9464af395b
commit 16047eb224
2 changed files with 34 additions and 1 deletions

View File

@@ -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__*/

View File

@@ -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);
}