15 #include <containers/Map.hpp> 16 #include <debug/MinimalCrash.hpp> 17 #include <metaprogramming/TypeTraits.hpp> 18 #include <metaprogramming/UniversalReferences.hpp> 24 std::chrono::steady_clock;
28 std::chrono::time_point<Clock>;
32 decltype(Instant{}-Instant{});
90 (implExpl==EXPLICITLY);
116 children.find(subName);
119 if(ref==children.end())
121 children.try_emplace(subName,subName,
this).first;
158 enum{UNSTOPPABLE,STOPPABLE};
186 takeTime()-lastMomentStarted;
189 lastMomentStopped-lastMomentStarted;
198 _cumulativeMeasure+currentMeasure();
209 cumulativeMeasure()/nMeasures;
221 if(hasRunningChildren())
222 MINIMAL_CRASH(
"Trying to stop stopwatch %s with %d running children",name,nStartedChildren);
240 const bool isStoppableFlag=STOPPABLE)
257 template <
typename U,
262 std::chrono::duration<O,U>(duration).count();
266 template <
typename O=
double>
270 std::chrono::duration<O>(duration).count();
276 template <
typename F,
288 f(forw<Args>(args)...);
300 template <
typename F,
302 Duration durationOf(F&& f,
308 duationOf(duration,forw<F>(f),forw<Args>(args)...);
#define MINIMAL_CRASH(...)
Initialize the minimal crasher.
bool hasRunningChildren() const
Checks if has running children.
double durationIn(const Duration &duration)
Convert duration into a units of measure.
auto durationOf(Duration &duration, F &&f, Args &&...args)
Returns the duration of executing a function.
void minimalCrash(const char *path, const int line, const char *funcName, const char *format,...)
const bool & isStarted() const
Returns whether the timer is started.
Duration cumulativeMeasure() const
Returns the total measured time, including current one if is running.
Duration _cumulativeMeasure
Cumulative time for which the timer has been let running.
Instant lastMomentStarted
Last moment the stopwatch was started.
Started
Started mode: was it started by a children or explicityly?
Timer & operator[](const char *subName)
Gets reference to the mapped sub timer.
decltype(auto) father(Ts &&...ts)
Timer * _father
Father of current timer.
bool isStartedFlag
Mark if the stopwatch is started.
void innerStart(const bool implExpl)
Common start.
bool hasChildren() const
Checks if has children.
bool isExplicitlyStarted
Determine whether it was explicitly started (or from a children)
void start()
Explicitly starts the stopwatch.
Duration averageMeasure() const
Average measure.
const char * name
Name of the timer.
void childrenStarted()
Starts through a children.
Timer(const char *name, Timer *father=nullptr, const bool isStoppableFlag=STOPPABLE)
Builds the stopwatch.
const Timer & father() const
Gets a reference to the father.
const bool isStoppable
Mark whether the stopwatch can be stopped.
#define PROVIDE_ALSO_NON_CONST_METHOD(NAME)
int nMeasures
Number of intervals measured.
double durationInSec(const Duration &duration)
Convert duration into seconds.
Timer timings("Total time", Timer::NO_FATHER, Timer::UNSTOPPABLE)
Global timings.
Instant takeTime()
Get current time.
Duration currentMeasure() const
Returns the last measured or the current one.
void stop()
Stop the stopwatch.