1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-29 08:50:58 +01:00
phorge-phorge/src/applications/console/plugin/DarkConsoleXHProfPlugin.php

108 lines
2.6 KiB
PHP
Raw Normal View History

2011-02-02 22:48:52 +01:00
<?php
final class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
2011-02-02 22:48:52 +01:00
protected $profileFilePHID;
2011-02-02 22:48:52 +01:00
public function getName() {
return 'XHProf';
}
2011-02-02 22:48:52 +01:00
public function getColor() {
$data = $this->getData();
if ($data['profileFilePHID']) {
return '#ff00ff';
2011-02-02 22:48:52 +01:00
}
return null;
2011-02-02 22:48:52 +01:00
}
public function getDescription() {
return 'Provides detailed PHP profiling information through XHProf.';
}
public function generateData() {
return array(
'profileFilePHID' => $this->profileFilePHID,
'profileURI' => (string)$this
->getRequestURI()
->alter('__profile__', 'page'),
);
2011-02-02 22:48:52 +01:00
}
public function getXHProfRunID() {
return $this->profileFilePHID;
2011-02-02 22:48:52 +01:00
}
public function renderPanel() {
$data = $this->getData();
$run = $data['profileFilePHID'];
$profile_uri = $data['profileURI'];
2011-02-02 22:48:52 +01:00
if (!DarkConsoleXHProfPluginAPI::isProfilerAvailable()) {
$href = PhabricatorEnv::getDoclink('Installation Guide');
$install_guide = phutil_tag(
'a',
array(
'href' => $href,
'class' => 'bright-link',
),
'Installation Guide');
2013-02-13 23:50:15 +01:00
return hsprintf(
'<div class="dark-console-no-content">'.
'The "xhprof" PHP extension is not available. Install xhprof '.
'to enable the XHProf console plugin. You can find instructions in '.
2013-02-13 23:50:15 +01:00
'the %s.'.
'</div>',
$install_guide);
2011-02-02 22:48:52 +01:00
}
2011-02-06 21:58:01 +01:00
$result = array();
$header = phutil_tag(
'div',
array('class' => 'dark-console-panel-header'),
array(
phutil_tag(
'a',
array(
'href' => $profile_uri,
'class' => $run ? 'disabled button' : 'green button',
),
pht('Profile Page')),
phutil_tag('h1', array(), pht('XHProf Profiler')),
));
$result[] = $header;
2011-02-06 21:58:01 +01:00
if ($run) {
$result[] = phutil_tag(
'a',
array(
'href' => "/xhprof/profile/$run/",
'class' => 'bright-link',
'style' => 'float: right; margin: 1em 2em 0 0; font-weight: bold;',
'target' => '_blank',
),
pht('Profile Permalink'));
$result[] = phutil_tag(
'iframe',
array('src' => "/xhprof/profile/$run/?frame=true"));
} else {
$result[] = phutil_tag(
'div',
array('class' => 'dark-console-no-content'),
pht(
'Profiling was not enabled for this page. Use the button above '.
'to enable it.'));
}
2013-02-13 23:50:15 +01:00
return phutil_implode_html("\n", $result);
}
2011-02-02 22:48:52 +01:00
public function willShutdown() {
$this->profileFilePHID = DarkConsoleXHProfPluginAPI::getProfileFilePHID();
2011-02-02 22:48:52 +01:00
}
}