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