Skip to content

Commit da6dcb1

Browse files
committed
Fix macOS time benchmark
#31 Fix macOS time benchmark
1 parent 0d6c4eb commit da6dcb1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

extension/php_xhprof.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ static inline void hp_array_del(char **name_array);
224224
char *hp_get_trace_callback(char *symbol, zend_execute_data *data);
225225
void hp_init_trace_callbacks();
226226

227+
double get_timebase_conversion();
228+
227229
hp_ignored_functions *hp_ignored_functions_init(char **names);
228230

229231
/* Struct to hold the various callbacks for a single xhprof mode */
@@ -286,6 +288,8 @@ ZEND_BEGIN_MODULE_GLOBALS(xhprof)
286288
/* Table of ignored function names and their filter */
287289
hp_ignored_functions *ignored_functions;
288290

291+
double timebase_conversion;
292+
289293
ZEND_END_MODULE_GLOBALS(xhprof)
290294

291295
PHP_MINIT_FUNCTION(xhprof);

extension/xhprof.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ PHP_RINIT_FUNCTION(xhprof)
299299
ZEND_TSRMLS_CACHE_UPDATE();
300300
#endif
301301

302+
XHPROF_G(timebase_conversion) = get_timebase_conversion();
303+
302304
return SUCCESS;
303305
}
304306

@@ -401,6 +403,18 @@ void hp_ignored_functions_clear(hp_ignored_functions *functions)
401403
efree(functions);
402404
}
403405

406+
double get_timebase_conversion()
407+
{
408+
#if defined(__APPLE__)
409+
mach_timebase_info_data_t info;
410+
(void) mach_timebase_info(&info);
411+
412+
return (info.numer / info.denom) * 1000 * 1000;
413+
#endif
414+
415+
return 1.0;
416+
}
417+
404418
hp_ignored_functions *hp_ignored_functions_init(char **names)
405419
{
406420
/* Delete the array storing ignored function names */
@@ -838,7 +852,7 @@ void hp_sample_check(hp_entry_t **entries)
838852
static inline uint64 cycle_timer()
839853
{
840854
#if defined(__APPLE__) && defined(__MACH__)
841-
return mach_absolute_time();
855+
return mach_absolute_time() / XHPROF_G(timebase_conversion);
842856
#else
843857
struct timespec s;
844858
clock_gettime(CLOCK_MONOTONIC, &s);

0 commit comments

Comments
 (0)