WIP: somethings wrong.. #19

Closed
muellerr wants to merge 808 commits from source/master into master
2 changed files with 38 additions and 10 deletions
Showing only changes of commit 3dbf353385 - Show all commits

View File

@ -7,8 +7,10 @@
#include <framework/timemanager/Stopwatch.h> #include <framework/timemanager/Stopwatch.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode): Stopwatch::Stopwatch(bool displayOnDestruction,
StopwatchDisplayMode displayMode):
displayOnDestruction(displayOnDestruction) { displayOnDestruction(displayOnDestruction) {
// Measures start time on initialization.
Clock::getUptime(&startTime); Clock::getUptime(&startTime);
} }
@ -28,7 +30,7 @@ ms_double_t Stopwatch::stopPrecise() {
void Stopwatch::display() { void Stopwatch::display() {
if(displayMode == DisplayMode::MS_DOUBLE) { if(displayMode == StopwatchDisplayMode::MS_DOUBLE) {
info << "Stopwatch: Operation took " << info << "Stopwatch: Operation took " <<
elapsedTimeMsDouble << " milliseconds" << std::endl; 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() { void Stopwatch::stopInternal() {
elapsedTime = Clock::getUptime() - startTime; elapsedTime = Clock::getUptime() - startTime;

View File

@ -8,6 +8,11 @@
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ #define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#include <framework/timemanager/Clock.h> #include <framework/timemanager/Clock.h>
enum class StopwatchDisplayMode {
MS_DOUBLE,
MS
};
/** /**
* @brief Simple Stopwatch implementation to measure elapsed time * @brief Simple Stopwatch implementation to measure elapsed time
* @details * @details
@ -15,24 +20,38 @@
* times automatically on destruction if not explicitely deactivated in the * times automatically on destruction if not explicitely deactivated in the
* constructor. The default time format is the elapsed time in miliseconds * constructor. The default time format is the elapsed time in miliseconds
* as a float. * as a float.
* This class caches the value
*/ */
class Stopwatch { class Stopwatch {
enum class DisplayMode {
MS_DOUBLE,
MS
};
Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode = Stopwatch(bool displayOnDestruction = true,
DisplayMode::MS_DOUBLE); StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE);
virtual~ Stopwatch(); virtual~ Stopwatch();
/**
* Caches the start time
*/
void start(); void start();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in milliseconds (rounded)
*/
ms_normal_t stop(); ms_normal_t stop();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in milliseconds (doulbe precision)
*/
ms_double_t stopPrecise(); ms_double_t stopPrecise();
/**
* Displays the elapsed times on the osstream, depending on internal display
* mode.
*/
void display(); void display();
StopwatchDisplayMode getDisplayMode() const;
void setDisplayMode(StopwatchDisplayMode displayMode);
private: private:
timeval startTime {0, 0}; timeval startTime {0, 0};
@ -40,7 +59,7 @@ private:
double elapsedTimeMsDouble = 0; double elapsedTimeMsDouble = 0;
bool displayOnDestruction = true; bool displayOnDestruction = true;
DisplayMode displayMode = DisplayMode::MS_DOUBLE; StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE;
void stopInternal(); void stopInternal();
}; };