[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
getrusage for MinGW
From: |
John W. Eaton |
Subject: |
getrusage for MinGW |
Date: |
Tue, 21 Mar 2006 11:06:33 -0500 |
On 21-Mar-2006, David Bateman wrote:
| The getrusage and therefore the cputime function don't work under MinGW
| as MinGW lacks both the getrusage and times functions. It however has
| the GetProcessTimes windows API function. Could the following patch be
| considered to allow MinGW to use at least the user and system times of
| the getrusage function and therefore have the cputime function work
| correctly?
| *** ./src/DLD-FUNCTIONS/getrusage.cc.orig2 2006-03-21 16:38:49.486021589
+0100
| --- ./src/DLD-FUNCTIONS/getrusage.cc 2006-03-21 16:39:16.063621581 +0100
| ***************
| *** 191,196 ****
| --- 191,210 ----
| tv_tmp.assign ("usec", static_cast<double> (fraction * 1e6 / HZ));
| m.assign ("stime", octave_value (tv_tmp));
|
| + #elif defined (__MINGW32__)
| + HANDLE hProcess = GetCurrentProcess ();
| + FILETIME ftCreation, ftExit, ftUser, ftKernel;
| + GetProcessTimes (hProcess, &ftCreation, &ftExit, &ftKernel, &ftUser);
| +
| + EIGHT_BYTE_INT itmp = *(reinterpret_cast<EIGHT_BYTE_INT *> (&ftUser));
| + tv_tmp.assign ("sec", static_cast<double> (itmp / 10000000U));
| + tv_tmp.assign ("usec", static_cast<double> (itmp % 10000000U) / 10.);
| + m.assign ("utime", octave_value (tv_tmp));
| +
| + itmp = *(reinterpret_cast<EIGHT_BYTE_INT *> (&ftKernel));
| + tv_tmp.assign ("sec", static_cast<double> (itmp / 10000000U));
| + tv_tmp.assign ("usec", static_cast<double> (itmp % 10000000U) / 10.);
| + m.assign ("stime", octave_value (tv_tmp));
| #else
|
| tv_tmp.assign ("sec", 0);
I would prefer that system-dependent code be place in a function
somewhere else, like sysdep.cc (so perhaps the other code that is
already there needs to be hidden away as well).
Also, is FILETIME always required to be an integer data type? If so,
why do you need to cast the pointer value? Why can't you simply write
tv_tmp.assign ("sec", static_cast<double> (ftKernel / 10000000U));
? If FILETIME is not required to be an integer data type (maybe it
could be defined as a pointer to some array or structure) then casting
the pointer is likely to cause trouble anyway, isn't it?
Finally, what file that is included by getrusage.cc gives you the
definitions of HANDLE and FILETIME?
jwe