1
/*-------------------------------------------------------------------------
4
* 64-bit versions of fseeko/ftello()
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/port/getrusage.c,v 1.8 2004-12-31 22:03:53 pgsql Exp $
13
*-------------------------------------------------------------------------
20
#include "rusagestub.h"
22
/* This code works on:
30
* which currently is all the supported platforms that don't have a
31
* native version of getrusage(). So, if configure decides to compile
32
* this file at all, we just use this version unconditionally.
36
getrusage(int who, struct rusage * rusage)
46
if (rusage == (struct rusage *)NULL)
51
memset(rusage, 0, sizeof(struct rusage));
52
if (GetProcessTimes(GetCurrentProcess(),
53
&starttime, &exittime, &kerneltime, &usertime) == 0)
55
_dosmaperr(GetLastError());
59
/* Convert FILETIMEs (0.1 us) to struct timeval */
60
memcpy(&li, &kerneltime, sizeof(FILETIME));
61
li.QuadPart /= 10L; /* Convert to microseconds */
62
rusage->ru_stime.tv_sec = li.QuadPart / 1000000L;
63
rusage->ru_stime.tv_usec = li.QuadPart % 1000000L;
65
memcpy(&li, &usertime, sizeof(FILETIME));
66
li.QuadPart /= 10L; /* Convert to microseconds */
67
rusage->ru_utime.tv_sec = li.QuadPart / 1000000L;
68
rusage->ru_utime.tv_usec = li.QuadPart % 1000000L;
70
#else /* all but WIN32 */
73
int tick_rate = CLK_TCK; /* ticks per second */
77
if (rusage == (struct rusage *) NULL)
84
/* errno set by times */
101
#define TICK_TO_SEC(T, RATE) ((T)/(RATE))
102
#define TICK_TO_USEC(T,RATE) (((T)%(RATE)*1000000)/RATE)
103
rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate);
104
rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
105
rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
106
rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);