Skip to content

Instantly share code, notes, and snippets.

@smalyshev
Created January 27, 2011 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smalyshev/799049 to your computer and use it in GitHub Desktop.
Save smalyshev/799049 to your computer and use it in GitHub Desktop.
xhprof with Sugar
<?php
if(mt_rand(0, 200) != 42) {
return;
}
if(!empty($_REQUEST['entryPoint']) && ($_REQUEST['entryPoint'] == 'getImage' || $_REQUEST['entryPoint'] == 'getYUIComboFile')) {
return;
}
xhprof_enable(XHPROF_FLAGS_LONGNAMES);
$xhprof_enabled = true;
include_once "xhprof_lib/utils/xhprof_lib.php";
include_once "xhprof_lib/utils/xhprof_runs.php";
function xhprof_collect()
{
global $xhprof_enabled;
if(empty($xhprof_enabled)) return;
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$name = str_replace(array(".", "-"), array("_", "_"), basename(getcwd()));
if(isset($_REQUEST['module'])) {
$name .= "_".$_REQUEST['module'];
}
if(isset($_REQUEST['action'])) {
$name .= "_".$_REQUEST['action'];
}
$run_id = $xhprof_runs->save_run($xhprof_data, $name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment