4 #include <sys/resource.h>
8 #include <msp/core/systemerror.h>
10 #include "rawtime_private.h"
11 #include "timedelta.h"
12 #include "timestamp.h"
25 return TimeStamp(timeval_to_rawtime(tv));
28 GetSystemTimeAsFileTime(&ft);
29 return TimeStamp(filetime_to_rawtime(ft));
33 string format_now(const string &fmt)
35 return DateTime(now()).format(fmt);
38 TimeDelta get_cpu_time()
42 getrusage(RUSAGE_SELF, &ru);
43 return (ru.ru_utime.tv_sec+ru.ru_stime.tv_sec)*sec + (ru.ru_utime.tv_usec+ru.ru_stime.tv_usec)*usec;
45 //XXX Figure out the function to use on Win32
50 void sleep(const TimeDelta &d)
53 timespec ts = rawtime_to_timespec(d.raw());
54 while(nanosleep(&ts, 0)==-1)
56 throw system_error("nanosleep");
58 Sleep((DWORD)(d/msec));