From 470ccafaeb947e21b6ed905fa5926458a17e228b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Fri, 4 Nov 2016 22:29:42 +0100 Subject: [PATCH] Added C++ wrapper for prof_counter --- include/profile.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/profile.h b/include/profile.h index acf9166bbb..d14f29d889 100644 --- a/include/profile.h +++ b/include/profile.h @@ -33,6 +33,9 @@ #include #include +#include +#include + /** * Function get_tics * Returns the number of microseconds that have elapsed since the system was started. @@ -87,4 +90,45 @@ static inline void prof_end( prof_counter* aCnt ) aCnt->end = get_tics(); } +class PROF_COUNTER +{ +public: + PROF_COUNTER(const std::string& name, bool autostart = true) + { + m_name = name; + m_running= false; + if(autostart) + start(); + } + + void start() + { + m_running = true; + prof_start(&m_cnt); + } + + void stop() + { + if(!m_running) + return; + m_running=false; + prof_end(&m_cnt); + } + + void show() + { + stop(); + fprintf(stderr,"%s took %.1f milliseconds.\n", m_name.c_str(), (double)m_cnt.msecs()); + } + double msecs() const { + return m_cnt.msecs(); + } + +private: + std::string m_name; + prof_counter m_cnt; + bool m_running; +}; + + #endif