mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
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
This commit is contained in:
parent
ad032e72ca
commit
4254702271
5 changed files with 184 additions and 88 deletions
|
@ -4132,6 +4132,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorXHProfProfileView' => 'applications/xhprof/view/PhabricatorXHProfProfileView.php',
|
||||
'PhabricatorXHProfSample' => 'applications/xhprof/storage/PhabricatorXHProfSample.php',
|
||||
'PhabricatorXHProfSampleListController' => 'applications/xhprof/controller/PhabricatorXHProfSampleListController.php',
|
||||
'PhabricatorXHProfSampleQuery' => 'applications/xhprof/query/PhabricatorXHProfSampleQuery.php',
|
||||
'PhabricatorXHProfSampleSearchEngine' => 'applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php',
|
||||
'PhabricatorYoutubeRemarkupRule' => 'infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php',
|
||||
'Phame404Response' => 'applications/phame/site/Phame404Response.php',
|
||||
'PhameBlog' => 'applications/phame/storage/PhameBlog.php',
|
||||
|
@ -9442,8 +9444,13 @@ phutil_register_library_map(array(
|
|||
'PhabricatorXHProfProfileSymbolView' => 'PhabricatorXHProfProfileView',
|
||||
'PhabricatorXHProfProfileTopLevelView' => 'PhabricatorXHProfProfileView',
|
||||
'PhabricatorXHProfProfileView' => 'AphrontView',
|
||||
'PhabricatorXHProfSample' => 'PhabricatorXHProfDAO',
|
||||
'PhabricatorXHProfSample' => array(
|
||||
'PhabricatorXHProfDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorXHProfSampleListController' => 'PhabricatorXHProfController',
|
||||
'PhabricatorXHProfSampleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorXHProfSampleSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorYoutubeRemarkupRule' => 'PhutilRemarkupRule',
|
||||
'Phame404Response' => 'AphrontHTMLResponse',
|
||||
'PhameBlog' => array(
|
||||
|
|
|
@ -8,91 +8,9 @@ final class PhabricatorXHProfSampleListController
|
|||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$view = $request->getURIData('view');
|
||||
|
||||
if (!$view) {
|
||||
$view = 'all';
|
||||
}
|
||||
|
||||
$pager = new PHUIPagerView();
|
||||
$pager->setOffset($request->getInt('page'));
|
||||
|
||||
switch ($view) {
|
||||
case 'sampled':
|
||||
$clause = 'sampleRate > 0';
|
||||
$show_type = false;
|
||||
break;
|
||||
case 'my-runs':
|
||||
$clause = qsprintf(
|
||||
id(new PhabricatorXHProfSample())->establishConnection('r'),
|
||||
'sampleRate = 0 AND userPHID = %s',
|
||||
$request->getUser()->getPHID());
|
||||
$show_type = false;
|
||||
break;
|
||||
case 'manual':
|
||||
$clause = 'sampleRate = 0';
|
||||
$show_type = false;
|
||||
break;
|
||||
case 'all':
|
||||
default:
|
||||
$clause = '1 = 1';
|
||||
$show_type = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$samples = id(new PhabricatorXHProfSample())->loadAllWhere(
|
||||
'%Q ORDER BY id DESC LIMIT %d, %d',
|
||||
$clause,
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
|
||||
$samples = $pager->sliceResults($samples);
|
||||
$pager->setURI($request->getRequestURI(), 'page');
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
foreach ($samples as $sample) {
|
||||
$file_phid = $sample->getFilePHID();
|
||||
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setObjectName($sample->getID())
|
||||
->setHeader($sample->getRequestPath())
|
||||
->setHref($this->getApplicationURI('profile/'.$file_phid.'/'))
|
||||
->addAttribute(
|
||||
number_format($sample->getUsTotal())." \xCE\xBCs");
|
||||
|
||||
if ($sample->getController()) {
|
||||
$item->addAttribute($sample->getController());
|
||||
}
|
||||
|
||||
$item->addAttribute($sample->getHostName());
|
||||
|
||||
$rate = $sample->getSampleRate();
|
||||
if ($rate == 0) {
|
||||
$item->addIcon('flag-6', pht('Manual Run'));
|
||||
} else {
|
||||
$item->addIcon('flag-7', pht('Sampled (1/%d)', $rate));
|
||||
}
|
||||
|
||||
$item->addIcon(
|
||||
'none',
|
||||
phabricator_datetime($sample->getDateCreated(), $viewer));
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$list->setPager($pager);
|
||||
$list->setNoDataString(pht('There are no profiling samples.'));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(pht('XHProf Samples'));
|
||||
|
||||
$title = pht('XHProf Samples');
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($title)
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild($list);
|
||||
|
||||
return id(new PhabricatorXHProfSampleSearchEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorXHProfSampleQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function newResultObject() {
|
||||
return new PhabricatorXHProfSample();
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
return $this->loadStandardPage($this->newResultObject());
|
||||
}
|
||||
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
return 'PhabricatorXHProfApplication';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorXHProfSampleSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
public function getResultTypeDescription() {
|
||||
return pht('XHProf Samples');
|
||||
}
|
||||
|
||||
public function getApplicationClassName() {
|
||||
return 'PhabricatorXHProfApplication';
|
||||
}
|
||||
|
||||
public function newQuery() {
|
||||
return id(new PhabricatorXHProfSampleQuery());
|
||||
}
|
||||
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function buildCustomSearchFields() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/xhprof/'.$path;
|
||||
}
|
||||
|
||||
protected function getBuiltinQueryNames() {
|
||||
$names = array(
|
||||
'all' => pht('All Samples'),
|
||||
);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromBuiltin($query_key) {
|
||||
$query = $this->newSavedQuery();
|
||||
$query->setQueryKey($query_key);
|
||||
|
||||
switch ($query_key) {
|
||||
case 'all':
|
||||
return $query;
|
||||
}
|
||||
|
||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
}
|
||||
|
||||
protected function renderResultList(
|
||||
array $samples,
|
||||
PhabricatorSavedQuery $query,
|
||||
array $handles) {
|
||||
assert_instances_of($samples, 'PhabricatorXHProfSample');
|
||||
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
foreach ($samples as $sample) {
|
||||
$file_phid = $sample->getFilePHID();
|
||||
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setObjectName($sample->getID())
|
||||
->setHeader($sample->getRequestPath())
|
||||
->setHref($this->getApplicationURI('profile/'.$file_phid.'/'))
|
||||
->addAttribute(
|
||||
number_format($sample->getUsTotal())." \xCE\xBCs");
|
||||
|
||||
if ($sample->getController()) {
|
||||
$item->addAttribute($sample->getController());
|
||||
}
|
||||
|
||||
$item->addAttribute($sample->getHostName());
|
||||
|
||||
$rate = $sample->getSampleRate();
|
||||
if ($rate == 0) {
|
||||
$item->addIcon('flag-6', pht('Manual Run'));
|
||||
} else {
|
||||
$item->addIcon('flag-7', pht('Sampled (1/%d)', $rate));
|
||||
}
|
||||
|
||||
$item->addIcon(
|
||||
'none',
|
||||
phabricator_datetime($sample->getDateCreated(), $viewer));
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$result = new PhabricatorApplicationSearchResultView();
|
||||
$result->setObjectList($list);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorXHProfSample extends PhabricatorXHProfDAO {
|
||||
final class PhabricatorXHProfSample
|
||||
extends PhabricatorXHProfDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
protected $filePHID;
|
||||
protected $usTotal;
|
||||
|
@ -29,4 +31,25 @@ final class PhabricatorXHProfSample extends PhabricatorXHProfDAO {
|
|||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
||||
public function getCapabilities() {
|
||||
return array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
);
|
||||
}
|
||||
|
||||
public function getPolicy($capability) {
|
||||
switch ($capability) {
|
||||
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||
return PhabricatorPolicies::getMostOpenPolicy();
|
||||
}
|
||||
}
|
||||
|
||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue