wrowe 2002/08/04 11:29:33
Modified: include apr_time.h
time/unix time.c
time/win32 time.c
Log:
Time in exact ms intervals can be very useful in benchmarking... this
patch defines a general API for doing so if the platform supports
toggling the clock resolution. Don't recommend doing so for HTTPD,
but flood and ab should appreciate it.
Revision Changes Path
1.56 +8 -0 apr/include/apr_time.h
Index: apr_time.h
===================================================================
RCS file: /home/cvs/apr/include/apr_time.h,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- apr_time.h 15 Jul 2002 06:43:34 -0000 1.55
+++ apr_time.h 4 Aug 2002 18:29:33 -0000 1.56
@@ -256,6 +256,14 @@
apr_size_t max, const char *format,
apr_time_exp_t *tm);
+/**
+ * Improve the clock resolution for the lifetime of the given pool.
+ * Generally this is only desireable on benchmarking and other very
+ * time-sensitive applications, and has no impact on most platforms.
+ * @param pool The pool to associate the finer clock resolution
+ */
+APR_DECLARE(void) apr_time_clock_hires(apr_pool_t *p);
+
#ifdef __cplusplus
}
#endif
1.70 +6 -0 apr/time/unix/time.c
Index: time.c
===================================================================
RCS file: /home/cvs/apr/time/unix/time.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- time.c 8 Jun 2002 20:04:26 -0000 1.69
+++ time.c 4 Aug 2002 18:29:33 -0000 1.70
@@ -364,6 +364,12 @@
#endif
+/* A noop on all known Unix implementations */
+APR_DECLARE(void) apr_time_clock_hires(apr_pool_t *p)
+{
+ return;
+}
+
/* Deprecated */
APR_DECLARE(apr_status_t) apr_explode_time(apr_time_exp_t *result,
apr_time_t input,
1.36 +20 -0 apr/time/win32/time.c
Index: time.c
===================================================================
RCS file: /home/cvs/apr/time/win32/time.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- time.c 9 Jun 2002 20:25:51 -0000 1.35
+++ time.c 4 Aug 2002 18:29:33 -0000 1.36
@@ -65,6 +65,7 @@
#endif
#include <string.h>
#include <winbase.h>
+#include "misc.h"
/* Leap year is any year divisible by four, but not by 100 unless also
* divisible by 400
@@ -281,6 +282,25 @@
*/
Sleep((DWORD)(t / 1000));
}
+
+
+static apr_status_t clock_restore(void *unsetres)
+{
+ ULONG newRes;
+ SetTimerResolution((ULONG)unsetres, FALSE, &newRes);
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(void) apr_time_clock_hires(apr_pool_t *p)
+{
+ ULONG newRes;
+ if (SetTimerResolution(10000, TRUE, &newRes) == 0 /* STATUS_SUCCESS */) {
+ /* register the cleanup... */
+ apr_pool_cleanup_register(p, (void*)10000, clock_restore,
+ apr_pool_cleanup_null);
+ }
+}
+
/* Deprecated */
APR_DECLARE(apr_status_t) apr_explode_time(apr_time_exp_t *result,