This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Getrusage update


The attached patch, (I know, the Changelog should be in the body, but as Evolution just died on me (oh, for a release of libgal that doesn't change weekly!) I'm in a non-normal mailing mode here) fills in the ru_maxrss and ru_majflt fields for getrusage. This was reported to me by Guido Serassio who is porting squid to native win32 code and was patching squid...

Anyway, the patch is straightforward, with one kink: The already used function GetProcessTimes is documented by MSDN as being NT only, but it's not in the autoload.cc file. I wasn't sure what to do with my new call, GetProcessMemoryInfo therefore, so I erred on the side of caution.

If possible, I'd love to see this in 1.3.4. 

And lastly, I haven't done massive testing on it yet.

Rob
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/ChangeLog,v
retrieving revision 1.970
diff -u -p -r1.970 ChangeLog
--- ChangeLog	2001/10/21 03:38:41	1.970
+++ ChangeLog	2001/10/21 14:53:33
@@ -1,3 +1,10 @@
+2001-10-22  Robert Collins  <rbtcollins@hotmail.com>
+
+	* autoload.cc: Autoload GetProcessMemoryInfo.
+	* resource.cc (fill_rusage): Calculate ru_maxrss and ru_majflt entries. 
+	(Bug report on this from Guido Serassio in the squid project).
+	This requires including psapi.h.
+
 2001-10-20  Christopher Faylor  <cgf@redhat.com>
 
 	* dll_init.cc (dll_list::alloc): Increase retry count to 1000.
Index: autoload.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/autoload.cc,v
retrieving revision 1.36
diff -u -p -r1.36 autoload.cc
--- autoload.cc	2001/10/16 14:53:26	1.36
+++ autoload.cc	2001/10/21 14:53:34
@@ -381,6 +381,8 @@ LoadDLLfuncEx (RtlInitUnicodeString, 8, 
 LoadDLLfuncEx (RtlNtStatusToDosError, 4, ntdll, 1)
 LoadDLLfuncEx (ZwQuerySystemInformation, 16, ntdll, 1)
 
+LoadDLLfunc (GetProcessMemoryInfo, 12, psapi)
+
 LoadDLLfuncEx (LsaDeregisterLogonProcess, 4, secur32, 1)
 LoadDLLfuncEx (LsaFreeReturnBuffer, 4, secur32, 1)
 LoadDLLfuncEx (LsaLogonUser, 56, secur32, 1)
Index: resource.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/resource.cc,v
retrieving revision 1.16
diff -u -p -r1.16 resource.cc
--- resource.cc	2001/09/11 20:01:00	1.16
+++ resource.cc	2001/10/21 14:53:34
@@ -20,6 +20,7 @@ details. */
 #include "sync.h"
 #include "sigproc.h"
 #include "pinfo.h"
+#include "psapi.h"
 
 /* add timeval values */
 static void
@@ -73,6 +74,14 @@ fill_rusage (struct rusage *r, HANDLE h)
   add_timeval (&r->ru_stime, &tv);
   totimeval (&tv, &user_time, 0, 0);
   add_timeval (&r->ru_utime, &tv);
+
+  PROCESS_MEMORY_COUNTERS pmc;
+  
+  if (wincap.is_winnt() && GetProcessMemoryInfo( h, &pmc, sizeof(pmc)) )
+    {
+      r->ru_maxrss += (long)(pmc.WorkingSetSize /1024);
+      r->ru_majflt += pmc.PageFaultCount;
+    }
 }
 
 extern "C"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]