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

Add timing information for commit hooks to push logs

Summary:
Depends on D19779. Ref T13216. The push logs currently record the "hostWait", which is roughly "locking + subprocess cost". We also record locking separately, so we can figure out "subprocess cost" alone by subtracting the lock costs.

However, the subprocess (normally `git receive-pack`) runs hooks, and we don't have an easy way to figure out how much time was spent doing actual `git` stuff vs spent doing commit hook processing. This would have been useful in diagnosing at least one recent issue.

Track at least a rough hook cost and record it in the push logs.

Test Plan: Pushed to a repository, saw a reasonable hook cost appear in the database table.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13216

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

+23 -2
+2
resources/sql/autopatches/20181106.repo.02.hook.sql
··· 1 + ALTER TABLE {$NAMESPACE}_repository.repository_pushevent 2 + ADD hookWait BIGINT UNSIGNED;
+4 -1
scripts/repository/commit_hook.php
··· 17 17 // subclasses of PhabricatorConfigSiteSource to read it and build an instance 18 18 // environment. 19 19 20 + $hook_start = microtime(true); 21 + 20 22 if ($argc > 1) { 21 23 $context = $argv[1]; 22 24 $context = explode(':', $context, 2); ··· 35 37 throw new Exception(pht('usage: commit-hook <repository>')); 36 38 } 37 39 38 - $engine = new DiffusionCommitHookEngine(); 40 + $engine = id(new DiffusionCommitHookEngine()) 41 + ->setStartTime($hook_start); 39 42 40 43 $repository = id(new PhabricatorRepositoryQuery()) 41 44 ->setViewer(PhabricatorUser::getOmnipotentUser())
+15 -1
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 31 31 private $mercurialHook; 32 32 private $mercurialCommits = array(); 33 33 private $gitCommits = array(); 34 + private $startTime; 34 35 35 36 private $heraldViewerProjects; 36 37 private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; ··· 68 69 69 70 public function getRequestIdentifier() { 70 71 return $this->requestIdentifier; 72 + } 73 + 74 + public function setStartTime($start_time) { 75 + $this->startTime = $start_time; 76 + return $this; 77 + } 78 + 79 + public function getStartTime() { 80 + return $this->startTime; 71 81 } 72 82 73 83 public function setSubversionTransactionInfo($transaction, $repository) { ··· 1102 1112 private function newPushEvent() { 1103 1113 $viewer = $this->getViewer(); 1104 1114 1115 + $hook_start = $this->getStartTime(); 1116 + $hook_end = microtime(true); 1117 + 1105 1118 $event = PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) 1106 1119 ->setRepositoryPHID($this->getRepository()->getPHID()) 1107 1120 ->setRemoteAddress($this->getRemoteAddress()) 1108 1121 ->setRemoteProtocol($this->getRemoteProtocol()) 1109 - ->setEpoch(PhabricatorTime::getNow()); 1122 + ->setEpoch(PhabricatorTime::getNow()) 1123 + ->setHookWait((int)(1000000 * ($hook_end - $hook_start))); 1110 1124 1111 1125 $identifier = $this->getRequestIdentifier(); 1112 1126 if (strlen($identifier)) {
+2
src/applications/repository/storage/PhabricatorRepositoryPushEvent.php
··· 19 19 protected $writeWait; 20 20 protected $readWait; 21 21 protected $hostWait; 22 + protected $hookWait; 22 23 23 24 private $repository = self::ATTACHABLE; 24 25 private $logs = self::ATTACHABLE; ··· 41 42 'writeWait' => 'uint64?', 42 43 'readWait' => 'uint64?', 43 44 'hostWait' => 'uint64?', 45 + 'hookWait' => 'uint64?', 44 46 ), 45 47 self::CONFIG_KEY_SCHEMA => array( 46 48 'key_repository' => array(