octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getrusage for MinGW


From: David Bateman
Subject: getrusage for MinGW
Date: Tue, 21 Mar 2006 16:45:15 +0100
User-agent: Mozilla Thunderbird 1.0.6-7.5.20060mdk (X11/20050322)

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?

Regards
David

-- 
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

*** ./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);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]