WallclockTimer updated
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1694 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -7,22 +7,15 @@
|
||||
namespace fail {
|
||||
|
||||
WallclockTimer::WallclockTimer() {
|
||||
m_log.setDescription("WallclockTimer");
|
||||
m_log.showTime(false);
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
void WallclockTimer::startTimer() {
|
||||
if (isRunning) {
|
||||
m_log << "WallclockTimer is already running." << std::endl;
|
||||
} else {
|
||||
isRunning = true;
|
||||
gettimeofday(&start, NULL);
|
||||
m_log << "WallclockTimer started." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::string WallclockTimer::getRuntime() {
|
||||
std::string WallclockTimer::getRuntimeAsString() {
|
||||
|
||||
int length;
|
||||
long t1,t2, duration;
|
||||
@ -53,14 +46,46 @@ std::string WallclockTimer::getRuntime() {
|
||||
return resultstring.str();
|
||||
}
|
||||
|
||||
double WallclockTimer::getRuntimeAsDouble() {
|
||||
|
||||
int length;
|
||||
long t1,t2, duration;
|
||||
double resultdouble
|
||||
std::stringstream lengthinfo, resultstring;
|
||||
|
||||
if (isRunning) {
|
||||
gettimeofday(¤t, NULL);
|
||||
t1 = (start.tv_sec*1000000)+start.tv_usec;
|
||||
t2 = (current.tv_sec*1000000)+current.tv_usec;
|
||||
} else {
|
||||
t1 = (start.tv_sec*1000000)+start.tv_usec;
|
||||
t2 = (end.tv_sec*1000000)+end.tv_usec;
|
||||
}
|
||||
|
||||
duration = t2-t1;
|
||||
lengthinfo << duration-((duration/1000000)*1000000);
|
||||
length = lengthinfo.str().length();
|
||||
resultstring << (int) duration/1000000 << ".";
|
||||
|
||||
if (length < 6) {
|
||||
int i;
|
||||
for (i = 0 ; i< 6-length ; i++){
|
||||
resultstring << "0";
|
||||
}
|
||||
}
|
||||
|
||||
resultstring << (int) duration-((duration/1000000)*1000000);
|
||||
resultdouble = atof( resultstring.str().c_str() );
|
||||
return resultdouble;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WallclockTimer::stopTimer() {
|
||||
if (isRunning) {
|
||||
isRunning = false;
|
||||
gettimeofday(&end, NULL);
|
||||
m_log << "WallclockTimer stopped." << std::endl;
|
||||
} else {
|
||||
m_log << "WallclockTimer is already stopped." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WallclockTimer::reset() {
|
||||
@ -71,7 +96,6 @@ void WallclockTimer::reset() {
|
||||
current.tv_usec = 0;
|
||||
end.tv_sec = 0;
|
||||
end.tv_usec = 0;
|
||||
m_log << "WallclockTimer reseted." << std::endl;
|
||||
}
|
||||
|
||||
} // end-of-namespace: fail
|
||||
|
||||
@ -8,9 +8,11 @@
|
||||
#define __WALLCLOCKTIMER_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "Logger.hpp"
|
||||
|
||||
namespace fail {
|
||||
|
||||
@ -25,7 +27,6 @@ private:
|
||||
|
||||
bool isRunning;
|
||||
struct timeval start,end,current;
|
||||
Logger m_log;
|
||||
|
||||
public:
|
||||
WallclockTimer();
|
||||
@ -35,9 +36,13 @@ public:
|
||||
*/
|
||||
void startTimer();
|
||||
/**
|
||||
* Returns the elapsed time. This works while the timer is running, and if it is stopped.
|
||||
* Returns the elapsed time as string. This works while the timer is running, and if it is stopped.
|
||||
*/
|
||||
std::string getRuntime();
|
||||
std::string getRuntimeAsString();
|
||||
/**
|
||||
* Returns the elapsed time as double. This works while the timer is running, and if it is stopped.
|
||||
*/
|
||||
double getRuntimeAsDouble();
|
||||
/**
|
||||
* Stops the timer.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user