Skip to content

Instantly share code, notes, and snippets.

@mmenozzi
Last active August 29, 2015 14:01
Show Gist options
  • Save mmenozzi/9c7a77c97923ad51015d to your computer and use it in GitHub Desktop.
Save mmenozzi/9c7a77c97923ad51015d to your computer and use it in GitHub Desktop.
Profiling with xhprof
$profilingEnabled = extension_loaded('xhprof') && isset($_GET['xhprof']);
if ($profilingEnabled) {
include_once '/Users/manuele/Work/Projects/xhprof-0.9.3/xhprof_lib/utils/xhprof_lib.php';
include_once '/Users/manuele/Work/Projects/xhprof-0.9.3/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
register_shutdown_function(
function() {
$profiler_namespace = 'xxx'; // namespace for your application
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
// url to the XHProf UI libraries (change the host name and path)
$profiler_url = sprintf('http://localhost/xhprof-0.9.3/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace);
echo '<a href="'. $profiler_url .'" target="_blank">Xhprof output</a>';
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment