WIP: somethings wrong.. #19
@ -6,10 +6,11 @@
|
|||||||
|
|
||||||
#include <framework/timemanager/Stopwatch.h>
|
#include <framework/timemanager/Stopwatch.h>
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
Stopwatch::Stopwatch(bool displayOnDestruction,
|
Stopwatch::Stopwatch(bool displayOnDestruction,
|
||||||
StopwatchDisplayMode displayMode):
|
StopwatchDisplayMode displayMode, uint8_t precision):
|
||||||
displayOnDestruction(displayOnDestruction) {
|
displayOnDestruction(displayOnDestruction), outputPrecision(precision) {
|
||||||
// Measures start time on initialization.
|
// Measures start time on initialization.
|
||||||
Clock::getUptime(&startTime);
|
Clock::getUptime(&startTime);
|
||||||
}
|
}
|
||||||
@ -31,8 +32,9 @@ ms_double_t Stopwatch::stopPrecise() {
|
|||||||
|
|
||||||
void Stopwatch::display() {
|
void Stopwatch::display() {
|
||||||
if(displayMode == StopwatchDisplayMode::MS_DOUBLE) {
|
if(displayMode == StopwatchDisplayMode::MS_DOUBLE) {
|
||||||
info << "Stopwatch: Operation took " <<
|
info << "Stopwatch: Operation took "
|
||||||
elapsedTimeMsDouble << " milliseconds" << std::endl;
|
<< std::setprecision(outputPrecision) << elapsedTimeMsDouble
|
||||||
|
<< " milliseconds" << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 +
|
info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 +
|
||||||
@ -56,6 +58,8 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const {
|
|||||||
return displayMode;
|
return displayMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Stopwatch::stopInternal() {
|
void Stopwatch::stopInternal() {
|
||||||
elapsedTime = Clock::getUptime() - startTime;
|
elapsedTime = Clock::getUptime() - startTime;
|
||||||
elapsedTimeMsDouble = timevalOperations::toDouble(elapsedTime) * 1000.0;
|
elapsedTimeMsDouble = timevalOperations::toDouble(elapsedTime) * 1000.0;
|
||||||
|
@ -22,9 +22,19 @@ enum class StopwatchDisplayMode {
|
|||||||
* as a float.
|
* as a float.
|
||||||
*/
|
*/
|
||||||
class Stopwatch {
|
class Stopwatch {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Default constructor. Call "Stopwatch stopwatch" without brackets if
|
||||||
|
* no parameters are required!
|
||||||
|
* @param displayOnDestruction If set to true, displays measured time on
|
||||||
|
* object destruction
|
||||||
|
* @param displayMode Display format is either MS rounded or MS as double
|
||||||
|
* format
|
||||||
|
* @param outputPrecision If using double format, specify precision here.
|
||||||
|
*/
|
||||||
Stopwatch(bool displayOnDestruction = true,
|
Stopwatch(bool displayOnDestruction = true,
|
||||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE);
|
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE,
|
||||||
|
uint8_t outputPrecision = 4);
|
||||||
virtual~ Stopwatch();
|
virtual~ Stopwatch();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,12 +63,12 @@ class Stopwatch {
|
|||||||
StopwatchDisplayMode getDisplayMode() const;
|
StopwatchDisplayMode getDisplayMode() const;
|
||||||
void setDisplayMode(StopwatchDisplayMode displayMode);
|
void setDisplayMode(StopwatchDisplayMode displayMode);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
timeval startTime {0, 0};
|
timeval startTime {0, 0};
|
||||||
timeval elapsedTime {0, 0};
|
timeval elapsedTime {0, 0};
|
||||||
double elapsedTimeMsDouble = 0;
|
double elapsedTimeMsDouble {0.0};
|
||||||
|
|
||||||
bool displayOnDestruction = true;
|
bool displayOnDestruction = true;
|
||||||
|
uint8_t outputPrecision = 4;
|
||||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE;
|
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE;
|
||||||
|
|
||||||
void stopInternal();
|
void stopInternal();
|
||||||
|
Loading…
Reference in New Issue
Block a user