Skip to content

Commit

Permalink
Fix macOS time benchmark
Browse files Browse the repository at this point in the history
#31 Fix macOS time benchmark
  • Loading branch information
longxinH committed Dec 3, 2019
1 parent 0d6c4eb commit da6dcb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions extension/php_xhprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 15 additions & 1 deletion extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ PHP_RINIT_FUNCTION(xhprof)
ZEND_TSRMLS_CACHE_UPDATE();
#endif

XHPROF_G(timebase_conversion) = get_timebase_conversion();

return SUCCESS;
}

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit da6dcb1

Please sign in to comment.