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

113 lines
3 KiB
PHP
Raw Normal View History

2011-02-02 22:48:52 +01:00
<?php
/*
* Copyright 2012 Facebook, Inc.
2011-02-02 22:48:52 +01:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 (isset($_REQUEST['__profile__']) &&
$_REQUEST['__profile__'] != 'all') {
$this->xhprofID = DarkConsoleXHProfPluginAPI::stopProfiler();
}
2011-02-02 22:48:52 +01:00
}
}