mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +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 {
|
||||
|
||||
protected $xhprofID;
|
||||
protected $xhprofData;
|
||||
|
||||
public function getName() {
|
||||
$run = $this->getData();
|
||||
|
@ -50,7 +49,39 @@ class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
|
|||
'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>;
|
||||
}
|
||||
|
||||
public function willShutdown() {
|
||||
if (empty($_REQUEST['_profile_']) ||
|
||||
$_REQUEST['_profile_'] != 'complete') {
|
||||
require_module('profiling/phprof/bootstrap');
|
||||
$this->xhprofData = FB_HotProfiler::stop_hotprofiler();
|
||||
}
|
||||
}
|
||||
|
||||
public function didShutdown() {
|
||||
if ($this->xhprofData) {
|
||||
require_module_lazy('profiling/phprof');
|
||||
|
|
|
@ -36,15 +36,11 @@ final class DarkConsoleXHProfPluginAPI {
|
|||
require_once $root.'/externals/xhprof/xhprof_lib.php';
|
||||
}
|
||||
|
||||
public static function hookProfiler($section) {
|
||||
public static function hookProfiler() {
|
||||
if (empty($_REQUEST['__profile__'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($section != $_REQUEST['__profile__']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self::isProfilerAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,11 @@ class PhabricatorXHProfProfileSymbolView extends AphrontView {
|
|||
$children = array();
|
||||
$parents = array();
|
||||
foreach ($this->profileData as $key => $counters) {
|
||||
if (strpos($key, '==>') !== false) {
|
||||
list($parent, $child) = explode('==>', $key, 2);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if ($parent == $symbol) {
|
||||
$children[$key] = $child;
|
||||
} else if ($child == $symbol) {
|
||||
|
|
|
@ -35,7 +35,7 @@ phutil_require_module('phabricator', 'infrastructure/env');
|
|||
PhabricatorEnv::setEnvConfig($conf);
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/console/plugin/xhprof/api');
|
||||
DarkConsoleXHProfPluginAPI::hookProfiler('all');
|
||||
DarkConsoleXHProfPluginAPI::hookProfiler();
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$path = $_REQUEST['__path__'];
|
||||
|
@ -91,12 +91,20 @@ foreach ($headers as $header) {
|
|||
if (isset($_REQUEST['__profile__']) &&
|
||||
($_REQUEST['__profile__'] == 'all')) {
|
||||
$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) {
|
||||
$response_string = str_replace(
|
||||
'<body>',
|
||||
'<body>'.$profile,
|
||||
$response_string);
|
||||
} else {
|
||||
echo $profile;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue