Example #1
0
 /**
  * Get single instance of XHProf
  * @return XHProf
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Stop the profiler
  *
  * @return mixed Void or modified response if replaceRunId is defined
  */
 public function afterDispatch($event)
 {
     $runId = XHProf::finish();
     $replaceRunId = Configure::read('XHProf.replaceRunId');
     if (!empty($replaceRunId)) {
         $body = $event->data['response']->body();
         $body = str_replace($replaceRunId, $runId, $event->data['response']);
         $event->data['response']->body($body);
         return $event->data['response'];
     }
 }
Example #3
0
 public function getSummary()
 {
     if (Yii::app()->getComponent('xhprof', false) === null) {
         return null;
     }
     XHProf::getInstance()->setHtmlUrlPath(Yii::app()->xhprof->getReportBaseUrl());
     $urls = array();
     $data = $this->getData();
     if ($data['enabled']) {
         $urls['report'] = XHProf::getInstance()->getReportUrl($data['runId'], $data['ns']);
         $urls['callgraph'] = XHProf::getInstance()->getCallgraphUrl($data['runId'], $data['ns']);
     }
     return $this->render(__DIR__ . '/views/panel.php', array('enabled' => $data['enabled'], 'urls' => $urls));
 }
Example #4
0
 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;
     }
 }
Example #5
0
 /**
  * Initialize default options and include necessary files
  *
  * @return void
  */
 protected static function _initialize()
 {
     // Can't profile without xhprof
     if (!extension_loaded('xhprof')) {
         throw new RuntimeException('XHProf extension is not loaded.');
     }
     // Merge base configuration
     $options = (array) Configure::read('XHProf') + self::$_baseConfig;
     Configure::write('XHProf', $options);
     // Include libraries
     if (!class_exists('XHProfRuns_Default')) {
         $path = $options['library'] . DS . 'utils' . DS;
         $files = array($path . 'xhprof_lib.php', $path . 'xhprof_runs.php');
         foreach ($files as $file) {
             if (!(include $file)) {
                 throw new RuntimeException(sprintf('Couldn\'t include library file: %s.', $file));
             }
         }
     }
     // All good to go
     self::$_initiated = true;
 }
Example #6
0
 /**
  * Get report details for current profiling process. Info consists of:
  * - unique run identifier (runId)
  * - namespace for run (ns, current application ID by default)
  * - requested URL (url)
  * - time of request (time)
  * @return array key-valued list
  */
 public function getReportInfo()
 {
     if (!$this->isActive()) {
         return array('enabled' => false, 'runId' => null, 'ns' => null, 'url' => null, 'time' => null);
     }
     if ($this->reportInfo === null) {
         $request = Yii::app()->getRequest();
         $this->reportInfo = array('enabled' => true, 'runId' => XHProf::getInstance()->getRunId(), 'ns' => XHProf::getInstance()->getRunNamespace(), 'url' => $request->getHostInfo() . $request->getUrl(), 'time' => microtime(true));
     }
     return $this->reportInfo;
 }