31#include <IceUtil/Time.h>
33#include <ArmarXCore/interface/core/TimeServerInterface.h>
72#ifndef BOOST_NO_CXX11_HDR_CHRONO
73#define GENERATE_TIME_OPERATOR_COMP(op) \
74 template <class Rep, class Period> \
75 inline bool operator op(IceUtil::Time a, std::chrono::duration<Rep, Period> b) \
77 return a.toMicroSeconds() op std::chrono::duration_cast<std::chrono::microseconds>(b) \
80 template <class Rep, class Period> \
81 inline bool operator op(std::chrono::duration<Rep, Period> a, IceUtil::Time b) \
83 return std::chrono::duration_cast<std::chrono::microseconds>(a).count() \
84 op b.toMicroSeconds(); \
92#undef GENERATE_TIME_OPERATOR_COMP
93#define GENERATE_TIME_OPERATORS_ARITH(op) \
94 template <class Rep, class Period> \
95 inline IceUtil::Time operator op(IceUtil::Time a, std::chrono::duration<Rep, Period> b) \
97 return a op IceUtil::Time::microSeconds( \
98 std::chrono::duration_cast<std::chrono::microseconds>(b).count()); \
100 template <class Rep, class Period> \
101 inline IceUtil::Time operator op(std::chrono::duration<Rep, Period> a, IceUtil::Time b) \
103 return IceUtil::Time::microSeconds( \
104 std::chrono::duration_cast<std::chrono::microseconds>(a).count()) op b; \
110#undef GENERATE_TIME_OPERATORS_ARITH
114 class LocalTimeServer;
153 static IceUtil::Time
GetTime(
bool forceSystemTime);
161 static IceUtil::Time
GetTimeSince(IceUtil::Time referenceTime,
172 static IceUtil::Time
GetTimeSince(IceUtil::Time referenceTime,
bool forceSystemTime);
180 static void Sleep(IceUtil::Time duration);
188 template <
class Rep,
class Period>
190 Sleep(std::chrono::duration<Rep, Period> d)
192 Sleep(IceUtil::Time::microSeconds(
193 std::chrono::duration_cast<std::chrono::microseconds>(d).count()));
199 Sleep(IceUtil::Time::microSeconds(
int(1000000 * seconds)));
205 Sleep(IceUtil::Time::microSeconds(
int(1000 * milliseconds)));
211 Sleep(IceUtil::Time::microSeconds(
int(microseconds)));
218 static void MSSleep(
int durationMS);
251 static int USleep(
long usec);
260 static std::string
toStringDate(
const IceUtil::Time& time);
263 static std::string
toStringTime(
const IceUtil::Time& time);
289#define TIMING_START(name) auto name = IceUtil::Time::now();
293#define TIMING_END_COMMENT_STREAM(name, comment, os) \
295 name = (IceUtil::Time::now() - name); \
296 os << deactivateSpam(1, comment) << comment \
297 << " - duration: " << name.toMilliSecondsDouble() << " ms"; \
302#define TIMING_END_COMMENT(name, comment) TIMING_END_COMMENT_STREAM(name, comment, ARMARX_INFO)
306#define TIMING_END(name) TIMING_END_COMMENT(name, #name)
310#define TIMING_END_STREAM(name, os) TIMING_END_COMMENT_STREAM(name, #name, os)
315#define TIMING_CEND_COMMENT(name, comment, thresholdMs) \
316 if ((IceUtil::Time::now() - name).toMilliSecondsDouble() >= thresholdMs) \
317 TIMING_END_COMMENT(name, comment)
321#define TIMING_CEND(name, thresholdMs) TIMING_CEND_COMMENT(name, #name, thresholdMs)
#define GENERATE_TIME_OPERATORS_ARITH(op)
#define GENERATE_TIME_OPERATOR_COMP(op)
static LocalTimeServerPtr GetTimeServer()
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
static void SetTimeServer(LocalTimeServerPtr ts)
static std::string toStringDate(const IceUtil::Time &time)
Return a date string like "2020-01-31" (Y-M-D).
static IceUtil::Time GetTimeSince(IceUtil::Time referenceTime, TimeMode timeMode=TimeMode::VirtualTime)
Get the difference between the current time and a reference time.
static std::string toStringTime(const IceUtil::Time &time)
Return a time string like "15-30-05" (H-M-S).
static void Sleep(float seconds)
static void Sleep(std::chrono::duration< Rep, Period > d)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
static void WaitForNextTick()
block until the next tick of the timeserver.
static std::string toStringDateTime(const IceUtil::Time &time)
Return a date & time string like "2020-01-31_15-30-05" (Y-M-D_H-M-S).
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
static int NanoSleep(long usec)
Nanosleep convenience function.
static void SleepUS(float microseconds)
static LocalTimeServerPtr timeServerPtr
pointer to the applications LocalTimeServer if NULL, system time is used
static int USleep(long usec)
like timed_wait on boost condition_variables, but with timeserver support
static void Sleep(IceUtil::Time duration)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
static bool HasTimeServer()
check if we have been initialized with a Timeserver
static void SleepMS(float milliseconds)
TimeMode
Time mode to be used.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< LocalTimeServer > LocalTimeServerPtr