1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

When a page is profiled, profile all AJAX requests too

Summary: If a page is profiled, add an "X-Phabricator-Profiler" header to all Ajax requests, and profile those too.

Test Plan: Profiled a page, checked Darkconsole, saw profiles for everything.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4885
This commit is contained in:
epriestley 2013-02-09 13:29:47 -08:00
parent 27a537c15f
commit f5827871d5
5 changed files with 35 additions and 6 deletions

View file

@ -1174,7 +1174,7 @@ celerity_register_resource_map(array(
),
'javelin-behavior-dark-console' =>
array(
'uri' => '/res/ae7f15ce/rsrc/js/application/core/behavior-dark-console.js',
'uri' => '/res/89aeb6c0/rsrc/js/application/core/behavior-dark-console.js',
'type' => 'js',
'requires' =>
array(
@ -3488,7 +3488,7 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/bc0774e5/core.pkg.js',
'type' => 'js',
),
'3e0098ea' =>
'dca4a03d' =>
array(
'name' => 'darkconsole.pkg.js',
'symbols' =>
@ -3496,7 +3496,7 @@ celerity_register_resource_map(array(
0 => 'javelin-behavior-dark-console',
1 => 'javelin-behavior-error-log',
),
'uri' => '/res/pkg/3e0098ea/darkconsole.pkg.js',
'uri' => '/res/pkg/dca4a03d/darkconsole.pkg.js',
'type' => 'js',
),
'8aaacd1b' =>
@ -3666,7 +3666,7 @@ celerity_register_resource_map(array(
'javelin-behavior-aphront-drag-and-drop-textarea' => '95d0d865',
'javelin-behavior-aphront-form-disable-on-submit' => 'bc0774e5',
'javelin-behavior-audit-preview' => 'f96657b8',
'javelin-behavior-dark-console' => '3e0098ea',
'javelin-behavior-dark-console' => 'dca4a03d',
'javelin-behavior-device' => 'bc0774e5',
'javelin-behavior-differential-accept-with-errors' => '95d0d865',
'javelin-behavior-differential-add-reviewers-and-ccs' => '95d0d865',
@ -3682,7 +3682,7 @@ celerity_register_resource_map(array(
'javelin-behavior-differential-user-select' => '95d0d865',
'javelin-behavior-diffusion-commit-graph' => 'f96657b8',
'javelin-behavior-diffusion-pull-lastmodified' => 'f96657b8',
'javelin-behavior-error-log' => '3e0098ea',
'javelin-behavior-error-log' => 'dca4a03d',
'javelin-behavior-global-drag-and-drop' => 'bc0774e5',
'javelin-behavior-konami' => 'bc0774e5',
'javelin-behavior-lightbox-attachments' => 'bc0774e5',

View file

@ -13,11 +13,23 @@ final class DarkConsoleXHProfPluginAPI {
return extension_loaded('xhprof');
}
public static function getProfilerHeader() {
return 'X-Phabricator-Profiler';
}
public static function isProfilerRequested() {
if (!empty($_REQUEST['__profile__'])) {
return $_REQUEST['__profile__'];
}
$header = self::getProfilerHeader();
$header = strtoupper($header);
$header = str_replace('-', '_', $header);
$header = 'HTTP_'.$header;
if (!empty($_SERVER[$header])) {
return $_SERVER[$header];
}
static $profilerRequested = null;
if (!isset($profilerRequested)) {

View file

@ -147,6 +147,7 @@ final class CelerityStaticResourceResponse {
$higher_priority_names = array(
'refresh-csrf',
'aphront-basic-tokenizer',
'dark-console',
);
$higher_priority_behaviors = array_select_keys(

View file

@ -161,12 +161,19 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView {
if ($console) {
require_celerity_resource('aphront-dark-console-css');
$headers = array();
if (DarkConsoleXHProfPluginAPI::isProfilerRequested()) {
$headers[DarkConsoleXHProfPluginAPI::getProfilerHeader()] = 'page';
}
Javelin::initBehavior(
'dark-console',
array(
'uri' => $request ? (string)$request->getRequestURI() : '?',
'selected' => $user ? $user->getConsoleTab() : null,
'visible' => $user ? (int)$user->getConsoleVisible() : true,
'headers' => $headers,
));
// Change this to initBehavior when there is some behavior to initialize

View file

@ -14,7 +14,6 @@ JX.behavior('dark-console', function(config, statics) {
config.key = config.key || root.getAttribute('data-console-key');
add_request(config);
// Do first-time setup.
function setup_console() {
statics.root = JX.$('darkconsole');
@ -42,6 +41,16 @@ JX.behavior('dark-console', function(config, statics) {
install_shortcut();
if (config.headers) {
// If the main page had profiling enabled, also enable it for any Ajax
// requests.
JX.Request.listen('open', function(r) {
for (var k in config.headers) {
r.getTransport().setRequestHeader(k, config.headers[k]);
}
});
}
return statics.root;
}