From 2a35266ba784736a68af3c0db9b0e9ba77e8053a Mon Sep 17 00:00:00 2001 From: hellwig Date: Thu, 4 Oct 2012 13:26:48 +0000 Subject: [PATCH] Bugfix WallclockTimer git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1714 8c4709b5-6ec9-48aa-a5cd-a96041d1645a --- src/core/util/WallclockTimer.cc | 47 +++++++++++++-------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/core/util/WallclockTimer.cc b/src/core/util/WallclockTimer.cc index 7fc8af23..001795af 100644 --- a/src/core/util/WallclockTimer.cc +++ b/src/core/util/WallclockTimer.cc @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "WallclockTimer.hpp" @@ -17,38 +19,27 @@ void WallclockTimer::startTimer() { std::string WallclockTimer::getRuntimeAsString() const { - int length; - long t1,t2, duration; - struct timeval current; - std::stringstream lengthinfo, resultstring; + std::stringstream result; + result << getRuntimeAsDouble(); - 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); - return resultstring.str(); + return result.str().c_str(); } double WallclockTimer::getRuntimeAsDouble() const { - return atof(getRuntimeAsString().c_str()); + + double result; + struct timeval current; + + if (isRunning) { + gettimeofday(¤t, NULL); + result = current.tv_sec - start.tv_sec; + result = result + (((double)current.tv_usec-start.tv_usec)/1000000); + } else { + result = end.tv_sec - start.tv_sec; + result = result + (((double)end.tv_usec-start.tv_usec)/1000000); + } + + return result; }