[svn:parrot] r40843 - branches/pluggable_runcore/config/gen/platform/win32

cotto at svn.parrot.org cotto at svn.parrot.org
Fri Aug 28 20:19:25 UTC 2009


Author: cotto
Date: Fri Aug 28 20:19:22 2009
New Revision: 40843
URL: https://trac.parrot.org/parrot/changeset/40843

Log:
[profiling] Switch to QueryPerformanceCounter for high-resolution timing info on win32.
GetProcessTimes would be ideal because it won't record time spent by other processes, but it's goofy and this isn't.

Modified:
   branches/pluggable_runcore/config/gen/platform/win32/hires_timer.c

Modified: branches/pluggable_runcore/config/gen/platform/win32/hires_timer.c
==============================================================================
--- branches/pluggable_runcore/config/gen/platform/win32/hires_timer.c	Fri Aug 28 19:35:23 2009	(r40842)
+++ branches/pluggable_runcore/config/gen/platform/win32/hires_timer.c	Fri Aug 28 20:19:22 2009	(r40843)
@@ -17,15 +17,6 @@
 
 =over 4
 
-=cut
-
-*/
-
-
-#define TIME_IN_NS(n) ((n).dwHighDateTime * 2^32 + (n).dwLowDateTime)
-
-/*
-
 =item C<UHUGEINTVAL Parrot_hires_get_time()>
 
 Return a high-resolution number representing how long Parrot has been running.
@@ -36,16 +27,16 @@
 
 UHUGEINTVAL Parrot_hires_get_time()
 {
-    FILETIME creation, exit, kernel, user;
-    GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user);
-    return TIME_IN_NS(kernel) + TIME_IN_NS(user);
+    LARGE_INTEGER ticks;
+    QueryPerformanceCounter(&ticks);
+    return (UHUGEINTVAL) ticks.QuadPart;
 }
 
 /*
 
 =item C<UINTVAL Parrot_hires_get_resolution()>
 
-Return the number of ns that each time unit from Parrot_hires_get_time represents.
+Return the number of nanoseconds that each time unit from Parrot_hires_get_time represents.
 
 =cut
 
@@ -53,7 +44,11 @@
 
 UINTVAL Parrot_hires_get_resolution()
 {
-    return 100;
+    LARGE_INTEGER ticks;
+    /* QueryPerformanceCounter returns ticks per second, so divide 1 billion by
+     * that to find the length of each tick */
+    QueryPerformanceFrequency(&ticks);
+    return (UINTVAL) (1000*1000*1000 / ticks.QuadPart );
 }
 
 


More information about the parrot-commits mailing list