Example #1
0
 /**
  * Destructor, call _shutdown method
  */
 function __destruct()
 {
     if (!self::$_isDie) {
         self::$_isDie = true;
         if (self::$_config['profiler']['showEnd']) {
             self::mark('jbdump::end');
         }
         $this->profiler(self::$_config['profiler']['render']);
     }
     if (!self::$_config['profiler']['showOnAjax'] && self::isAjax()) {
         return;
     }
     // JBDump incriment output
     if (!empty(self::$_counters['mode_0'])) {
         arsort(self::$_counters['mode_0']);
         foreach (self::$_counters['mode_0'] as $counterName => $count) {
             echo '<pre>JBDump Increment / "' . $counterName . '" = ' . $count . '</pre>';
         }
     }
     // JBDump trace incriment output
     if (!empty(self::$_counters['trace'])) {
         uasort(self::$_counters['trace'], function ($a, $b) {
             if ($a['count'] == $b['count']) {
                 return 0;
             }
             return $a['count'] < $b['count'] ? 1 : -1;
         });
         foreach (self::$_counters['trace'] as $counterHash => $traceInfo) {
             self::i()->dump($traceInfo['trace'], $traceInfo['label'] . ' = ' . $traceInfo['count']);
         }
     }
     // JBDump pairs profiler
     if (!empty(self::$_profilerPairs)) {
         foreach (self::$_profilerPairs as $label => $pairs) {
             $timeDelta = $memDelta = $count = 0;
             $memDiffs = $timeDiffs = array();
             foreach ($pairs as $key => $pair) {
                 if (!isset($pair['stop']) || !isset($pair['start'])) {
                     continue;
                 }
                 $count++;
                 $tD = $pair['stop'][0] - $pair['start'][0];
                 $mD = $pair['stop'][1] - $pair['start'][1];
                 $timeDiffs[] = $tD;
                 $memDiffs[] = $mD;
                 $timeDelta += $tD;
                 $memDelta += $mD;
             }
             if ($count > 0) {
                 $timeAvg = array_sum($timeDiffs) / $count;
                 $memoAvg = array_sum($memDiffs) / $count;
                 $timeStd = $memoStd = '';
                 if ($count > 1) {
                     $timeStdValue = $this->_stdDev($timeDiffs);
                     $memoStdValue = $this->_stdDev($memDiffs);
                     $timeStd = ' <span title="' . round($timeStdValue / $timeAvg * 100) . '%">(&plusmn;' . self::_profilerFormatTime($timeStdValue, true, 2) . ')</span>';
                     $memoStd = ' <span title="' . round($memoStdValue / $memoAvg * 100) . '%">(&plusmn;' . self::_profilerFormatMemory($memoStdValue, true) . ')</span>';
                 }
                 $output = array('<pre>JBDump ProfilerPairs / "' . $label . '"', 'Count  = ' . $count, 'Time   = ' . implode(";\t\t", array('ave: ' . self::_profilerFormatTime($timeAvg, true, 2) . $timeStd, 'sum: ' . self::_profilerFormatTime(array_sum($timeDiffs), true, 2), 'min(' . (array_search(min($timeDiffs), $timeDiffs) + 1) . '):' . self::_profilerFormatTime(min($timeDiffs), true, 2), 'max(' . (array_search(max($timeDiffs), $timeDiffs) + 1) . '): ' . self::_profilerFormatTime(max($timeDiffs), true, 2))), 'Memory = ' . implode(";\t\t", array('ave: ' . self::_profilerFormatMemory($memoAvg, true) . $memoStd, 'sum: ' . self::_profilerFormatMemory(array_sum($memDiffs), true), 'min(' . (array_search(min($memDiffs), $memDiffs) + 1) . '): ' . self::_profilerFormatMemory(min($memDiffs), true), 'max(' . (array_search(max($memDiffs), $memDiffs) + 1) . '): ' . self::_profilerFormatMemory(max($memDiffs), true))), '</pre>');
             } else {
                 $output = array('<pre>JBDump ProfilerPairs / "' . $label . '"', 'Count  = ' . $count, '</pre>');
             }
             echo implode(PHP_EOL, $output);
         }
     }
 }