usec replaced by seconds
This commit is contained in:
parent
da9bb97b23
commit
5b0f80509f
@ -7,8 +7,8 @@
|
|||||||
#include <framework/ipc/MutexFactory.h>
|
#include <framework/ipc/MutexFactory.h>
|
||||||
#include <framework/globalfunctions/timevalOperations.h>
|
#include <framework/globalfunctions/timevalOperations.h>
|
||||||
|
|
||||||
typedef uint32_t ms_normal_t;
|
typedef uint32_t millis_t;
|
||||||
typedef double ms_double_t;
|
typedef float seconds_t;
|
||||||
|
|
||||||
class Clock {
|
class Clock {
|
||||||
public:
|
public:
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
Stopwatch::Stopwatch(bool displayOnDestruction,
|
Stopwatch::Stopwatch(bool displayOnDestruction,
|
||||||
StopwatchDisplayMode displayMode, uint8_t precision):
|
StopwatchDisplayMode displayMode):
|
||||||
displayOnDestruction(displayOnDestruction), outputPrecision(precision) {
|
displayOnDestruction(displayOnDestruction) {
|
||||||
// Measures start time on initialization.
|
// Measures start time on initialization.
|
||||||
Clock::getUptime(&startTime);
|
Clock::getUptime(&startTime);
|
||||||
}
|
}
|
||||||
@ -19,29 +19,27 @@ void Stopwatch::start() {
|
|||||||
startTime = Clock::getUptime();
|
startTime = Clock::getUptime();
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_normal_t Stopwatch::stop() {
|
millis_t Stopwatch::stop() {
|
||||||
stopInternal();
|
stopInternal();
|
||||||
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
|
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_double_t Stopwatch::stopPrecise() {
|
seconds_t Stopwatch::stopSeconds() {
|
||||||
stopInternal();
|
stopInternal();
|
||||||
return elapsedTimeMsDouble;
|
return timevalOperations::toDouble(elapsedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Stopwatch::display() {
|
void Stopwatch::display() {
|
||||||
if(displayMode == StopwatchDisplayMode::MS_DOUBLE) {
|
if(displayMode == StopwatchDisplayMode::MILLIS) {
|
||||||
info << "Stopwatch: Operation took "
|
|
||||||
<< std::setprecision(outputPrecision) << elapsedTimeMsDouble
|
|
||||||
<< " milliseconds" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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";
|
||||||
}
|
}
|
||||||
|
else if(displayMode == StopwatchDisplayMode::SECONDS) {
|
||||||
|
info <<"Stopwatch: Operation took " << std::setprecision(4)
|
||||||
|
<< std::fixed << timevalOperations::toDouble(elapsedTime)
|
||||||
|
<< " seconds";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Stopwatch::~Stopwatch() {
|
Stopwatch::~Stopwatch() {
|
||||||
if(displayOnDestruction) {
|
if(displayOnDestruction) {
|
||||||
@ -58,9 +56,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#include <framework/timemanager/Clock.h>
|
#include <framework/timemanager/Clock.h>
|
||||||
|
|
||||||
enum class StopwatchDisplayMode {
|
enum class StopwatchDisplayMode {
|
||||||
MS_DOUBLE,
|
MILLIS,
|
||||||
MS
|
SECONDS
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,9 +32,8 @@ public:
|
|||||||
* format
|
* format
|
||||||
* @param outputPrecision If using double format, specify precision here.
|
* @param outputPrecision If using double format, specify precision here.
|
||||||
*/
|
*/
|
||||||
Stopwatch(bool displayOnDestruction = true,
|
Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode
|
||||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE,
|
= StopwatchDisplayMode::MILLIS);
|
||||||
uint8_t outputPrecision = 4);
|
|
||||||
virtual~ Stopwatch();
|
virtual~ Stopwatch();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,13 +45,8 @@ public:
|
|||||||
* Calculates the elapsed time since start and returns it
|
* Calculates the elapsed time since start and returns it
|
||||||
* @return elapsed time in milliseconds (rounded)
|
* @return elapsed time in milliseconds (rounded)
|
||||||
*/
|
*/
|
||||||
ms_normal_t stop();
|
millis_t stop();
|
||||||
|
seconds_t stopSeconds();
|
||||||
/**
|
|
||||||
* 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
|
* Displays the elapsed times on the osstream, depending on internal display
|
||||||
@ -65,11 +59,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
timeval startTime {0, 0};
|
timeval startTime {0, 0};
|
||||||
timeval elapsedTime {0, 0};
|
timeval elapsedTime {0, 0};
|
||||||
double elapsedTimeMsDouble {0.0};
|
|
||||||
|
|
||||||
bool displayOnDestruction = true;
|
bool displayOnDestruction = true;
|
||||||
uint8_t outputPrecision = 4;
|
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS;
|
||||||
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE;
|
|
||||||
|
|
||||||
void stopInternal();
|
void stopInternal();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user