@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 MultimeterEvent extends MultimeterDAO {
4
5 const TYPE_STATIC_RESOURCE = 0;
6 const TYPE_REQUEST_TIME = 1;
7 const TYPE_EXEC_TIME = 2;
8
9 protected $eventType;
10 protected $eventLabelID;
11 protected $resourceCost;
12 protected $sampleRate;
13 protected $eventContextID;
14 protected $eventHostID;
15 protected $eventViewerID;
16 protected $epoch;
17 protected $requestKey;
18
19 private $eventLabel;
20
21 public function setEventLabel($event_label) {
22 $this->eventLabel = $event_label;
23 return $this;
24 }
25
26 public function getEventLabel() {
27 return $this->eventLabel;
28 }
29
30 public static function getEventTypeName($type) {
31 switch ($type) {
32 case self::TYPE_STATIC_RESOURCE:
33 return pht('Static Resource');
34 case self::TYPE_REQUEST_TIME:
35 return pht('Web Request');
36 case self::TYPE_EXEC_TIME:
37 return pht('Subprocesses');
38 }
39
40 return pht('Unknown ("%s")', $type);
41 }
42
43 public static function formatResourceCost(
44 PhabricatorUser $viewer,
45 $type,
46 $cost) {
47
48 switch ($type) {
49 case self::TYPE_STATIC_RESOURCE:
50 return pht('%s Req', new PhutilNumber($cost));
51 case self::TYPE_REQUEST_TIME:
52 case self::TYPE_EXEC_TIME:
53 return pht('%s us', new PhutilNumber($cost));
54 }
55
56 return pht('%s Unit(s)', new PhutilNumber($cost));
57 }
58
59
60 protected function getConfiguration() {
61 return array(
62 self::CONFIG_TIMESTAMPS => false,
63 self::CONFIG_COLUMN_SCHEMA => array(
64 'eventType' => 'uint32',
65 'resourceCost' => 'sint64',
66 'sampleRate' => 'uint32',
67 'requestKey' => 'bytes12',
68 ),
69 self::CONFIG_KEY_SCHEMA => array(
70 'key_request' => array(
71 'columns' => array('requestKey'),
72 ),
73 'key_type' => array(
74 'columns' => array('eventType', 'epoch'),
75 ),
76 ),
77 ) + parent::getConfiguration();
78 }
79
80}