1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-01 02:10:59 +01:00
phorge-phorge/src/aphront/console/plugin/DarkConsoleXHProfPlugin.php

97 lines
2.4 KiB
PHP
Raw Normal View History

2011-02-02 22:48:52 +01:00
<?php
2011-09-14 17:02:31 +02:00
/**
* @group console
*/
final class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
2011-02-02 22:48:52 +01:00
protected $xhprofID;
public function getName() {
$run = $this->getData();
if ($run) {
return '<span style="color: #ff00ff;">&bull;</span> XHProf';
}
return 'XHProf';
}
public function getDescription() {
return 'Provides detailed PHP profiling information through XHProf.';
}
public function generateData() {
return $this->xhprofID;
}
public function getXHProfRunID() {
return $this->xhprofID;
}
public function render() {
if (!DarkConsoleXHProfPluginAPI::isProfilerAvailable()) {
$href = PhabricatorEnv::getDoclink('article/Installation_Guide.html');
$install_guide = phutil_render_tag(
'a',
array(
'href' => $href,
'class' => 'bright-link',
),
'Installation Guide');
2011-02-02 22:48:52 +01:00
return
'<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 '.
'the '.$install_guide.'.'.
'</div>';
2011-02-02 22:48:52 +01:00
}
2011-02-06 21:58:01 +01:00
$result = array();
$run = $this->getXHProfRunID();
2011-02-06 21:58:01 +01:00
$header =
'<div class="dark-console-panel-header">'.
phutil_render_tag(
'a',
array(
'href' => $this->getRequestURI()->alter('__profile__', 'page'),
'class' => $run
? 'disabled button'
: 'green button',
),
'Profile Page').
'<h1>XHProf Profiler</h1>'.
'</div>';
$result[] = $header;
2011-02-06 21:58:01 +01:00
if ($run) {
$result[] =
'<a href="/xhprof/profile/'.$run.'/" '.
'class="bright-link" '.
'style="float: right; margin: 1em 2em 0 0;'.
'font-weight: bold;" '.
'target="_blank">Profile Permalink</a>'.
'<iframe src="/xhprof/profile/'.$run.'/?frame=true"></iframe>';
} else {
$result[] =
'<div class="dark-console-no-content">'.
'Profiling was not enabled for this page. Use the button above '.
'to enable it.'.
'</div>';
}
return implode("\n", $result);
}
2011-02-02 22:48:52 +01:00
public function willShutdown() {
if (DarkConsoleXHProfPluginAPI::isProfilerRequested() &&
(DarkConsoleXHProfPluginAPI::isProfilerRequested() !== 'all')) {
$this->xhprofID = DarkConsoleXHProfPluginAPI::stopProfiler();
}
2011-02-02 22:48:52 +01:00
}
}