|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/port/getrusage.c,v 1.6 2004/08/29 04:13:12 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/port/getrusage.c,v 1.7 2004/09/02 17:55:16 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
|
26 | 26 | *solaris_sparc
|
27 | 27 | *svr4
|
28 | 28 | *hpux 9.*
|
| 29 | + *win32 |
29 | 30 | * which currently is all the supported platforms that don't have a
|
30 | 31 | * native version of getrusage(). So, if configure decides to compile
|
31 | 32 | * this file at all, we just use this version unconditionally.
|
|
35 | 36 | getrusage(intwho,structrusage*rusage)
|
36 | 37 | {
|
37 | 38 | #ifdefWIN32
|
38 |
| -if (rusage) |
39 |
| -memset(rusage,0,sizeof(rusage)); |
40 |
| -#else |
| 39 | + |
| 40 | +FILETIMEstarttime; |
| 41 | +FILETIMEexittime; |
| 42 | +FILETIMEkerneltime; |
| 43 | +FILETIMEusertime; |
| 44 | +ULARGE_INTEGERli; |
| 45 | + |
| 46 | +if (rusage== (structrusage*)NULL) |
| 47 | +{ |
| 48 | +errno=EFAULT; |
| 49 | +return-1; |
| 50 | +} |
| 51 | +memset(rusage,0,sizeof(structrusage)); |
| 52 | +if (GetProcessTimes(GetCurrentProcess(), |
| 53 | +&starttime,&exittime,&kerneltime,&usertime)==0) |
| 54 | +{ |
| 55 | +_dosmaperr(GetLastError()); |
| 56 | +return-1; |
| 57 | +} |
| 58 | + |
| 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; |
| 64 | + |
| 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; |
| 69 | + |
| 70 | +#else/* all but WIN32 */ |
| 71 | + |
41 | 72 | structtmstms;
|
42 | 73 | inttick_rate=CLK_TCK;/* ticks per second */
|
43 | 74 | clock_tu,
|
@@ -73,6 +104,8 @@ getrusage(int who, struct rusage * rusage)
|
73 | 104 | rusage->ru_utime.tv_usec=TICK_TO_USEC(u,tick_rate);
|
74 | 105 | rusage->ru_stime.tv_sec=TICK_TO_SEC(s,tick_rate);
|
75 | 106 | rusage->ru_stime.tv_usec=TICK_TO_USEC(u,tick_rate);
|
76 |
| -#endif |
| 107 | + |
| 108 | +#endif/* WIN32 */ |
| 109 | + |
77 | 110 | return0;
|
78 | 111 | }
|