Skip to content

Commit

Permalink
fix 24h wraparound in time reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Felix committed Jan 10, 2020
1 parent 165a94b commit eab6ed3
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/pal-win/unistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,14 @@ int getrusage(int who, struct rusage* usage)
if (GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &kernelTime, &userTime) == -1)
return -1;

SYSTEMTIME userSystemTime;
if (FileTimeToSystemTime(&userTime, &userSystemTime) == -1)
return -1;

SYSTEMTIME kernelSystemTime;
if (FileTimeToSystemTime(&kernelTime, &kernelSystemTime) == -1)
return -1;
uint64_t userT64=(userTime.dwHighDateTime << 32) | userTime.dwLowDateTime;
uint64_t kernelT64 = (kernelTime.dwHighDateTime << 32) | kernelTime.dwLowDateTime;

usage->ru_utime.tv_sec = userSystemTime.wHour*3600+
userSystemTime.wMinute*60+
userSystemTime.wSecond;
usage->ru_utime.tv_usec = userSystemTime.wMilliseconds * 1000;
usage->ru_utime.tv_sec = userT64 / 10 / 1000 / 1000;
usage->ru_utime.tv_usec = (userT64 / 10) % (1000*1000);

usage->ru_stime.tv_sec = kernelSystemTime.wHour * 3600 +
kernelSystemTime.wMinute * 60 +
kernelSystemTime.wSecond;
usage->ru_stime.tv_usec = kernelSystemTime.wMilliseconds * 1000;
usage->ru_stime.tv_sec = kernelT64 / 10 / 1000 / 1000;
usage->ru_stime.tv_usec = (kernelT64 / 10) % (1000 * 1000);

PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
Expand Down

0 comments on commit eab6ed3

Please sign in to comment.