From 8cb74a82187abc67089ec63975ba6e4340a92348 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 20 Feb 2020 17:47:33 +1100 Subject: [PATCH] functiontimer: created convenience class to help when profiling functions --- app/common/CMakeLists.txt | 1 + app/common/functiontimer.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/common/functiontimer.h diff --git a/app/common/CMakeLists.txt b/app/common/CMakeLists.txt index 1d123450b..743df6778 100644 --- a/app/common/CMakeLists.txt +++ b/app/common/CMakeLists.txt @@ -29,6 +29,7 @@ set(OLIVE_SOURCES common/filefunctions.cpp common/flipmodifiers.h common/flipmodifiers.cpp + common/functiontimer.h common/lerp.h common/qtutils.h common/qtutils.cpp diff --git a/app/common/functiontimer.h b/app/common/functiontimer.h new file mode 100644 index 000000000..119aecd1d --- /dev/null +++ b/app/common/functiontimer.h @@ -0,0 +1,33 @@ +#ifndef FUNCTIONTIMER_H +#define FUNCTIONTIMER_H + +#include +#include + +#define TIME_THIS_FUNCTION FunctionTimer __f(__FUNCTION__) + +class FunctionTimer { +public: + FunctionTimer(const char* s) + { + name_ = s; + time_ = QDateTime::currentMSecsSinceEpoch(); + } + + ~FunctionTimer() + { + qint64 elapsed = (QDateTime::currentMSecsSinceEpoch() - time_); + + if (elapsed > 1) { + qDebug() << name_ << "took" << elapsed; + } + } + +private: + const char* name_; + + qint64 time_; + +}; + +#endif // FUNCTIONTIMER_H