Path: blob/master/src/applications/console/plugin/DarkConsoleXHProfPlugin.php
13402 views
<?php12final class DarkConsoleXHProfPlugin extends DarkConsolePlugin {34protected $profileFilePHID;56public function getName() {7return pht('XHProf');8}910public function getColor() {11$data = $this->getData();12if ($data['profileFilePHID']) {13return '#ff00ff';14}15return null;16}1718public function getDescription() {19return pht('Provides detailed PHP profiling information through XHProf.');20}2122public function generateData() {23return array(24'profileFilePHID' => $this->profileFilePHID,25'profileURI' => (string)$this26->getRequestURI()27->alter('__profile__', 'page'),28);29}3031public function getXHProfRunID() {32return $this->profileFilePHID;33}3435public function renderPanel() {36$data = $this->getData();3738$run = $data['profileFilePHID'];39$profile_uri = $data['profileURI'];4041if (!DarkConsoleXHProfPluginAPI::isProfilerAvailable()) {42$href = PhabricatorEnv::getDoclink('Installation Guide');43$install_guide = phutil_tag(44'a',45array(46'href' => $href,47'class' => 'bright-link',48),49pht('Installation Guide'));50return hsprintf(51'<div class="dark-console-no-content">%s</div>',52pht(53'The "xhprof" PHP extension is not available. Install xhprof '.54'to enable the XHProf console plugin. You can find instructions in '.55'the %s.',56$install_guide));57}5859$result = array();6061$header = phutil_tag(62'div',63array('class' => 'dark-console-panel-header'),64array(65phutil_tag(66'a',67array(68'href' => $profile_uri,69'class' => $run ? 'disabled button' : 'button button-green',70),71pht('Profile Page')),72phutil_tag('h1', array(), pht('XHProf Profiler')),73));74$result[] = $header;7576if ($run) {77$result[] = phutil_tag(78'a',79array(80'href' => "/xhprof/profile/$run/",81'class' => 'bright-link',82'style' => 'float: right; margin: 1em 2em 0 0; font-weight: bold;',83'target' => '_blank',84),85pht('Profile Permalink'));86$result[] = phutil_tag(87'iframe',88array('src' => "/xhprof/profile/$run/?frame=true"));89} else {90$result[] = phutil_tag(91'div',92array('class' => 'dark-console-no-content'),93pht(94'Profiling was not enabled for this page. Use the button above '.95'to enable it.'));96}9798return phutil_implode_html("\n", $result);99}100101102public function willShutdown() {103$this->profileFilePHID = DarkConsoleXHProfPluginAPI::getProfileFilePHID();104}105106}107108109