Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / xhprof / query / PhabricatorXHProfSampleSearchEngine.php
blob171f28f0279da95305c8458672c03e06a027f214
1 <?php
3 final class PhabricatorXHProfSampleSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('XHProf Samples');
10 public function getApplicationClassName() {
11 return 'PhabricatorXHProfApplication';
14 public function newQuery() {
15 return id(new PhabricatorXHProfSampleQuery());
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 return $query;
24 protected function buildCustomSearchFields() {
25 return array();
28 protected function getURI($path) {
29 return '/xhprof/'.$path;
32 protected function getBuiltinQueryNames() {
33 $names = array(
34 'all' => pht('All Samples'),
37 return $names;
40 public function buildSavedQueryFromBuiltin($query_key) {
41 $query = $this->newSavedQuery();
42 $query->setQueryKey($query_key);
44 switch ($query_key) {
45 case 'all':
46 return $query;
49 return parent::buildSavedQueryFromBuiltin($query_key);
52 protected function renderResultList(
53 array $samples,
54 PhabricatorSavedQuery $query,
55 array $handles) {
56 assert_instances_of($samples, 'PhabricatorXHProfSample');
58 $viewer = $this->requireViewer();
60 $list = new PHUIObjectItemListView();
61 foreach ($samples as $sample) {
62 $file_phid = $sample->getFilePHID();
64 $item = id(new PHUIObjectItemView())
65 ->setObjectName($sample->getID())
66 ->setHeader($sample->getDisplayName())
67 ->setHref($sample->getURI());
69 $us_total = $sample->getUsTotal();
70 if ($us_total) {
71 $item->addAttribute(pht("%s \xCE\xBCs", new PhutilNumber($us_total)));
74 if ($sample->getController()) {
75 $item->addAttribute($sample->getController());
78 $item->addAttribute($sample->getHostName());
80 $rate = $sample->getSampleRate();
81 if ($rate == 0) {
82 $item->addIcon('flag-6', pht('Manual Run'));
83 } else {
84 $item->addIcon('flag-7', pht('Sampled (1/%d)', $rate));
87 $item->addIcon(
88 'none',
89 phabricator_datetime($sample->getDateCreated(), $viewer));
91 $list->addItem($item);
94 return $this->newResultView()
95 ->setObjectList($list);
99 private function newResultView($content = null) {
100 // If we aren't rendering a dashboard panel, activate global drag-and-drop
101 // so you can import profiles by dropping them into the list.
103 if (!$this->isPanelContext()) {
104 $drop_upload = id(new PhabricatorGlobalUploadTargetView())
105 ->setViewer($this->requireViewer())
106 ->setHintText("\xE2\x87\xAA ".pht('Drop .xhprof Files to Import'))
107 ->setSubmitURI('/xhprof/import/drop/')
108 ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE);
110 $content = array(
111 $drop_upload,
112 $content,
116 return id(new PhabricatorApplicationSearchResultView())
117 ->setContent($content);