[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/xhprof/view/ -> PhabricatorXHProfProfileSymbolView.php (source)

   1  <?php
   2  
   3  /**
   4   * @phutil-external-symbol function xhprof_compute_flat_info
   5   */
   6  final class PhabricatorXHProfProfileSymbolView
   7    extends PhabricatorXHProfProfileView {
   8  
   9    private $profileData;
  10    private $symbol;
  11  
  12    public function setProfileData(array $data) {
  13      $this->profileData = $data;
  14      return $this;
  15    }
  16  
  17    public function setSymbol($symbol) {
  18      $this->symbol = $symbol;
  19      return $this;
  20    }
  21  
  22    public function render() {
  23      DarkConsoleXHProfPluginAPI::includeXHProfLib();
  24  
  25      $data = $this->profileData;
  26  
  27      $GLOBALS['display_calls'] = true;
  28      $totals = array();
  29      $flat = xhprof_compute_flat_info($data, $totals);
  30      unset($GLOBALS['display_calls']);
  31  
  32      $symbol = $this->symbol;
  33  
  34      $children = array();
  35      $parents = array();
  36      foreach ($this->profileData as $key => $counters) {
  37        if (strpos($key, '==>') !== false) {
  38          list($parent, $child) = explode('==>', $key, 2);
  39        } else {
  40          continue;
  41        }
  42        if ($parent == $symbol) {
  43          $children[$key] = $child;
  44        } else if ($child == $symbol) {
  45          $parents[$key] = $parent;
  46        }
  47      }
  48  
  49      $rows = array();
  50      $rows[] = array(
  51        'Metrics for this Call',
  52        '',
  53        '',
  54        '',
  55      );
  56      $rows[] = $this->formatRow(
  57        array(
  58          $symbol,
  59          $flat[$symbol]['ct'],
  60          $flat[$symbol]['wt'],
  61          1.0,
  62        ));
  63  
  64      $rows[] = array(
  65        'Parent Calls',
  66        '',
  67        '',
  68        '',
  69      );
  70      foreach ($parents as $key => $name) {
  71        $rows[] = $this->formatRow(
  72          array(
  73            $name,
  74            $data[$key]['ct'],
  75            $data[$key]['wt'],
  76            '',
  77          ));
  78      }
  79  
  80  
  81      $rows[] = array(
  82        'Child Calls',
  83        '',
  84        '',
  85        '',
  86      );
  87      $child_rows = array();
  88      foreach ($children as $key => $name) {
  89        $child_rows[] = array(
  90          $name,
  91          $data[$key]['ct'],
  92          $data[$key]['wt'],
  93          $data[$key]['wt'] / $flat[$symbol]['wt'],
  94        );
  95      }
  96      $child_rows = isort($child_rows, 2);
  97      $child_rows = array_reverse($child_rows);
  98      $rows = array_merge(
  99        $rows,
 100        array_map(array($this, 'formatRow'), $child_rows));
 101  
 102      $table = new AphrontTableView($rows);
 103      $table->setHeaders(
 104        array(
 105          'Symbol',
 106          'Count',
 107          'Wall Time',
 108          '%',
 109        ));
 110      $table->setColumnClasses(
 111        array(
 112          'wide pri',
 113          'n',
 114          'n',
 115          'n',
 116        ));
 117  
 118      $panel = new AphrontPanelView();
 119      $panel->setHeader('XHProf Profile');
 120      $panel->appendChild($table);
 121  
 122      return $panel->render();
 123    }
 124  
 125    private function formatRow(array $row) {
 126      return array(
 127        $this->renderSymbolLink($row[0]),
 128        number_format($row[1]),
 129        number_format($row[2]).' us',
 130        ($row[3] != '' ? sprintf('%.1f%%', 100 * $row[3]) : ''),
 131      );
 132    }
 133  
 134  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1