WIP: somethings wrong.. #19
@ -10,7 +10,6 @@
|
|||||||
Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode):
|
Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode):
|
||||||
displayOnDestruction(displayOnDestruction) {
|
displayOnDestruction(displayOnDestruction) {
|
||||||
Clock::getUptime(&startTime);
|
Clock::getUptime(&startTime);
|
||||||
stopwatchState = StopwatchState::STARTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stopwatch::start() {
|
void Stopwatch::start() {
|
||||||
@ -18,31 +17,22 @@ void Stopwatch::start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ms_normal_t Stopwatch::stop() {
|
ms_normal_t Stopwatch::stop() {
|
||||||
elapsedTime = Clock::getUptime() - startTime;
|
stopInternal();
|
||||||
int32_t elapsedTimeMs = elapsedTime.tv_sec * 1000 +
|
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
|
||||||
elapsedTime.tv_usec/1000;
|
|
||||||
if(elapsedTimeMs < 0) {
|
|
||||||
error << "Stopwatch: Measured time negative!";
|
|
||||||
return INVALID_TIME;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return static_cast<ms_normal_t>(elapsedTimeMs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_double_t Stopwatch::stopPrecise() {
|
ms_double_t Stopwatch::stopPrecise() {
|
||||||
elapsedTime = Clock::getUptime() - startTime;
|
stopInternal();
|
||||||
return timevalOperations::toDouble(elapsedTime) * 1000.0;
|
return elapsedTimeMsDouble;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Stopwatch::display() {
|
void Stopwatch::display() {
|
||||||
if(displayMode == DisplayMode::MS_FLOAT) {
|
if(displayMode == DisplayMode::MS_DOUBLE) {
|
||||||
info << "Stopwatch: Operation took " <<
|
info << "Stopwatch: Operation took " <<
|
||||||
elapsedTimeMs << " milliseconds" << std::endl;
|
elapsedTimeMsDouble << " milliseconds" << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
timeval elapsedTime = stopTime - startTime;
|
|
||||||
info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 +
|
info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 +
|
||||||
elapsedTime.tv_usec * 1000 << " milliseconds";
|
elapsedTime.tv_usec * 1000 << " milliseconds";
|
||||||
}
|
}
|
||||||
@ -56,7 +46,8 @@ Stopwatch::~Stopwatch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Stopwatch::stopInternal() {
|
void Stopwatch::stopInternal() {
|
||||||
elapsedTime = Clock::getUptime() - startTime;
|
elapsedTime = Clock::getUptime() - startTime;
|
||||||
elapsedTimeMs = timevalOperations::toDouble(elapsedTime) * 1000.0;
|
elapsedTimeMsDouble = timevalOperations::toDouble(elapsedTime) * 1000.0;
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,23 @@
|
|||||||
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
||||||
#include <framework/timemanager/Clock.h>
|
#include <framework/timemanager/Clock.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Simple Stopwatch implementation to measure elapsed time
|
||||||
|
* @details
|
||||||
|
* This class can be used to measure elapsed times. It also displays elapsed
|
||||||
|
* times automatically on destruction if not explicitely deactivated in the
|
||||||
|
* constructor. The default time format is the elapsed time in miliseconds
|
||||||
|
* as a float.
|
||||||
|
* This class caches the value
|
||||||
|
*/
|
||||||
class Stopwatch {
|
class Stopwatch {
|
||||||
enum class DisplayMode {
|
enum class DisplayMode {
|
||||||
MS_FLOAT,
|
MS_DOUBLE,
|
||||||
MS
|
MS
|
||||||
};
|
};
|
||||||
|
|
||||||
Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode =
|
Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode =
|
||||||
DisplayMode::MS_FLOAT);
|
DisplayMode::MS_DOUBLE);
|
||||||
virtual~ Stopwatch();
|
virtual~ Stopwatch();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
@ -25,23 +34,13 @@ class Stopwatch {
|
|||||||
|
|
||||||
void display();
|
void display();
|
||||||
private:
|
private:
|
||||||
static const ms_normal_t INVALID_TIME = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
timeval startTime {0, 0};
|
timeval startTime {0, 0};
|
||||||
timeval stopTime {0, 0};
|
|
||||||
timeval elapsedTime {0, 0};
|
timeval elapsedTime {0, 0};
|
||||||
double elapsedTimeMs = 0;
|
double elapsedTimeMsDouble = 0;
|
||||||
//ms_normal_t elapsedTimeMs {0};
|
|
||||||
|
|
||||||
bool displayOnDestruction = true;
|
bool displayOnDestruction = true;
|
||||||
|
DisplayMode displayMode = DisplayMode::MS_DOUBLE;
|
||||||
enum class StopwatchState {
|
|
||||||
IDLE,
|
|
||||||
STARTED,
|
|
||||||
};
|
|
||||||
|
|
||||||
StopwatchState stopwatchState = StopwatchState::IDLE;
|
|
||||||
DisplayMode displayMode = DisplayMode::MS_FLOAT;
|
|
||||||
|
|
||||||
void stopInternal();
|
void stopInternal();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user