git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1867 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
|
|
#include "WallclockTimer.hpp"
|
|
|
|
namespace fail {
|
|
|
|
void WallclockTimer::startTimer()
|
|
{
|
|
m_IsRunning = true;
|
|
gettimeofday(&m_Start, NULL);
|
|
}
|
|
|
|
std::string WallclockTimer::getRuntimeAsString() const
|
|
{
|
|
std::stringstream result;
|
|
result << getRuntimeAsDouble();
|
|
|
|
return result.str().c_str();
|
|
}
|
|
|
|
double WallclockTimer::getRuntimeAsDouble() const
|
|
{
|
|
double result;
|
|
struct timeval current;
|
|
|
|
if (m_IsRunning) {
|
|
gettimeofday(¤t, NULL);
|
|
result = current.tv_sec - m_Start.tv_sec;
|
|
result = result + (((double)current.tv_usec-m_Start.tv_usec)/1000000);
|
|
} else {
|
|
result = m_End.tv_sec - m_Start.tv_sec;
|
|
result = result + (((double)m_End.tv_usec-m_Start.tv_usec)/1000000);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void WallclockTimer::stopTimer()
|
|
{
|
|
if (m_IsRunning) {
|
|
m_IsRunning = false;
|
|
gettimeofday(&m_End, NULL);
|
|
}
|
|
}
|
|
|
|
void WallclockTimer::reset()
|
|
{
|
|
m_IsRunning = false;
|
|
m_Start.tv_sec = 0;
|
|
m_Start.tv_usec = 0;
|
|
m_End.tv_sec = 0;
|
|
m_End.tv_usec = 0;
|
|
}
|
|
|
|
} // end-of-namespace: fail
|