1 #ifndef SimTK_SimTKCOMMON_TIMING_H_ 2 #define SimTK_SimTKCOMMON_TIMING_H_ 67 #if defined(__APPLE__) 68 #include <Availability.h> 86 #if defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101200 88 #define SimTK_IS_APPLE_AND_MUST_DECLARE_CLOCK_GETTIME 1 90 #define SimTK_IS_APPLE_AND_MUST_DECLARE_CLOCK_GETTIME 0 93 #if defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 95 #define SimTK_IS_APPLE_AND_MUST_DEFINE_CLOCK_GETTIME 1 97 #define SimTK_IS_APPLE_AND_MUST_DEFINE_CLOCK_GETTIME 0 102 #if defined(_MSC_VER) 118 typedef unsigned int useconds_t;
119 inline int usleep(useconds_t us) {
121 req.tv_sec = (long) (us / 1000000U);
122 req.tv_nsec = (long)((us % 1000000U)*1000U);
123 int status = nanosleep(&req,0);
124 return status ? -1 : 0;
128 #if defined(_MSC_VER) || SimTK_IS_APPLE_AND_MUST_DECLARE_CLOCK_GETTIME 130 typedef long clockid_t;
141 #define CLOCK_REALTIME 1 // time of day clock, from 1/1/1970 142 #define CLOCK_MONOTONIC 2 // counter from last boot time 143 #define CLOCK_MONOTONIC_HR 3 // "high resolution" (same) 144 #define CLOCK_MONOTONIC_RAW 4 // "not subject to NTP adjustments" (same) 145 #define CLOCK_THREAD_CPUTIME_ID 5 // current thread's cpu time (kernel+user) 146 #define CLOCK_PROCESS_CPUTIME_ID 6 // cumulative cpu time of all threads of 153 struct timespec *tp);
187 {
return (
long long)ts.tv_sec*1000000000LL + (
long long)ts.tv_nsec; }
192 { ts.tv_sec = (long)(ns / 1000000000LL);
193 if (ns >= 0) ts.tv_nsec = (long)( ns % 1000000000LL);
194 else ts.tv_nsec = -(long)((-ns) % 1000000000LL); }
230 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
241 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
275 #ifdef CLOCK_MONOTONIC_RAW 276 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
278 clock_gettime(CLOCK_MONOTONIC, &ts);
316 #endif // SimTK_SimTKCOMMON_TIMING_H_ #define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
long long secToNs(const double &s)
Given a signed time interval as a double precision floating point number of seconds, return the same time interval as a count of nanosecond ticks in a signed 64 bit integer.
Definition: Timing.h:205
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
double cpuTime()
Return the cumulative CPU time in seconds (both kernel and user time) that has been used so far by an...
Definition: Timing.h:228
void nsToTimespec(const long long &ns, timespec &ts)
Given a signed number of nanoseconds, convert that into seconds and leftover nanoseconds in a timespe...
Definition: Timing.h:191
double realTime()
Return current time on the high-resolution interval timer in seconds.
Definition: Timing.h:290
void sleepInNs(const long long &ns)
Sleep for the indicated number of nanoseconds, with the actual precision system dependent but intende...
Definition: Timing.h:299
long long timespecToNs(const timespec &ts)
Convert a time stored in a timespec struct to the equivalent number of nanoseconds (as a signed quant...
Definition: Timing.h:186
High precision mathematical and physical constants.
void sleepInSec(const double &seconds)
Sleep for the indicated number of seconds, with the actual precision system dependent but intended to...
Definition: Timing.h:311
double nsToSec(const long long &ns)
Given a count of nanosecond ticks as a signed 64 bit integer, return the same time interval as a doub...
Definition: Timing.h:199
Mandatory first inclusion for any Simbody source or header file.
#define SimTK_NS_TO_S
Convert nanoseconds to seconds.
Definition: Constants.h:527
#define SimTK_S_TO_NS
Convert seconds to nanoseconds.
Definition: Constants.h:535
double threadCpuTime()
Return the total CPU time in seconds (both kernel and user time) that has been used so far by the cur...
Definition: Timing.h:239
long long realTimeInNs()
Return current time on the high-resolution interval timer in nanoseconds, as a 64-bit integer count...
Definition: Timing.h:273