From 4aba4ddb2c938b930541909f023792af27332d31 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 19 Nov 2013 14:10:45 -0800 Subject: [PATCH] Cascade DarkConsole query plan analyzer to Ajax requests Summary: Fixes T4123. If you click "Profile" on a page, we already profile all the ajax requests it generates. Do the same for "Analyze Query Plans". Test Plan: Viewed a page with Ajax requests using "Analyze Query Plans", and not using "Analyze Query Plans". Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4123 Differential Revision: https://secure.phabricator.com/D7601 --- .../plugin/DarkConsoleServicesPlugin.php | 23 +++++++++++++++++-- src/view/page/PhabricatorStandardPageView.php | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/aphront/console/plugin/DarkConsoleServicesPlugin.php b/src/aphront/console/plugin/DarkConsoleServicesPlugin.php index 3005c94b0d..38538f0564 100644 --- a/src/aphront/console/plugin/DarkConsoleServicesPlugin.php +++ b/src/aphront/console/plugin/DarkConsoleServicesPlugin.php @@ -15,17 +15,36 @@ final class DarkConsoleServicesPlugin extends DarkConsolePlugin { return 'Information about services.'; } + public static function getQueryAnalyzerHeader() { + return 'X-Phabricator-QueryAnalyzer'; + } + + public static function isQueryAnalyzerRequested() { + if (!empty($_REQUEST['__analyze__'])) { + return true; + } + + $header = AphrontRequest::getHTTPHeader(self::getQueryAnalyzerHeader()); + if ($header) { + return true; + } + + return false; + } + /** * @phutil-external-symbol class PhabricatorStartup */ public function generateData() { + $should_analyze = self::isQueryAnalyzerRequested(); + $log = PhutilServiceProfiler::getInstance()->getServiceCallLog(); foreach ($log as $key => $entry) { $config = idx($entry, 'config', array()); unset($log[$key]['config']); - if (empty($_REQUEST['__analyze__'])) { + if (!$should_analyze) { $log[$key]['explain'] = array( 'sev' => 7, 'size' => null, @@ -139,7 +158,7 @@ final class DarkConsoleServicesPlugin extends DarkConsolePlugin { 'analyzeURI' => (string)$this ->getRequestURI() ->alter('__analyze__', true), - 'didAnalyze' => isset($_REQUEST['__analyze__']), + 'didAnalyze' => $should_analyze, ); } diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php index f01d2ccd92..ee639564b2 100644 --- a/src/view/page/PhabricatorStandardPageView.php +++ b/src/view/page/PhabricatorStandardPageView.php @@ -185,6 +185,9 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView { if (DarkConsoleXHProfPluginAPI::isProfilerStarted()) { $headers[DarkConsoleXHProfPluginAPI::getProfilerHeader()] = 'page'; } + if (DarkConsoleServicesPlugin::isQueryAnalyzerRequested()) { + $headers[DarkConsoleServicesPlugin::getQueryAnalyzerHeader()] = true; + } Javelin::initBehavior( 'dark-console', -- 2.51.2