Esempio n. 1
0
 /**
  * Output profiling data.
  */
 public function show()
 {
     global $DB;
     $debug_str = '<a name="debug"></a>';
     $debug_str .= '******************** ' . _('Script profiler') . ' ********************' . '<br>';
     $totalScriptTime = $this->stopTime - $this->startTime;
     $totalTimeStr = _s('Total time: %s', round($totalScriptTime, 6));
     if ($totalTimeStr > $this->slowScriptTime) {
         $totalTimeStr = '<b>' . $totalTimeStr . '</b>';
     }
     $debug_str .= $totalTimeStr . '<br>';
     $sqlTotalTimeStr = _s('Total SQL time: %s', $this->sqlTotalTime);
     if ($sqlTotalTimeStr > $this->slowTotalSqlTime) {
         $sqlTotalTimeStr = '<b>' . $sqlTotalTimeStr . '</b>';
     }
     $debug_str .= $sqlTotalTimeStr . '<br>';
     if (isset($DB) && isset($DB['SELECT_COUNT'])) {
         $debug_str .= _s('SQL count: %s (selects: %s | executes: %s)', count($this->sqlQueryLog), $DB['SELECT_COUNT'], $DB['EXECUTE_COUNT']) . '<br>';
     }
     $debug_str .= _s('Peak memory usage: %s', mem2str($this->getMemoryPeak())) . '<br>';
     $debug_str .= _s('Memory limit: %s', ini_get('memory_limit')) . '<br>';
     $debug_str .= '<br>';
     foreach ($this->apiLog as $i => $apiCall) {
         $debug_str .= '<div style="border-bottom: 1px dotted gray; margin-bottom: 20px;">';
         list($class, $method, $params, $result, $file, $line) = $apiCall;
         // api method
         $debug_str .= '<div style="padding-bottom: 10px;">';
         $debug_str .= $i + 1 . '. <b>' . $class . '->' . $method . '</b> [' . $file . ':' . $line . ']';
         $debug_str .= '</div>';
         // parameters
         $debug_str .= '<table><tr><td style="width: 300px" valign="top">Parameters:';
         foreach ($params as $p) {
             $debug_str .= '<pre>' . print_r(CHtml::encode($p), true) . '</pre>';
         }
         $debug_str .= '</td>';
         // result
         $debug_str .= '<td valign="top">Result:<pre>' . print_r(CHtml::encode($result), true) . '</pre></td>';
         $debug_str .= '</tr></table>';
         $debug_str .= '</div>';
     }
     $debug_str .= '<br>';
     foreach ($this->sqlQueryLog as $query) {
         $time = $query[0];
         $sql = htmlspecialchars($query[1], ENT_QUOTES, 'UTF-8');
         if (strpos($sql, 'SELECT ') !== false) {
             $sqlString = '<span style="color: green; font-size: 1.2em;">' . $sql . '</span>';
         } else {
             $sqlString = '<span style="color: blue; font-size: 1.2em;">' . $sql . '</span>';
         }
         $sqlString = 'SQL (' . $time . '): ' . $sqlString . '<br>';
         if ($time > $this->slowSqlQueryTime) {
             $sqlString = '<b>' . $sqlString . '</b>';
         }
         $debug_str .= $sqlString;
         $callStackString = '<span style="font-style: italic;">' . $this->formatCallStack($query[2]) . '</span>' . '<br>' . '<br>';
         $debug_str .= rtrim($callStackString, '-> ') . '</span>' . '<br>' . '<br>';
     }
     $debug = new CDiv(null, 'textcolorstyles');
     $debug->attr('name', 'zbx_debug_info');
     $debug->attr('style', 'display: none; overflow: auto; width: 95%; border: 1px #777777 solid; margin: 4px; padding: 4px;');
     $debug->addItem(array(BR(), new CJSscript($debug_str), BR()));
     $debug->show();
 }