[m-dev.] diff: enable timing with Win32

Peter Ross petdr at cs.mu.OZ.AU
Tue Jul 4 22:23:00 AEST 2000


Hi,


===================================================================


Estimated hours taken: 1

Enable MR_get_user_cpu_miliseconds under Win32.

runtime/mercury_conf_param.h:
    Define MR_WIN32_GETPROCESSTIMES if Win32 API is available.
    
runtime/mercury_timing.c:
    If MR_WIN32_GETPROCESSTIMES is defined, use GetProcessTimes() to
    define MR_get_user_cpu_miliseconds().


Index: mercury_conf_param.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.37
diff -u -r1.37 mercury_conf_param.h
--- mercury_conf_param.h	2000/06/29 09:55:36	1.37
+++ mercury_conf_param.h	2000/07/04 12:18:39
@@ -387,6 +387,7 @@
   #define MR_WIN32
   #define MR_WIN32_GETSYSTEMINFO
   #define MR_WIN32_VIRTUAL_ALLOC
+  #define MR_WIN32_GETPROCESSTIMES
 #endif
 
 /*---------------------------------------------------------------------------*/
Index: mercury_timing.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_timing.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_timing.c
--- mercury_timing.c	2000/06/08 07:59:06	1.3
+++ mercury_timing.c	2000/07/04 12:18:39
@@ -17,13 +17,41 @@
   #include <sys/times.h>		/* for times() and `struct tms' */
 #endif
 
+#ifdef MR_WIN32_GETPROCESSTIMES
+  #include <windows.h>
+#endif
+
 #include "mercury_timing.h"
 
 int
 MR_get_user_cpu_miliseconds(void)
 {
 #ifndef MR_CLOCK_TICKS_PER_SECOND
+  #ifdef MR_WIN32_GETPROCESSTIMES
+    #define FILETIME_TO_MILLISEC(ST, Msec)				\
+	do								\
+	{								\
+	  SYSTEMTIME tmp;						\
+	  FileTimeToSystemTime(&ST, &tmp);				\
+	  Msec = tmp.wMilliseconds +					\
+	    1000 * (tmp.wSecond + 60 * (tmp.wMinute + 60 * tmp.wHour));	\
+	} while(0)
+
+	FILETIME CreationTime;
+	FILETIME ExitTime;
+	FILETIME KernelTime;
+	FILETIME UserTime;
+	int UserMsec, KernelMsec;
+	
+	GetProcessTimes(GetCurrentProcess(),
+					&CreationTime, &ExitTime,
+					&KernelTime, &UserTime);
+	FILETIME_TO_MILLISEC(UserTime, UserMsec);
+	FILETIME_TO_MILLISEC(KernelTime, KernelMsec);
+	return UserMsec + KernelMsec;
+  #else
 	return -1;
+  #endif
 #else
 	const double ticks_per_milisecond = MR_CLOCK_TICKS_PER_SECOND / 1000.0;
 	struct tms t;

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list