@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use ApplicationSearch in XHProf

Summary:
Ref T12297. This slightly modernizes the XHProf UI. Not included here:

- Some of the code acts like samples have PHIDs, but they currently do not. I plan to add them in the next change.
- I've intentionally left the actual list untouched for now -- it has some old/buggy code (like `flag-6` is no longer an icon) that I'll fix in a future change.

Test Plan: {F3224264}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12297

Differential Revision: https://secure.phabricator.com/D17400

+184 -88
+8 -1
src/__phutil_library_map__.php
··· 4132 4132 'PhabricatorXHProfProfileView' => 'applications/xhprof/view/PhabricatorXHProfProfileView.php', 4133 4133 'PhabricatorXHProfSample' => 'applications/xhprof/storage/PhabricatorXHProfSample.php', 4134 4134 'PhabricatorXHProfSampleListController' => 'applications/xhprof/controller/PhabricatorXHProfSampleListController.php', 4135 + 'PhabricatorXHProfSampleQuery' => 'applications/xhprof/query/PhabricatorXHProfSampleQuery.php', 4136 + 'PhabricatorXHProfSampleSearchEngine' => 'applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php', 4135 4137 'PhabricatorYoutubeRemarkupRule' => 'infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php', 4136 4138 'Phame404Response' => 'applications/phame/site/Phame404Response.php', 4137 4139 'PhameBlog' => 'applications/phame/storage/PhameBlog.php', ··· 9442 9444 'PhabricatorXHProfProfileSymbolView' => 'PhabricatorXHProfProfileView', 9443 9445 'PhabricatorXHProfProfileTopLevelView' => 'PhabricatorXHProfProfileView', 9444 9446 'PhabricatorXHProfProfileView' => 'AphrontView', 9445 - 'PhabricatorXHProfSample' => 'PhabricatorXHProfDAO', 9447 + 'PhabricatorXHProfSample' => array( 9448 + 'PhabricatorXHProfDAO', 9449 + 'PhabricatorPolicyInterface', 9450 + ), 9446 9451 'PhabricatorXHProfSampleListController' => 'PhabricatorXHProfController', 9452 + 'PhabricatorXHProfSampleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 9453 + 'PhabricatorXHProfSampleSearchEngine' => 'PhabricatorApplicationSearchEngine', 9447 9454 'PhabricatorYoutubeRemarkupRule' => 'PhutilRemarkupRule', 9448 9455 'Phame404Response' => 'AphrontHTMLResponse', 9449 9456 'PhameBlog' => array(
+4 -86
src/applications/xhprof/controller/PhabricatorXHProfSampleListController.php
··· 8 8 } 9 9 10 10 public function handleRequest(AphrontRequest $request) { 11 - $viewer = $request->getViewer(); 12 - $view = $request->getURIData('view'); 13 - 14 - if (!$view) { 15 - $view = 'all'; 16 - } 17 - 18 - $pager = new PHUIPagerView(); 19 - $pager->setOffset($request->getInt('page')); 20 - 21 - switch ($view) { 22 - case 'sampled': 23 - $clause = 'sampleRate > 0'; 24 - $show_type = false; 25 - break; 26 - case 'my-runs': 27 - $clause = qsprintf( 28 - id(new PhabricatorXHProfSample())->establishConnection('r'), 29 - 'sampleRate = 0 AND userPHID = %s', 30 - $request->getUser()->getPHID()); 31 - $show_type = false; 32 - break; 33 - case 'manual': 34 - $clause = 'sampleRate = 0'; 35 - $show_type = false; 36 - break; 37 - case 'all': 38 - default: 39 - $clause = '1 = 1'; 40 - $show_type = true; 41 - break; 42 - } 43 - 44 - $samples = id(new PhabricatorXHProfSample())->loadAllWhere( 45 - '%Q ORDER BY id DESC LIMIT %d, %d', 46 - $clause, 47 - $pager->getOffset(), 48 - $pager->getPageSize() + 1); 49 - 50 - $samples = $pager->sliceResults($samples); 51 - $pager->setURI($request->getRequestURI(), 'page'); 52 - 53 - $list = new PHUIObjectItemListView(); 54 - foreach ($samples as $sample) { 55 - $file_phid = $sample->getFilePHID(); 56 - 57 - $item = id(new PHUIObjectItemView()) 58 - ->setObjectName($sample->getID()) 59 - ->setHeader($sample->getRequestPath()) 60 - ->setHref($this->getApplicationURI('profile/'.$file_phid.'/')) 61 - ->addAttribute( 62 - number_format($sample->getUsTotal())." \xCE\xBCs"); 11 + return id(new PhabricatorXHProfSampleSearchEngine()) 12 + ->setController($this) 13 + ->buildResponse(); 14 + } 63 15 64 - if ($sample->getController()) { 65 - $item->addAttribute($sample->getController()); 66 - } 67 - 68 - $item->addAttribute($sample->getHostName()); 69 - 70 - $rate = $sample->getSampleRate(); 71 - if ($rate == 0) { 72 - $item->addIcon('flag-6', pht('Manual Run')); 73 - } else { 74 - $item->addIcon('flag-7', pht('Sampled (1/%d)', $rate)); 75 - } 76 - 77 - $item->addIcon( 78 - 'none', 79 - phabricator_datetime($sample->getDateCreated(), $viewer)); 80 - 81 - $list->addItem($item); 82 - } 83 - 84 - $list->setPager($pager); 85 - $list->setNoDataString(pht('There are no profiling samples.')); 86 - 87 - $crumbs = $this->buildApplicationCrumbs(); 88 - $crumbs->addTextCrumb(pht('XHProf Samples')); 89 - 90 - $title = pht('XHProf Samples'); 91 - 92 - return $this->newPage() 93 - ->setTitle($title) 94 - ->setCrumbs($crumbs) 95 - ->appendChild($list); 96 - 97 - } 98 16 }
+51
src/applications/xhprof/query/PhabricatorXHProfSampleQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorXHProfSampleQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 5 + 6 + private $ids; 7 + private $phids; 8 + 9 + public function withIDs(array $ids) { 10 + $this->ids = $ids; 11 + return $this; 12 + } 13 + 14 + public function withPHIDs(array $phids) { 15 + $this->phids = $phids; 16 + return $this; 17 + } 18 + 19 + public function newResultObject() { 20 + return new PhabricatorXHProfSample(); 21 + } 22 + 23 + protected function loadPage() { 24 + return $this->loadStandardPage($this->newResultObject()); 25 + } 26 + 27 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 28 + $where = parent::buildWhereClauseParts($conn); 29 + 30 + if ($this->ids !== null) { 31 + $where[] = qsprintf( 32 + $conn, 33 + 'id IN (%Ld)', 34 + $this->ids); 35 + } 36 + 37 + if ($this->phids !== null) { 38 + $where[] = qsprintf( 39 + $conn, 40 + 'phid IN (%Ls)', 41 + $this->phids); 42 + } 43 + 44 + return $where; 45 + } 46 + 47 + public function getQueryApplicationClass() { 48 + return 'PhabricatorXHProfApplication'; 49 + } 50 + 51 + }
+97
src/applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorXHProfSampleSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('XHProf Samples'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return 'PhabricatorXHProfApplication'; 12 + } 13 + 14 + public function newQuery() { 15 + return id(new PhabricatorXHProfSampleQuery()); 16 + } 17 + 18 + protected function buildQueryFromParameters(array $map) { 19 + $query = $this->newQuery(); 20 + 21 + return $query; 22 + } 23 + 24 + protected function buildCustomSearchFields() { 25 + return array(); 26 + } 27 + 28 + protected function getURI($path) { 29 + return '/xhprof/'.$path; 30 + } 31 + 32 + protected function getBuiltinQueryNames() { 33 + $names = array( 34 + 'all' => pht('All Samples'), 35 + ); 36 + 37 + return $names; 38 + } 39 + 40 + public function buildSavedQueryFromBuiltin($query_key) { 41 + $query = $this->newSavedQuery(); 42 + $query->setQueryKey($query_key); 43 + 44 + switch ($query_key) { 45 + case 'all': 46 + return $query; 47 + } 48 + 49 + return parent::buildSavedQueryFromBuiltin($query_key); 50 + } 51 + 52 + protected function renderResultList( 53 + array $samples, 54 + PhabricatorSavedQuery $query, 55 + array $handles) { 56 + assert_instances_of($samples, 'PhabricatorXHProfSample'); 57 + 58 + $viewer = $this->requireViewer(); 59 + 60 + $list = new PHUIObjectItemListView(); 61 + foreach ($samples as $sample) { 62 + $file_phid = $sample->getFilePHID(); 63 + 64 + $item = id(new PHUIObjectItemView()) 65 + ->setObjectName($sample->getID()) 66 + ->setHeader($sample->getRequestPath()) 67 + ->setHref($this->getApplicationURI('profile/'.$file_phid.'/')) 68 + ->addAttribute( 69 + number_format($sample->getUsTotal())." \xCE\xBCs"); 70 + 71 + if ($sample->getController()) { 72 + $item->addAttribute($sample->getController()); 73 + } 74 + 75 + $item->addAttribute($sample->getHostName()); 76 + 77 + $rate = $sample->getSampleRate(); 78 + if ($rate == 0) { 79 + $item->addIcon('flag-6', pht('Manual Run')); 80 + } else { 81 + $item->addIcon('flag-7', pht('Sampled (1/%d)', $rate)); 82 + } 83 + 84 + $item->addIcon( 85 + 'none', 86 + phabricator_datetime($sample->getDateCreated(), $viewer)); 87 + 88 + $list->addItem($item); 89 + } 90 + 91 + $result = new PhabricatorApplicationSearchResultView(); 92 + $result->setObjectList($list); 93 + 94 + return $result; 95 + } 96 + 97 + }
+24 -1
src/applications/xhprof/storage/PhabricatorXHProfSample.php
··· 1 1 <?php 2 2 3 - final class PhabricatorXHProfSample extends PhabricatorXHProfDAO { 3 + final class PhabricatorXHProfSample 4 + extends PhabricatorXHProfDAO 5 + implements PhabricatorPolicyInterface { 4 6 5 7 protected $filePHID; 6 8 protected $usTotal; ··· 27 29 ), 28 30 ), 29 31 ) + parent::getConfiguration(); 32 + } 33 + 34 + 35 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 36 + 37 + 38 + public function getCapabilities() { 39 + return array( 40 + PhabricatorPolicyCapability::CAN_VIEW, 41 + ); 42 + } 43 + 44 + public function getPolicy($capability) { 45 + switch ($capability) { 46 + case PhabricatorPolicyCapability::CAN_VIEW: 47 + return PhabricatorPolicies::getMostOpenPolicy(); 48 + } 49 + } 50 + 51 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 52 + return false; 30 53 } 31 54 32 55 }