Added C++ wrapper for prof_counter

This commit is contained in:
Tomasz Włostowski 2016-11-04 22:29:42 +01:00 committed by Maciej Suminski
parent 9c758c4010
commit 470ccafaeb
1 changed files with 44 additions and 0 deletions

View File

@ -33,6 +33,9 @@
#include <sys/time.h>
#include <stdint.h>
#include <cstdio>
#include <string>
/**
* 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