php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #61132
Patch xhprof__mach_timer_patch_rtc_v2.diff revision 2012-02-18 05:56 UTC by github at fabian-franz dot de

Patch xhprof__mach_timer_patch_rtc_v2.diff for xhprof Bug #61132

Patch version 2012-02-18 05:56 UTC

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

Developer: github@fabian-franz.de

--- xhprof.c.old	2012-02-18 06:37:32.000000000 +0100
+++ xhprof.c	2012-02-18 06:45:08.000000000 +0100
@@ -51,6 +51,8 @@
  */
 #    include <mach/mach_init.h>
 #    include <mach/thread_policy.h>
+#    include <mach/mach_time.h>
+
 #    define cpu_set_t thread_affinity_policy_data_t
 #    define CPU_SET(cpu_id, new_mask) \
         (*(new_mask)).affinity_tag = (cpu_id + 1)
@@ -1180,11 +1182,15 @@
  * @author cjiang
  */
 inline uint64 cycle_timer() {
+#ifndef __APPLE__
   uint32 __a,__d;
   uint64 val;
   asm volatile("rdtsc" : "=a" (__a), "=d" (__d));
   (val) = ((uint64)__a) | (((uint64)__d)<<32);
   return val;
+#else
+  return mach_absolute_time();
+#endif
 }
 
 /**
@@ -1266,6 +1272,7 @@
  * @author cjiang
  */
 static double get_cpu_frequency() {
+#ifndef __APPLE__
   struct timeval start;
   struct timeval end;
 
@@ -1283,6 +1290,12 @@
   }
   uint64 tsc_end = cycle_timer();
   return (tsc_end - tsc_start) * 1.0 / (get_us_interval(&start, &end));
+#else
+  mach_timebase_info_data_t sTimebaseInfo;
+  (void) mach_timebase_info(&sTimebaseInfo);
+
+  return (sTimebaseInfo.numer / sTimebaseInfo.denom) * 1000;
+#endif
 }
 
 /**
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC