Skip to content

Commit

Permalink
Use RUSAGE_THREAD, if available
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
fio-prf authored and axboe committed Jan 24, 2013
1 parent 798827c commit 7732a09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,11 @@ static void *thread_main(void *data)
}

fio_gettime(&td->epoch, NULL);
#ifdef RUSAGE_THREAD
getrusage(RUSAGE_THREAD, &td->ru_start);
#else
getrusage(RUSAGE_SELF, &td->ru_start);

#endif
clear_state = 0;
while (keep_running(td)) {
uint64_t verify_bytes;
Expand Down
14 changes: 12 additions & 2 deletions os/windows/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,21 @@ int getrusage(int who, struct rusage *r_usage)
const uint64_t SECONDS_BETWEEN_1601_AND_1970 = 11644473600;
FILETIME cTime, eTime, kTime, uTime;
time_t time;
HANDLE h;

memset(r_usage, 0, sizeof(*r_usage));

HANDLE hProcess = GetCurrentProcess();
GetProcessTimes(hProcess, &cTime, &eTime, &kTime, &uTime);
if (who == RUSAGE_SELF) {
h = GetCurrentProcess();
GetProcessTimes(h, &cTime, &eTime, &kTime, &uTime);
} else if (who == RUSAGE_THREAD) {
h = GetCurrentThread();
GetThreadTimes(h, &cTime, &eTime, &kTime, &uTime);
} else {
log_err("fio: getrusage %d is not implemented\n", who);
return -1;
}

time = ((uint64_t)uTime.dwHighDateTime << 32) + uTime.dwLowDateTime;
/* Divide by 10,000,000 to get the number of seconds and move the epoch from
* 1601 to 1970 */
Expand Down
1 change: 1 addition & 0 deletions os/windows/posix/include/sys/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SYS_RESOURCE_H

#define RUSAGE_SELF 0
#define RUSAGE_THREAD 1

struct rusage
{
Expand Down

0 comments on commit 7732a09

Please sign in to comment.