@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.

Make Multimeter sample browsing UI a bit more useful

Summary: Ref T6930. Just iterating on this a bit: add some column grouping stuff so you can slice results apart and figure out where they came from.

Test Plan: {F389632}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6930

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

+121 -12
+121 -12
src/applications/multimeter/controller/MultimeterSampleController.php
··· 9 9 public function handleRequest(AphrontRequest $request) { 10 10 $viewer = $this->getViewer(); 11 11 12 + $group_map = array( 13 + 'type' => 'eventType', 14 + 'host' => 'eventHostID', 15 + 'context' => 'eventContextID', 16 + 'viewer' => 'eventViewerID', 17 + 'request' => 'requestKey', 18 + 'label' => 'eventLabelID', 19 + ); 20 + 21 + $group = explode('.', $request->getStr('group')); 22 + $group = array_intersect($group, array_keys($group_map)); 23 + $group = array_fuse($group); 24 + 25 + if (empty($group['type'])) { 26 + $group['type'] = 'type'; 27 + } 28 + 29 + $now = PhabricatorTime::getNow(); 30 + $ago = ($now - phutil_units('24 hours in seconds')); 31 + 12 32 $table = new MultimeterEvent(); 13 33 $conn = $table->establishConnection('r'); 14 34 $data = queryfx_all( 15 35 $conn, 16 - 'SELECT * FROM %T ORDER BY id DESC LIMIT 100', 17 - $table->getTableName()); 36 + 'SELECT *, count(*) N, SUM(sampleRate * resourceCost) as totalCost 37 + FROM %T 38 + WHERE epoch >= %d AND epoch <= %d 39 + GROUP BY %Q 40 + ORDER BY totalCost DESC, MAX(id) DESC 41 + LIMIT 100', 42 + $table->getTableName(), 43 + $ago, 44 + $now, 45 + implode(', ', array_select_keys($group_map, $group))); 18 46 19 47 $this->loadDimensions($data); 20 48 21 49 $rows = array(); 22 50 foreach ($data as $row) { 51 + 52 + if (isset($group['request'])) { 53 + $request_col = $row['requestKey']; 54 + } else { 55 + $request_col = $this->renderGroupingLink($group, 'request'); 56 + } 57 + 58 + if (isset($group['viewer'])) { 59 + $viewer_col = $this->getViewerDimension($row['eventViewerID']) 60 + ->getName(); 61 + } else { 62 + $viewer_col = $this->renderGroupingLink($group, 'viewer'); 63 + } 64 + 65 + if (isset($group['context'])) { 66 + $context_col = $this->getContextDimension($row['eventContextID']) 67 + ->getName(); 68 + } else { 69 + $context_col = $this->renderGroupingLink($group, 'context'); 70 + } 71 + 72 + if (isset($group['host'])) { 73 + $host_col = $this->getHostDimension($row['eventHostID']) 74 + ->getName(); 75 + } else { 76 + $host_col = $this->renderGroupingLink($group, 'host'); 77 + } 78 + 79 + if (isset($group['label'])) { 80 + $label_col = $this->getLabelDimension($row['eventLabelID']) 81 + ->getName(); 82 + } else { 83 + $label_col = $this->renderGroupingLink($group, 'label'); 84 + } 85 + 23 86 $rows[] = array( 24 - $row['id'], 25 - $row['requestKey'], 26 - $this->getViewerDimension($row['eventViewerID'])->getName(), 27 - $this->getContextDimension($row['eventContextID'])->getName(), 28 - $this->getHostDimension($row['eventHostID'])->getName(), 87 + ($row['N'] == 1) 88 + ? $row['id'] 89 + : pht('%s Events', new PhutilNumber($row['N'])), 90 + $request_col, 91 + $viewer_col, 92 + $context_col, 93 + $host_col, 29 94 MultimeterEvent::getEventTypeName($row['eventType']), 30 - $this->getLabelDimension($row['eventLabelID'])->getName(), 95 + $label_col, 31 96 MultimeterEvent::formatResourceCost( 32 97 $viewer, 33 98 $row['eventType'], 34 - $row['resourceCost']), 99 + $row['totalCost']), 35 100 $row['sampleRate'], 36 101 phabricator_datetime($row['epoch'], $viewer), 37 102 ); ··· 53 118 )) 54 119 ->setColumnClasses( 55 120 array( 121 + 'n', 56 122 null, 57 123 null, 58 124 null, 59 125 null, 60 126 null, 61 - null, 62 127 'wide', 63 128 'n', 64 129 'n', ··· 66 131 )); 67 132 68 133 $box = id(new PHUIObjectBoxView()) 69 - ->setHeaderText(pht('Samples')) 134 + ->setHeaderText( 135 + pht( 136 + 'Samples (%s - %s)', 137 + phabricator_datetime($ago, $viewer), 138 + phabricator_datetime($now, $viewer))) 70 139 ->appendChild($table); 71 140 72 141 $crumbs = $this->buildApplicationCrumbs(); 73 - $crumbs->addTextCrumb(pht('Samples')); 142 + $crumbs->addTextCrumb(pht('Samples'), $this->getGroupURI(array())); 143 + 144 + $crumb_map = array( 145 + 'host' => pht('By Host'), 146 + 'context' => pht('By Context'), 147 + 'viewer' => pht('By Viewer'), 148 + 'request' => pht('By Request'), 149 + 'label' => pht('By Label'), 150 + ); 151 + 152 + $parts = array(); 153 + foreach ($group as $item) { 154 + if ($item == 'type') { 155 + continue; 156 + } 157 + $parts[$item] = $item; 158 + $crumbs->addTextCrumb( 159 + idx($crumb_map, $item, $item), 160 + $this->getGroupURI($parts)); 161 + } 74 162 75 163 return $this->buildApplicationPage( 76 164 array( ··· 81 169 'title' => pht('Samples'), 82 170 )); 83 171 } 172 + 173 + private function renderGroupingLink(array $group, $key) { 174 + $group[] = $key; 175 + $uri = $this->getGroupURI($group); 176 + 177 + return phutil_tag( 178 + 'a', 179 + array( 180 + 'href' => $uri, 181 + 'style' => 'font-weight: bold', 182 + ), 183 + pht('(All)')); 184 + } 185 + 186 + private function getGroupURI(array $group) { 187 + unset($group['type']); 188 + $uri = clone $this->getRequest()->getRequestURI(); 189 + $uri->setQueryParam('group', implode('.', $group)); 190 + return $uri; 191 + } 192 + 84 193 85 194 }