[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @phutil-external-symbol function xhprof_compute_flat_info
   5   */
   6  final class PhabricatorXHProfProfileTopLevelView
   7    extends PhabricatorXHProfProfileView {
   8  
   9    private $profileData;
  10    private $limit;
  11    private $file;
  12  
  13    public function setProfileData(array $data) {
  14      $this->profileData = $data;
  15      return $this;
  16    }
  17  
  18    public function setLimit($limit) {
  19      $this->limit = $limit;
  20      return $this;
  21    }
  22  
  23    public function setFile(PhabricatorFile $file) {
  24      $this->file = $file;
  25      return $this;
  26    }
  27  
  28    public function render() {
  29      DarkConsoleXHProfPluginAPI::includeXHProfLib();
  30  
  31      $GLOBALS['display_calls'] = true;
  32      $totals = array();
  33      $flat = xhprof_compute_flat_info($this->profileData, $totals);
  34      unset($GLOBALS['display_calls']);
  35  
  36      $aggregated = array();
  37      foreach ($flat as $call => $counters) {
  38        $parts = explode('@', $call, 2);
  39        $agg_call = reset($parts);
  40        if (empty($aggregated[$agg_call])) {
  41          $aggregated[$agg_call] = $counters;
  42        } else {
  43          foreach ($aggregated[$agg_call] as $key => $val) {
  44            if ($key != 'wt') {
  45              $aggregated[$agg_call][$key] += $counters[$key];
  46            }
  47          }
  48        }
  49      }
  50      $flat = $aggregated;
  51  
  52      $flat = isort($flat, 'wt');
  53      $flat = array_reverse($flat);
  54  
  55      $rows = array();
  56      $rows[] = array(
  57        'Total',
  58        number_format($totals['ct']),
  59        number_format($totals['wt']).' us',
  60        '100.0%',
  61        number_format($totals['wt']).' us',
  62        '100.0%',
  63      );
  64  
  65      if ($this->limit) {
  66        $flat = array_slice($flat, 0, $this->limit);
  67      }
  68  
  69      foreach ($flat as $call => $counters) {
  70        $rows[] = array(
  71          $this->renderSymbolLink($call),
  72          number_format($counters['ct']),
  73          number_format($counters['wt']).' us',
  74          sprintf('%.1f%%', 100 * $counters['wt'] / $totals['wt']),
  75          number_format($counters['excl_wt']).' us',
  76          sprintf('%.1f%%', 100 * $counters['excl_wt'] / $totals['wt']),
  77        );
  78      }
  79  
  80      Javelin::initBehavior('phabricator-tooltips');
  81  
  82      $table = new AphrontTableView($rows);
  83      $table->setHeaders(
  84        array(
  85          'Symbol',
  86          'Count',
  87          javelin_tag(
  88            'span',
  89            array(
  90              'sigil' => 'has-tooltip',
  91              'meta'  => array(
  92                'tip' => 'Total wall time spent in this function and all of '.
  93                         'its children (children are other functions it called '.
  94                         'while executing).',
  95                'size' => 200,
  96              ),
  97            ),
  98            'Wall Time (Inclusive)'),
  99          '%',
 100          javelin_tag(
 101            'span',
 102            array(
 103              'sigil' => 'has-tooltip',
 104              'meta'  => array(
 105                'tip' => 'Wall time spent in this function, excluding time '.
 106                         'spent in children (children are other functions it '.
 107                         'called while executing).',
 108                'size' => 200,
 109              ),
 110            ),
 111            'Wall Time (Exclusive)'),
 112          '%',
 113        ));
 114      $table->setColumnClasses(
 115        array(
 116          'wide pri',
 117          'n',
 118          'n',
 119          'n',
 120          'n',
 121          'n',
 122        ));
 123  
 124      $panel = new AphrontPanelView();
 125      $panel->setHeader('XHProf Profile');
 126  
 127      if ($this->file) {
 128        $panel->addButton(
 129          phutil_tag(
 130            'a',
 131            array(
 132              'href' => $this->file->getBestURI(),
 133              'class' => 'green button',
 134            ),
 135            'Download .xhprof Profile'));
 136      }
 137  
 138      $panel->appendChild($table);
 139  
 140      return $panel->render();
 141    }
 142  }


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