mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Very slightly less terrible XHProf implementation.
This commit is contained in:
parent
9fbb0cc40a
commit
a5c0c277ca
4 changed files with 50 additions and 19 deletions
|
@ -19,7 +19,6 @@
|
||||||
class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
|
class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
|
||||||
|
|
||||||
protected $xhprofID;
|
protected $xhprofID;
|
||||||
protected $xhprofData;
|
|
||||||
|
|
||||||
public function getName() {
|
public function getName() {
|
||||||
$run = $this->getData();
|
$run = $this->getData();
|
||||||
|
@ -50,7 +49,39 @@ class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
|
||||||
'to enable the XHProf plugin.';
|
'to enable the XHProf plugin.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '...';
|
$run = $this->getXHProfRunID();
|
||||||
|
if ($run) {
|
||||||
|
return '<a href="/xhprof/profile/'.$run.'/">View Run</a>';
|
||||||
|
} else {
|
||||||
|
$hidden = array();
|
||||||
|
$data = array('__profile__' => 'page') + $_GET;
|
||||||
|
|
||||||
|
foreach ($data as $k => $v) {
|
||||||
|
$hidden[] = phutil_render_tag(
|
||||||
|
'input',
|
||||||
|
array(
|
||||||
|
'type' => 'hidden',
|
||||||
|
'name' => $k,
|
||||||
|
'value' => $v,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$hidden = implode("\n", $hidden);
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
'<form method="get">'.
|
||||||
|
$hidden.
|
||||||
|
'<button>Enable XHProf</button>'.
|
||||||
|
'</form>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function willShutdown() {
|
||||||
|
if (isset($_REQUEST['__profile__']) &&
|
||||||
|
$_REQUEST['__profile__'] != 'all') {
|
||||||
|
$this->xhprofID = DarkConsoleXHProfPluginAPI::stopProfiler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -93,14 +124,6 @@ class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
|
||||||
</x:frag>;
|
</x:frag>;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function willShutdown() {
|
|
||||||
if (empty($_REQUEST['_profile_']) ||
|
|
||||||
$_REQUEST['_profile_'] != 'complete') {
|
|
||||||
require_module('profiling/phprof/bootstrap');
|
|
||||||
$this->xhprofData = FB_HotProfiler::stop_hotprofiler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function didShutdown() {
|
public function didShutdown() {
|
||||||
if ($this->xhprofData) {
|
if ($this->xhprofData) {
|
||||||
require_module_lazy('profiling/phprof');
|
require_module_lazy('profiling/phprof');
|
||||||
|
|
|
@ -36,15 +36,11 @@ final class DarkConsoleXHProfPluginAPI {
|
||||||
require_once $root.'/externals/xhprof/xhprof_lib.php';
|
require_once $root.'/externals/xhprof/xhprof_lib.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function hookProfiler($section) {
|
public static function hookProfiler() {
|
||||||
if (empty($_REQUEST['__profile__'])) {
|
if (empty($_REQUEST['__profile__'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($section != $_REQUEST['__profile__']) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!self::isProfilerAvailable()) {
|
if (!self::isProfilerAvailable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,11 @@ class PhabricatorXHProfProfileSymbolView extends AphrontView {
|
||||||
$children = array();
|
$children = array();
|
||||||
$parents = array();
|
$parents = array();
|
||||||
foreach ($this->profileData as $key => $counters) {
|
foreach ($this->profileData as $key => $counters) {
|
||||||
|
if (strpos($key, '==>') !== false) {
|
||||||
list($parent, $child) = explode('==>', $key, 2);
|
list($parent, $child) = explode('==>', $key, 2);
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($parent == $symbol) {
|
if ($parent == $symbol) {
|
||||||
$children[$key] = $child;
|
$children[$key] = $child;
|
||||||
} else if ($child == $symbol) {
|
} else if ($child == $symbol) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
PhabricatorEnv::setEnvConfig($conf);
|
PhabricatorEnv::setEnvConfig($conf);
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'aphront/console/plugin/xhprof/api');
|
phutil_require_module('phabricator', 'aphront/console/plugin/xhprof/api');
|
||||||
DarkConsoleXHProfPluginAPI::hookProfiler('all');
|
DarkConsoleXHProfPluginAPI::hookProfiler();
|
||||||
|
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
$path = $_REQUEST['__path__'];
|
$path = $_REQUEST['__path__'];
|
||||||
|
@ -91,12 +91,20 @@ foreach ($headers as $header) {
|
||||||
if (isset($_REQUEST['__profile__']) &&
|
if (isset($_REQUEST['__profile__']) &&
|
||||||
($_REQUEST['__profile__'] == 'all')) {
|
($_REQUEST['__profile__'] == 'all')) {
|
||||||
$profile = DarkConsoleXHProfPluginAPI::stopProfiler();
|
$profile = DarkConsoleXHProfPluginAPI::stopProfiler();
|
||||||
$profile = print_r($profile, true);
|
$profile =
|
||||||
|
'<div style="text-align: center; background: #ff00ff; padding: 1em;
|
||||||
|
font-size: 24px; font-weight: bold;">'.
|
||||||
|
'<a href="/xhprof/profile/'.$profile.'/">'.
|
||||||
|
'>>> View Profile <<<'.
|
||||||
|
'</a>'.
|
||||||
|
'</div>';
|
||||||
if (strpos($response_string, '<body>') !== false) {
|
if (strpos($response_string, '<body>') !== false) {
|
||||||
$response_string = str_replace(
|
$response_string = str_replace(
|
||||||
'<body>',
|
'<body>',
|
||||||
'<body>'.$profile,
|
'<body>'.$profile,
|
||||||
$response_string);
|
$response_string);
|
||||||
|
} else {
|
||||||
|
echo $profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue