profile.h: added PROF_COUNTER C++ class
This commit is contained in:
parent
94a80acb36
commit
eaba60b89a
|
@ -37,6 +37,9 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class PROF_COUNTER is a small class to help profiling.
|
* The class PROF_COUNTER is a small class to help profiling.
|
||||||
* It allows the calculation of the elapsed time (in millisecondes) between
|
* It allows the calculation of the elapsed time (in millisecondes) between
|
||||||
|
@ -151,4 +154,41 @@ private:
|
||||||
*/
|
*/
|
||||||
unsigned GetRunningMicroSecs();
|
unsigned GetRunningMicroSecs();
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::string m_name;
|
||||||
|
prof_counter m_cnt;
|
||||||
|
bool m_running;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue