2011-02-02 22:48:52 +01:00
|
|
|
<?php
|
|
|
|
|
2011-09-14 17:02:31 +02:00
|
|
|
/**
|
|
|
|
* @group console
|
|
|
|
*/
|
2012-03-13 19:18:11 +01:00
|
|
|
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;">•</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()) {
|
2011-07-09 18:45:19 +02:00
|
|
|
$href = PhabricatorEnv::getDoclink('article/Installation_Guide.html');
|
2013-01-18 03:57:09 +01:00
|
|
|
$install_guide = phutil_tag(
|
2011-07-09 18:45:19 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $href,
|
|
|
|
'class' => 'bright-link',
|
|
|
|
),
|
|
|
|
'Installation Guide');
|
2011-02-02 22:48:52 +01:00
|
|
|
return
|
2011-07-09 18:45:19 +02:00
|
|
|
'<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
|
|
|
|
2011-07-09 18:45:19 +02:00
|
|
|
$result = array();
|
|
|
|
|
2011-02-03 01:14:23 +01:00
|
|
|
$run = $this->getXHProfRunID();
|
2011-02-06 21:58:01 +01:00
|
|
|
|
2011-07-09 18:45:19 +02:00
|
|
|
$header =
|
|
|
|
'<div class="dark-console-panel-header">'.
|
2013-01-18 03:57:09 +01:00
|
|
|
phutil_tag(
|
2011-07-09 18:45:19 +02:00
|
|
|
'a',
|
2011-02-03 01:14:23 +01:00
|
|
|
array(
|
2011-07-09 18:45:19 +02:00
|
|
|
'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
|
|
|
|
2011-07-09 18:45:19 +02: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>';
|
2011-02-03 01:14:23 +01:00
|
|
|
}
|
2011-07-09 18:45:19 +02:00
|
|
|
|
|
|
|
return implode("\n", $result);
|
2011-02-03 01:14:23 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-03 01:14:23 +01:00
|
|
|
public function willShutdown() {
|
2012-07-17 21:06:25 +02:00
|
|
|
if (DarkConsoleXHProfPluginAPI::isProfilerRequested() &&
|
|
|
|
(DarkConsoleXHProfPluginAPI::isProfilerRequested() !== 'all')) {
|
2011-02-03 01:14:23 +01:00
|
|
|
$this->xhprofID = DarkConsoleXHProfPluginAPI::stopProfiler();
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|