Ejemplo n.º 1
0
 /**
  * Render tree (recursive function)
  *
  * @param array $data
  * @return string
  */
 public function renderTree(array $data)
 {
     $helper = Mage::helper('aoe_profiler');
     /* @var $helper Aoe_Profiler_Helper_Data */
     $output = '';
     foreach ($data as $key => $uniqueId) {
         if (strpos($key, '_children') === false) {
             $tmp = $this->stackLog[$uniqueId];
             $hasChildren = isset($data[$key . '_children']) && count($data[$key . '_children']) > 0;
             $duration = round($tmp['time_total'] * 1000);
             $output .= '<li duration="' . $duration . '" class="' . ($tmp['level'] > 1 ? 'collapsed' : '') . ' level-' . $tmp['level'] . ' ' . ($hasChildren ? 'has-children' : '') . '">';
             $output .= '<div class="info">';
             $output .= '<div class="profiler-label">';
             if ($hasChildren) {
                 $output .= '<div class="toggle profiler-open">&nbsp;</div>';
                 $output .= '<div class="toggle profiler-closed">&nbsp;</div>';
             }
             $label = end($tmp['stack']);
             if (isset($tmp['detail'])) {
                 $label .= ' (' . htmlspecialchars($tmp['detail']) . ')';
             }
             $type = Varien_Profiler::getType($tmp['type'], $label);
             $output .= '<span class="caption type-' . $type . '" title="' . htmlspecialchars($label) . '" />';
             if (isset($tmp['file'])) {
                 $remoteCallUrlTemplate = Mage::getStoreConfig('dev/debug/remoteCallUrlTemplate');
                 $linkTemplate = '<a href="%s" onclick="var ajax = new XMLHttpRequest(); ajax.open(\'GET\', this.href); ajax.send(null); return false">%s</a>';
                 $url = sprintf($remoteCallUrlTemplate, $tmp['file'], intval($tmp['line']));
                 $output .= sprintf($linkTemplate, $url, htmlspecialchars($label));
             } else {
                 $output .= htmlspecialchars($label);
             }
             $output .= '</span>';
             $output .= '</div>';
             // class="label"
             $output .= '<div class="profiler-columns">';
             foreach ($this->metrics as $metric) {
                 $formatterMethod = 'format_' . $metric;
                 $ownTitle = 'Own: ' . $helper->{$formatterMethod}($tmp[$metric . '_own']) . ' ' . $this->units[$metric] . ' / ' . round($tmp[$metric . '_rel_own'] * 100, 2) . '%';
                 $subTitle = 'Sub: ' . $helper->{$formatterMethod}($tmp[$metric . '_sub']) . ' ' . $this->units[$metric] . ' / ' . round($tmp[$metric . '_rel_sub'] * 100, 2) . '%';
                 $totalTitle = $helper->{$formatterMethod}($tmp[$metric . '_own'] + $tmp[$metric . '_sub']) . ' ' . $this->units[$metric] . ' / ' . round(($tmp[$metric . '_rel_own'] + $tmp[$metric . '_rel_sub']) * 100, 2) . '%';
                 $fullTitle = $totalTitle . ' (' . $ownTitle . ', ' . $subTitle . ')';
                 $output .= '<div class="metric" title="' . $fullTitle . '">';
                 $progressBar = $this->renderProgressBar($tmp[$metric . '_rel_own'] * 100, $tmp[$metric . '_rel_sub'] * 100, $tmp[$metric . '_rel_offset'] * 100);
                 $output .= '<div class="' . $metric . ' profiler-column">' . $progressBar . '</div>';
                 $output .= '</div>';
                 // class="metric"
             }
             $output .= '</div>';
             // class="profiler-columns"
             $output .= '</div>';
             // class="info"
             if ($hasChildren) {
                 $output .= '<ul>' . $this->renderTree($data[$key . '_children']) . '</ul>';
             }
             $output .= '</li>';
         }
     }
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * Get type icon
  *
  * @param $type
  * @param $label
  * @return string
  */
 protected function getType($type, $label)
 {
     $type = Varien_Profiler::getType($type, $label);
     if (!isset($this->typeIcons[$type])) {
         $type = Varien_Profiler::TYPE_DEFAULT;
     }
     return $type;
 }