Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions extension/php_xhprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ extern zend_module_entry xhprof_module_entry;
#define XHPROF_FLAGS_MEMORY 0x0004 /* gather memory usage for funcs */

/* Constants for XHPROF_MODE_SAMPLED */
#define XHPROF_SAMPLING_INTERVAL 100000 /* In microsecs */
#define XHPROF_DEFAULT_SAMPLING_INTERVAL 100000 /* In microsecs */
#define XHPROF_MINIMAL_SAMPLING_INTERVAL 100 /* In microsecs */

/* Constant for ignoring functions, transparent to hierarchical profile */
#define XHPROF_MAX_IGNORED_FUNCTIONS 256
Expand Down Expand Up @@ -269,8 +270,9 @@ ZEND_BEGIN_MODULE_GLOBALS(xhprof)
struct timeval last_sample_time;
uint64 last_sample_tsc;
/* XHPROF_SAMPLING_INTERVAL in ticks */
long sampling_interval;
uint64 sampling_interval_tsc;

int sampling_depth;
/* XHProf flags */
uint32 xhprof_flags;

Expand Down
24 changes: 20 additions & 4 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ PHP_INI_BEGIN()
* directory specified by this ini setting.
*/
PHP_INI_ENTRY("xhprof.output_dir", "", PHP_INI_ALL, NULL)
/* sampling_interval:
* Sampling interval to be used by the sampling profiler, in microseconds.
*/
#define STRINGIFY_(X) #X
#define STRINGIFY(X) STRINGIFY_(X)

STD_PHP_INI_ENTRY("xhprof.sampling_interval", STRINGIFY(XHPROF_DEFAULT_SAMPLING_INTERVAL), PHP_INI_ALL, OnUpdateLong, sampling_interval, zend_xhprof_globals, xhprof_globals)

/* sampling_depth:
* Depth to trace call-chain by the sampling profiler
*/
STD_PHP_INI_ENTRY("xhprof.sampling_depth", STRINGIFY(INT_MAX), PHP_INI_ALL, OnUpdateLong, sampling_depth, zend_xhprof_globals, xhprof_globals)
PHP_INI_END()

/* Init module */
Expand Down Expand Up @@ -198,6 +209,8 @@ PHP_GINIT_FUNCTION(xhprof)
xhprof_globals->root = NULL;
xhprof_globals->trace_callbacks = NULL;
xhprof_globals->ignored_functions = NULL;
xhprof_globals->sampling_interval = XHPROF_DEFAULT_SAMPLING_INTERVAL;
xhprof_globals->sampling_depth = INT_MAX;
}

/**
Expand All @@ -221,6 +234,9 @@ PHP_MINIT_FUNCTION(xhprof)
for (i = 0; i < 256; i++) {
XHPROF_G(func_hash_counters[i]) = 0;
}
if (XHPROF_G(sampling_interval) < XHPROF_MINIMAL_SAMPLING_INTERVAL) {
XHPROF_G(sampling_interval) = XHPROF_MINIMAL_SAMPLING_INTERVAL;
}

/* Replace zend_compile with our proxy */
_zend_compile_file = zend_compile_file;
Expand Down Expand Up @@ -769,7 +785,7 @@ void hp_sample_stack(hp_entry_t **entries)
snprintf(key, sizeof(key), "%d.%06d", XHPROF_G(last_sample_time).tv_sec, XHPROF_G(last_sample_time).tv_usec);

/* Init stats in the global stats_count hashtable */
symbol = hp_get_function_stack(*entries, INT_MAX);
symbol = hp_get_function_stack(*entries, XHPROF_G(sampling_depth));

add_assoc_string(&XHPROF_G(stats_count), key, symbol);

Expand Down Expand Up @@ -801,7 +817,7 @@ void hp_sample_check(hp_entry_t **entries)
XHPROF_G(last_sample_tsc) += XHPROF_G(sampling_interval_tsc);

/* bump last_sample_time - HAS TO BE UPDATED BEFORE calling hp_sample_stack */
incr_us_interval(&XHPROF_G(last_sample_time), XHPROF_SAMPLING_INTERVAL);
incr_us_interval(&XHPROF_G(last_sample_time), XHPROF_G(sampling_interval));

/* sample the stack */
hp_sample_stack(entries);
Expand Down Expand Up @@ -946,10 +962,10 @@ void hp_mode_sampled_init_cb()
/* Find the microseconds that need to be truncated */
gettimeofday(&XHPROF_G(last_sample_time), 0);
now = XHPROF_G(last_sample_time);
hp_trunc_time(&XHPROF_G(last_sample_time), XHPROF_SAMPLING_INTERVAL);
hp_trunc_time(&XHPROF_G(last_sample_time), XHPROF_G(sampling_interval));

/* Convert sampling interval to ticks */
XHPROF_G(sampling_interval_tsc) = XHPROF_SAMPLING_INTERVAL;
XHPROF_G(sampling_interval_tsc) = XHPROF_G(sampling_interval);
}


Expand Down