vacuumlazy.c: Tweak local variable name.
[pgsql.git] / src / port / win32getrusage.c
blobce28b9ba6fea0de62cea8162638be8aa08c79c73
1 /*-------------------------------------------------------------------------
3 * win32getrusage.c
4 * get information about resource utilisation
6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * src/port/win32getrusage.c
13 *-------------------------------------------------------------------------
16 #include "c.h"
18 #include <sys/resource.h>
20 int
21 getrusage(int who, struct rusage *rusage)
23 FILETIME starttime;
24 FILETIME exittime;
25 FILETIME kerneltime;
26 FILETIME usertime;
27 ULARGE_INTEGER li;
29 if (who != RUSAGE_SELF)
31 /* Only RUSAGE_SELF is supported in this implementation for now */
32 errno = EINVAL;
33 return -1;
36 if (rusage == (struct rusage *) NULL)
38 errno = EFAULT;
39 return -1;
41 memset(rusage, 0, sizeof(struct rusage));
42 if (GetProcessTimes(GetCurrentProcess(),
43 &starttime, &exittime, &kerneltime, &usertime) == 0)
45 _dosmaperr(GetLastError());
46 return -1;
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;
60 return 0;