4 #include <sys/resource.h>
8 #include <msp/core/systemerror.h>
10 #include "rawtime_private.h"
11 #include "timedelta.h"
12 #include "timestamp.h"
26 return TimeStamp(timeval_to_rawtime(tv));
29 GetSystemTimeAsFileTime(&ft);
30 return TimeStamp(filetime_to_rawtime(ft));
34 string format_now(const string &fmt)
36 return DateTime(now()).format(fmt);
39 TimeDelta get_cpu_time()
43 getrusage(RUSAGE_SELF, &ru);
44 return (ru.ru_utime.tv_sec+ru.ru_stime.tv_sec)*sec + (ru.ru_utime.tv_usec+ru.ru_stime.tv_usec)*usec;
46 //XXX Figure out the function to use on Win32
51 void sleep(const TimeDelta &d)
54 timespec ts = rawtime_to_timespec(d.raw());
55 while(nanosleep(&ts, 0)==-1)
57 throw system_error("nanosleep");
59 Sleep((DWORD)(d/msec));