. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * class XHProf * * @since 0.84 * * Il you need to "profile" some part of code * * Install the pecl/xhprof extension * * Add XHPROF_PATH and XHPROF_URL in config/local_define.php (if needed) * * Before the code * $prof = new XHProf("something useful"); * * If the code contains an exit() or a redirect() you must also call (before) * unset($prof); * * php-errors.log will give you the URL of the result. */ class XHProf { // this can be overloaded in config/local_define.php const XHPROF_PATH = '/usr/share/xhprof/xhprof_lib'; const XHPROF_URL = '/xhprof'; static private $run = false; /** * @param $msg (default '') **/ function __construct($msg = '') { $this->start($msg); } function __destruct() { $this->stop(); } /** * @param $msg (default '') **/ function start($msg = '') { if (!self::$run && function_exists('xhprof_enable')) { xhprof_enable(); if (class_exists('Toolbox')) { Toolbox::logDebug("Start profiling with XHProf", $msg); } self::$run = true; } } function stop() { if (self::$run) { $data = xhprof_disable(); $incl = (defined('XHPROF_PATH') ? XHPROF_PATH : self::XHPROF_PATH); include_once $incl.'/utils/xhprof_lib.php'; include_once $incl.'/utils/xhprof_runs.php'; $runs = new XHProfRuns_Default(); $id = $runs->save_run($data, 'glpi'); $url = (defined('XHPROF_URL') ? XHPROF_URL : self::XHPROF_URL); $host = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost'); $link = "http://".$host."$url/index.php?run=$id&source=glpi"; Toolbox::logDebug("Stop profiling with XHProf, result URL", $link); self::$run = false; } } }