WIP: somethings wrong.. #19
@ -7,8 +7,10 @@
|
||||
#include <framework/timemanager/Stopwatch.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode):
|
||||
Stopwatch::Stopwatch(bool displayOnDestruction,
|
||||
StopwatchDisplayMode displayMode):
|
||||
displayOnDestruction(displayOnDestruction) {
|
||||
// Measures start time on initialization.
|
||||
Clock::getUptime(&startTime);
|
||||
}
|
||||
|
||||
@ -28,7 +30,7 @@ ms_double_t Stopwatch::stopPrecise() {
|
||||
|
||||
|
||||
void Stopwatch::display() {
|
||||
if(displayMode == DisplayMode::MS_DOUBLE) {
|
||||
if(displayMode == StopwatchDisplayMode::MS_DOUBLE) {
|
||||
info << "Stopwatch: Operation took " <<
|
||||
elapsedTimeMsDouble << " milliseconds" << std::endl;
|
||||
}
|
||||
@ -46,6 +48,13 @@ Stopwatch::~Stopwatch() {
|
||||
}
|
||||
}
|
||||
|
||||
void Stopwatch::setDisplayMode(StopwatchDisplayMode displayMode) {
|
||||
this->displayMode = displayMode;
|
||||
}
|
||||
|
||||
StopwatchDisplayMode Stopwatch::getDisplayMode() const {
|
||||
return displayMode;
|
||||
}
|
||||
|
||||
void Stopwatch::stopInternal() {
|
||||
elapsedTime = Clock::getUptime() - startTime;
|
||||
|
@ -8,6 +8,11 @@
|
||||
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
||||
#include <framework/timemanager/Clock.h>
|
||||
|
||||
enum class StopwatchDisplayMode {
|
||||
MS_DOUBLE,
|
||||
MS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Simple Stopwatch implementation to measure elapsed time
|
||||
* @details
|
||||
@ -15,24 +20,38 @@
|
||||
* 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 {
|
||||
enum class DisplayMode {
|
||||
MS_DOUBLE,
|
||||
MS
|
||||
};
|
||||
|
||||
Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode =
|
||||
DisplayMode::MS_DOUBLE);
|
||||
Stopwatch(bool displayOnDestruction = true,
|
||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE);
|
||||
virtual~ Stopwatch();
|
||||
|
||||
/**
|
||||
* Caches the start time
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in milliseconds (rounded)
|
||||
*/
|
||||
ms_normal_t stop();
|
||||
|
||||
/**
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in milliseconds (doulbe precision)
|
||||
*/
|
||||
ms_double_t stopPrecise();
|
||||
|
||||
/**
|
||||
* Displays the elapsed times on the osstream, depending on internal display
|
||||
* mode.
|
||||
*/
|
||||
void display();
|
||||
|
||||
StopwatchDisplayMode getDisplayMode() const;
|
||||
void setDisplayMode(StopwatchDisplayMode displayMode);
|
||||
private:
|
||||
|
||||
timeval startTime {0, 0};
|
||||
@ -40,7 +59,7 @@ private:
|
||||
double elapsedTimeMsDouble = 0;
|
||||
|
||||
bool displayOnDestruction = true;
|
||||
DisplayMode displayMode = DisplayMode::MS_DOUBLE;
|
||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE;
|
||||
|
||||
void stopInternal();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user