1 /*-------------------------------------------------------------------------
4 * get information about resource utilisation
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/port/win32getrusage.c
13 *-------------------------------------------------------------------------
18 #include <sys/resource.h>
21 getrusage(int who
, struct rusage
*rusage
)
29 if (who
!= RUSAGE_SELF
)
31 /* Only RUSAGE_SELF is supported in this implementation for now */
36 if (rusage
== (struct rusage
*) NULL
)
41 memset(rusage
, 0, sizeof(struct rusage
));
42 if (GetProcessTimes(GetCurrentProcess(),
43 &starttime
, &exittime
, &kerneltime
, &usertime
) == 0)
45 _dosmaperr(GetLastError());
49 /* Convert FILETIMEs (0.1 us) to struct timeval */
50 memcpy(&li
, &kerneltime
, sizeof(FILETIME
));
51 li
.QuadPart
/= 10L; /* Convert to microseconds */
52 rusage
->ru_stime
.tv_sec
= li
.QuadPart
/ 1000000L;
53 rusage
->ru_stime
.tv_usec
= li
.QuadPart
% 1000000L;
55 memcpy(&li
, &usertime
, sizeof(FILETIME
));
56 li
.QuadPart
/= 10L; /* Convert to microseconds */
57 rusage
->ru_utime
.tv_sec
= li
.QuadPart
/ 1000000L;
58 rusage
->ru_utime
.tv_usec
= li
.QuadPart
% 1000000L;