PostgreSQL Source Code  git master
resource.h File Reference
#include <sys/time.h>
Include dependency graph for resource.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rusage
 

Macros

#define RUSAGE_SELF   0
 
#define RUSAGE_CHILDREN   (-1)
 

Functions

int getrusage (int who, struct rusage *rusage)
 

Macro Definition Documentation

◆ RUSAGE_CHILDREN

#define RUSAGE_CHILDREN   (-1)

Definition at line 10 of file resource.h.

◆ RUSAGE_SELF

#define RUSAGE_SELF   0

Definition at line 9 of file resource.h.

Function Documentation

◆ getrusage()

int getrusage ( int  who,
struct rusage rusage 
)

Definition at line 21 of file win32getrusage.c.

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

References _dosmaperr(), rusage::ru_stime, rusage::ru_utime, and RUSAGE_SELF.

Referenced by pg_rusage_init(), ResetUsage(), and ShowUsage().