[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getrusage for MinGW
From: |
David Bateman |
Subject: |
Re: getrusage for MinGW |
Date: |
Tue, 21 Mar 2006 17:14:57 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.6-7.5.20060mdk (X11/20050322) |
John W. Eaton wrote:
>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).
>
>
Yes I know. The other alternative is to replace the "#if defined
(__MINGW32__)" with "#if defined (HAVE_GETPROCESSTIMES)" and add a test
for GetProcessTimes to configure.in. I'd prefer this to moving the code
to sysdep.cc as I believe that would make the code less readable. The
reason I used __MINGW32__ was to avoid having to reconfigure for a rapid
patch. If you accept the patch, I'll try and update configure.in tonight..
>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?
>
>
No this cast is needed, and is suggested on the Microsoft website.
Though they use C style casts. With the code as you suggest I get
getrusage2.cc:204: error: no match for 'operator/' in 'ftUser / 10000000u'
As for the cast to a pointer, this is also suggested by Microsoft and
without it I get an illegal cast.
>Finally, what file that is included by getrusage.cc gives you the
>definitions of HANDLE and FILETIME?
>
>
Oh, damn!!! Yes I cut and paste between a linux emacs and vmware/windows
emacs, and forgot to copy the #include.. Its in windows.h.
>jwe
>
>
>
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary