Exemple #1
0
 public function getSummary()
 {
     if (Yii::$app->get('xhprof', false) === null) {
         return null;
     }
     XHProf::getInstance()->setHtmlUrlPath(Yii::$app->get('xhprof')->getReportBaseUrl());
     $urls = [];
     $data = $this->data;
     if ($data['enabled']) {
         $urls['report'] = XHProf::getInstance()->getReportUrl($data['runId'], $data['ns']);
         $urls['callgraph'] = XHProf::getInstance()->getCallgraphUrl($data['runId'], $data['ns']);
     }
     return Yii::$app->view->render('@yii2-xhprof/views/panel', ['panel' => $this, 'enabled' => $data['enabled'], 'urls' => $urls]);
 }
    /**
     * Add code to display own overlay with links to report and callgraph for current profile run
     */
    public function appendResultsOverlay()
    {
        $XHProf = XHProf::getInstance();
        if (!$XHProf->isStarted()) {
            return;
        }
        $data = $this->getReportInfo();
        $reportUrl = $XHProf->getReportUrl($data['runId'], $data['ns']);
        $callgraphUrl = $XHProf->getCallgraphUrl($data['runId'], $data['ns']);
        echo <<<EOD
<script type="text/javascript">
(function() {
    var overlay = document.createElement('div');
    overlay.setAttribute('id', 'xhprof-overlay');
    overlay.innerHTML = '<div class="xhprof-header">XHProf</div><a href="{$reportUrl}" target="_blank">Report</a><a href="{$callgraphUrl}" target="_blank">Callgraph</a>';
    document.getElementsByTagName('body')[0].appendChild(overlay);
})();
</script>
EOD;
    }