PostgreSQL Source Code git master
win32getrusage.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * win32getrusage.c
4 * get information about resource utilisation
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/port/win32getrusage.c
12 *
13 *-------------------------------------------------------------------------
14 */
15
16#include "c.h"
17
18#include <sys/resource.h>
19
20int
21getrusage(int who, struct rusage *rusage)
22{
23 FILETIME starttime;
24 FILETIME exittime;
25 FILETIME kerneltime;
26 FILETIME usertime;
27 ULARGE_INTEGER li;
28
29 if (who != RUSAGE_SELF)
30 {
31 /* Only RUSAGE_SELF is supported in this implementation for now */
32 errno = EINVAL;
33 return -1;
34 }
35
36 if (rusage == (struct rusage *) NULL)
37 {
38 errno = EFAULT;
39 return -1;
40 }
41 memset(rusage, 0, sizeof(struct rusage));
42 if (GetProcessTimes(GetCurrentProcess(),
43 &starttime, &exittime, &kerneltime, &usertime) == 0)
44 {
45 _dosmaperr(GetLastError());
46 return -1;
47 }
48
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;
54
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;
59
60 return 0;
61}
#define RUSAGE_SELF
Definition: resource.h:9
struct timeval ru_utime
Definition: resource.h:14
struct timeval ru_stime
Definition: resource.h:15
void _dosmaperr(unsigned long)
Definition: win32error.c:177
int getrusage(int who, struct rusage *rusage)