Use RUSAGE_THREAD, if available
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/backend.c b/backend.c
index e025dbf..2362123 100644
--- a/backend.c
+++ b/backend.c
@@ -1210,8 +1210,11 @@
}
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;
diff --git a/os/windows/posix.c b/os/windows/posix.c
index 67e71c8..05fa5a9 100755
--- a/os/windows/posix.c
+++ b/os/windows/posix.c
@@ -547,11 +547,21 @@
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 */
diff --git a/os/windows/posix/include/sys/resource.h b/os/windows/posix/include/sys/resource.h
index 837d657..fd46b28 100644
--- a/os/windows/posix/include/sys/resource.h
+++ b/os/windows/posix/include/sys/resource.h
@@ -2,6 +2,7 @@
#define SYS_RESOURCE_H
#define RUSAGE_SELF 0
+#define RUSAGE_THREAD 1
struct rusage
{