diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e9699616d7..86abdb27d0 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -778,6 +778,7 @@ phutil_register_library_map(array( 'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/profile', 'PhabricatorXHProfProfileSymbolView' => 'applications/xhprof/view/symbol', 'PhabricatorXHProfProfileTopLevelView' => 'applications/xhprof/view/toplevel', + 'PhabricatorXHProfProfileView' => 'applications/xhprof/view/base', 'PhrictionActionConstants' => 'applications/phriction/constants/action', 'PhrictionChangeType' => 'applications/phriction/constants/changetype', 'PhrictionConstants' => 'applications/phriction/constants/base', @@ -1448,8 +1449,9 @@ phutil_register_library_map(array( 'PhabricatorXHPASTViewTreeController' => 'PhabricatorXHPASTViewPanelController', 'PhabricatorXHProfController' => 'PhabricatorController', 'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController', - 'PhabricatorXHProfProfileSymbolView' => 'AphrontView', - 'PhabricatorXHProfProfileTopLevelView' => 'AphrontView', + 'PhabricatorXHProfProfileSymbolView' => 'PhabricatorXHProfProfileView', + 'PhabricatorXHProfProfileTopLevelView' => 'PhabricatorXHProfProfileView', + 'PhabricatorXHProfProfileView' => 'AphrontView', 'PhrictionActionConstants' => 'PhrictionConstants', 'PhrictionChangeType' => 'PhrictionConstants', 'PhrictionContent' => 'PhrictionDAO', diff --git a/src/applications/xhprof/controller/profile/PhabricatorXHProfProfileController.php b/src/applications/xhprof/controller/profile/PhabricatorXHProfProfileController.php index cf0b954d7d..b2ee553fb3 100644 --- a/src/applications/xhprof/controller/profile/PhabricatorXHProfProfileController.php +++ b/src/applications/xhprof/controller/profile/PhabricatorXHProfProfileController.php @@ -1,7 +1,7 @@ getRequest(); $symbol = $request->getStr('symbol'); + $is_framed = $request->getBool('frame'); + if ($symbol) { $view = new PhabricatorXHProfProfileSymbolView(); - $view->setProfileData($data); $view->setSymbol($symbol); } else { $view = new PhabricatorXHProfProfileTopLevelView(); - $view->setProfileData($data); $view->setLimit(100); } + $view->setBaseURI($request->getRequestURI()->getPath()); + $view->setIsFramed($is_framed); + $view->setProfileData($data); + return $this->buildStandardPageResponse( $view, array( 'title' => 'Profile', - 'frame' => $request->getBool('frame'), + 'frame' => $is_framed, )); } } diff --git a/src/applications/xhprof/view/base/PhabricatorXHProfProfileView.php b/src/applications/xhprof/view/base/PhabricatorXHProfProfileView.php new file mode 100644 index 0000000000..9282c9e649 --- /dev/null +++ b/src/applications/xhprof/view/base/PhabricatorXHProfProfileView.php @@ -0,0 +1,44 @@ +isFramed = $is_framed; + return $this; + } + + public function setBaseURI($uri) { + $this->baseURI = $uri; + return $this; + } + + protected function renderSymbolLink($symbol) { + return phutil_render_tag( + 'a', + array( + 'href' => $this->baseURI.'?symbol='.$symbol, + 'target' => $this->isFramed ? '_top' : null, + ), + phutil_escape_html($symbol)); + } + +} diff --git a/src/applications/xhprof/view/base/__init__.php b/src/applications/xhprof/view/base/__init__.php new file mode 100644 index 0000000000..678958cefb --- /dev/null +++ b/src/applications/xhprof/view/base/__init__.php @@ -0,0 +1,14 @@ +baseURI = $uri; - return $this; - } - public function setSymbol($symbol) { $this->symbol = $symbol; return $this; @@ -67,8 +62,6 @@ class PhabricatorXHProfProfileSymbolView extends AphrontView { } } - $base_uri = $this->baseURI; - $rows = array(); $rows[] = array( 'Metrics for this Call', @@ -77,12 +70,7 @@ class PhabricatorXHProfProfileSymbolView extends AphrontView { '', ); $rows[] = array( - phutil_render_tag( - 'a', - array( - 'href' => $base_uri.'?symbol='.$symbol, - ), - phutil_escape_html($symbol)), + $this->renderSymbolLink($symbol), $flat[$symbol]['ct'], $flat[$symbol]['wt'], '100%', @@ -96,12 +84,7 @@ class PhabricatorXHProfProfileSymbolView extends AphrontView { ); foreach ($parents as $key => $name) { $rows[] = array( - phutil_render_tag( - 'a', - array( - 'href' => $base_uri.'?symbol='.$name, - ), - phutil_escape_html($name)), + $this->renderSymbolLink($name), $data[$key]['ct'], $data[$key]['wt'], '', @@ -152,17 +135,10 @@ class PhabricatorXHProfProfileSymbolView extends AphrontView { } private function formatRows($rows) { - $base_uri = $this->baseURI; - $result = array(); foreach ($rows as $row) { $result[] = array( - phutil_render_tag( - 'a', - array( - 'href' => $base_uri.'?symbol='.$row[0], - ), - phutil_escape_html($row[0])), + $this->renderSymbolLink($row[0]), number_format($row[1]), number_format($row[2]).' us', sprintf('%.1f%%', 100 * $row[3]), diff --git a/src/applications/xhprof/view/symbol/__init__.php b/src/applications/xhprof/view/symbol/__init__.php index 3ff4e39d21..2fd51c53b2 100644 --- a/src/applications/xhprof/view/symbol/__init__.php +++ b/src/applications/xhprof/view/symbol/__init__.php @@ -7,11 +7,10 @@ phutil_require_module('phabricator', 'aphront/console/plugin/xhprof/api'); -phutil_require_module('phabricator', 'view/base'); +phutil_require_module('phabricator', 'applications/xhprof/view/base'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); -phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/xhprof/view/toplevel/PhabricatorXHProfProfileTopLevelView.php b/src/applications/xhprof/view/toplevel/PhabricatorXHProfProfileTopLevelView.php index 3806719280..cdeb8c6b29 100644 --- a/src/applications/xhprof/view/toplevel/PhabricatorXHProfProfileTopLevelView.php +++ b/src/applications/xhprof/view/toplevel/PhabricatorXHProfProfileTopLevelView.php @@ -19,11 +19,11 @@ /** * @phutil-external-symbol function xhprof_compute_flat_info */ -class PhabricatorXHProfProfileTopLevelView extends AphrontView { +final class PhabricatorXHProfProfileTopLevelView + extends PhabricatorXHProfProfileView { private $profileData; private $limit; - private $baseURI; public function setProfileData(array $data) { $this->profileData = $data; @@ -35,11 +35,6 @@ class PhabricatorXHProfProfileTopLevelView extends AphrontView { return $this; } - public function setBaseURI($uri) { - $this->baseURI = $uri; - return $this; - } - public function render() { DarkConsoleXHProfPluginAPI::includeXHProfLib(); @@ -81,16 +76,9 @@ class PhabricatorXHProfProfileTopLevelView extends AphrontView { $flat = array_slice($flat, 0, $this->limit); } - $base_uri = $this->baseURI; - foreach ($flat as $call => $counters) { $rows[] = array( - phutil_render_tag( - 'a', - array( - 'href' => $base_uri.'?symbol='.$call, - ), - phutil_escape_html($call)), + $this->renderSymbolLink($call), number_format($counters['ct']), number_format($counters['wt']).' us', sprintf('%.1f%%', 100 * $counters['wt'] / $totals['wt']), diff --git a/src/applications/xhprof/view/toplevel/__init__.php b/src/applications/xhprof/view/toplevel/__init__.php index dbd5d1ce25..1602770d0f 100644 --- a/src/applications/xhprof/view/toplevel/__init__.php +++ b/src/applications/xhprof/view/toplevel/__init__.php @@ -7,11 +7,10 @@ phutil_require_module('phabricator', 'aphront/console/plugin/xhprof/api'); -phutil_require_module('phabricator', 'view/base'); +phutil_require_module('phabricator', 'applications/xhprof/view/base'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); -phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils');