Refactoring ITAStopWatch

parent 81e4ed24
......@@ -66,11 +66,7 @@ public:
/**
* \note Wurde bereits die Zeitnahme gestartet, wird eine Ausnahme ausgelöst
*/
inline void start()
{
m_dStart = m_pClock->getTime();
m_bStarted = true;
}
void start();
//! Zeitnahme stoppen
/**
......
......@@ -38,31 +38,29 @@ ITAStopWatch::ITAStopWatch()
reset();
}
ITAStopWatch::ITAStopWatch(ITAClock* pClock)
: m_pClock(pClock) {
ITAStopWatch::ITAStopWatch( ITAClock* pClock )
: m_pClock( pClock )
{
if (pClock == NULL)
if (!pClock)
ITA_EXCEPT1(INVALID_PARAMETER, "Clock must not be NULL");
// Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen
if (!m_bInstanceCreated) {
if (!m_bInstanceCreated)
{
ITACriticalSection cs;
cs.enter();
start();
stop();
reset();
for (unsigned int i=0; i<100; i++) {
for (unsigned int i=0; i<100; i++)
{
start();
stop();
}
cs.leave();
m_dStartStopLatency = minimum();
/* DEBUG:
printf("%s: Measured start/stop latency: %0.3f ns\n",
__FUNCTION__, _dStartStopLatency * 1000000000);
*/
m_bInstanceCreated = true;
}
......@@ -82,7 +80,35 @@ void ITAStopWatch::reset()
m_csReadWrite.leave();
}
bool ITAStopWatch::started() const { return m_bStarted; }
void ITAStopWatch::start()
{
m_dStart = m_pClock->getTime();
m_bStarted = true;
}
bool ITAStopWatch::started() const
{
return m_bStarted;
}
double ITAStopWatch::stop()
{
m_dStop = m_pClock->getTime();
double t = m_dStop - m_dStart - m_dStartStopLatency;
m_csReadWrite.enter();
m_dMin = ( std::min )( m_dMin, t );
m_dMax = ( std::max )( m_dMax, t );
m_dSum += t;
m_dSquareSum += ( t*t );
m_uiCycles++;
m_bStarted = false;
m_csReadWrite.leave();
return t;
}
unsigned int ITAStopWatch::cycles() const
{
......@@ -92,26 +118,22 @@ unsigned int ITAStopWatch::cycles() const
return uiResult;
}
/*
void ITAStopWatch::setMaxCycles(unsigned int uiMaxCycles)
{
m_uiMaxCycles = uiMaxCycles;
}
*/
double ITAStopWatch::minimum() const
{
return (m_uiCycles == 0 ? 0 : m_dMin);
}
double ITAStopWatch::maximum() const {
double ITAStopWatch::maximum() const
{
return m_dMax;
}
double ITAStopWatch::mean() const
{
if (m_csReadWrite.tryenter() == true) {
if (m_uiCycles == 0) {
if (m_csReadWrite.tryenter() == true )
{
if (m_uiCycles == 0)
{
m_csReadWrite.leave();
return -1;
}
......@@ -125,7 +147,8 @@ double ITAStopWatch::mean() const
double ITAStopWatch::variance() const
{
if (m_csReadWrite.tryenter() == true) {
if (m_csReadWrite.tryenter() == true)
{
if (m_uiCycles == 0) {
m_csReadWrite.leave();
return -1;
......@@ -152,7 +175,8 @@ double ITAStopWatch::selftest()
sw.start();
sw.stop();
sw.reset();
for (int i=0; i<1000; i++) {
for (int i=0; i<1000; i++)
{
sw.start();
sw.stop();
}
......@@ -185,22 +209,3 @@ std::string ITAStopWatch::ToString() const
return ss.str();
}
double ITAStopWatch::stop()
{
m_dStop = m_pClock->getTime();
double t = m_dStop - m_dStart - m_dStartStopLatency;
m_csReadWrite.enter();
m_dMin = (std::min)(m_dMin, t);
m_dMax = (std::max)(m_dMax, t);
m_dSum += t;
m_dSquareSum += (t*t);
m_uiCycles++;
m_bStarted = false;
m_csReadWrite.leave();
return t;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment