php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch xhprof-rdtsc-busy-loop for xhprof Bug #64165

Patch version 2013-02-06 23:35 UTC

Return to Bug #64165 | Download this patch
Patch Revisions:

Developer: tstarling

diff --git a/extension/xhprof.c b/extension/xhprof.c
index a053ede..e656059 100644
--- a/extension/xhprof.c
+++ b/extension/xhprof.c
@@ -1313,14 +1313,18 @@ static double get_cpu_frequency() {
     return 0.0;
   }
   uint64 tsc_start = cycle_timer();
-  /* Sleep for 5 miliseconds. Comparaing with gettimeofday's  few microseconds
-   * execution time, this should be enough. */
-  usleep(5000);
-  if (gettimeofday(&end, 0)) {
-    perror("gettimeofday");
-    return 0.0;
-  }
-  uint64 tsc_end = cycle_timer();
+  uint64 tsc_end;
+  volatile int i;
+  /* Busy loop for 5 miliseconds. */
+  do {
+    for (i = 0; i < 1000000; i++);
+    if (gettimeofday(&end, 0)) {
+      perror("gettimeofday");
+      return 0.0;
+    }
+    tsc_end = cycle_timer();
+  } while (get_us_interval(&start, &end) < 5000);
+
   return (tsc_end - tsc_start) * 1.0 / (get_us_interval(&start, &end));
 }
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 13:01:28 2024 UTC