diff --git a/extension/php_xhprof.h b/extension/php_xhprof.h index 88fd59b8..c21aea7b 100755 --- a/extension/php_xhprof.h +++ b/extension/php_xhprof.h @@ -224,6 +224,8 @@ static inline void hp_array_del(char **name_array); char *hp_get_trace_callback(char *symbol, zend_execute_data *data); void hp_init_trace_callbacks(); +double get_timebase_conversion(); + hp_ignored_functions *hp_ignored_functions_init(char **names); /* Struct to hold the various callbacks for a single xhprof mode */ @@ -286,6 +288,8 @@ ZEND_BEGIN_MODULE_GLOBALS(xhprof) /* Table of ignored function names and their filter */ hp_ignored_functions *ignored_functions; + double timebase_conversion; + ZEND_END_MODULE_GLOBALS(xhprof) PHP_MINIT_FUNCTION(xhprof); diff --git a/extension/xhprof.c b/extension/xhprof.c index 236827d2..8f4e98ef 100755 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -299,6 +299,8 @@ PHP_RINIT_FUNCTION(xhprof) ZEND_TSRMLS_CACHE_UPDATE(); #endif + XHPROF_G(timebase_conversion) = get_timebase_conversion(); + return SUCCESS; } @@ -401,6 +403,18 @@ void hp_ignored_functions_clear(hp_ignored_functions *functions) efree(functions); } +double get_timebase_conversion() +{ +#if defined(__APPLE__) + mach_timebase_info_data_t info; + (void) mach_timebase_info(&info); + + return (info.numer / info.denom) * 1000 * 1000; +#endif + + return 1.0; +} + hp_ignored_functions *hp_ignored_functions_init(char **names) { /* Delete the array storing ignored function names */ @@ -838,7 +852,7 @@ void hp_sample_check(hp_entry_t **entries) static inline uint64 cycle_timer() { #if defined(__APPLE__) && defined(__MACH__) - return mach_absolute_time(); + return mach_absolute_time() / XHPROF_G(timebase_conversion); #else struct timespec s; clock_gettime(CLOCK_MONOTONIC, &s);