4 #include <sys/resource.h>
8 #include <msp/core/systemerror.h>
10 #include "timedelta.h"
11 #include "timestamp.h"
21 Returns the current timestamp.
28 return TimeStamp(tv.tv_sec*1000000LL+tv.tv_usec);
30 static RawTime epoch = 0;
43 SystemTimeToFileTime(&st, &ft);
44 epoch = (ft.dwLowDateTime+(static_cast<RawTime>(ft.dwHighDateTime)<<32))/10;
48 GetSystemTimeAsFileTime(&ft);
49 return TimeStamp((ft.dwLowDateTime+(static_cast<RawTime>(ft.dwHighDateTime)<<32))/10-epoch);
53 string format_now(const string &fmt)
55 return DateTime(now()).format(fmt);
59 Returns the CPU time used by the program so far.
61 TimeDelta get_cpu_time()
65 getrusage(RUSAGE_SELF, &ru);
66 return (ru.ru_utime.tv_sec+ru.ru_stime.tv_sec)*sec + (ru.ru_utime.tv_usec+ru.ru_stime.tv_usec)*usec;
68 //XXX Figure out the function to use on Win32
74 Sleeps for the given time.
76 void sleep(const TimeDelta &d)
80 while(nanosleep(&ts, 0)==-1)
82 throw system_error("nanosleep");
84 Sleep((DWORD)(d/msec));