@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<?php
2
3final class PhabricatorXHProfSampleSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 public function getResultTypeDescription() {
7 return pht('XHProf Samples');
8 }
9
10 public function getApplicationClassName() {
11 return PhabricatorXHProfApplication::class;
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 /**
53 * @param array<PhabricatorXHProfSample> $samples
54 * @param PhabricatorSavedQuery $query
55 * @param array<PhabricatorObjectHandle> $handles
56 */
57 protected function renderResultList(
58 array $samples,
59 PhabricatorSavedQuery $query,
60 array $handles) {
61 assert_instances_of($samples, PhabricatorXHProfSample::class);
62
63 $viewer = $this->requireViewer();
64
65 $list = new PHUIObjectItemListView();
66 foreach ($samples as $sample) {
67 $file_phid = $sample->getFilePHID();
68
69 $item = id(new PHUIObjectItemView())
70 ->setObjectName($sample->getID())
71 ->setHeader($sample->getDisplayName())
72 ->setHref($sample->getURI());
73
74 $us_total = $sample->getUsTotal();
75 if ($us_total) {
76 $item->addAttribute(pht("%s \xCE\xBCs", new PhutilNumber($us_total)));
77 }
78
79 if ($sample->getController()) {
80 $item->addAttribute($sample->getController());
81 }
82
83 $item->addAttribute($sample->getHostName());
84
85 $rate = $sample->getSampleRate();
86 if ($rate == 0) {
87 $item->addIcon('flag-6', pht('Manual Run'));
88 } else {
89 $item->addIcon('flag-7', pht('Sampled (1/%d)', $rate));
90 }
91
92 $item->addIcon(
93 'none',
94 phabricator_datetime($sample->getDateCreated(), $viewer));
95
96 $list->addItem($item);
97 }
98
99 return $this->newResultView()
100 ->setObjectList($list);
101 }
102
103
104 private function newResultView($content = null) {
105 // If we aren't rendering a dashboard panel, activate global drag-and-drop
106 // so you can import profiles by dropping them into the list.
107
108 if (!$this->isPanelContext()) {
109 $drop_upload = id(new PhabricatorGlobalUploadTargetView())
110 ->setViewer($this->requireViewer())
111 ->setHintText("\xE2\x87\xAA ".pht('Drop .xhprof Files to Import'))
112 ->setSubmitURI('/xhprof/import/drop/')
113 ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE);
114
115 $content = array(
116 $drop_upload,
117 $content,
118 );
119 }
120
121 return id(new PhabricatorApplicationSearchResultView())
122 ->setContent($content);
123 }
124
125}