diff --git a/resources/sql/autopatches/20181106.repo.02.hook.sql b/resources/sql/autopatches/20181106.repo.02.hook.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20181106.repo.02.hook.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_repository.repository_pushevent + ADD hookWait BIGINT UNSIGNED; diff --git a/scripts/repository/commit_hook.php b/scripts/repository/commit_hook.php --- a/scripts/repository/commit_hook.php +++ b/scripts/repository/commit_hook.php @@ -17,6 +17,8 @@ // subclasses of PhabricatorConfigSiteSource to read it and build an instance // environment. +$hook_start = microtime(true); + if ($argc > 1) { $context = $argv[1]; $context = explode(':', $context, 2); @@ -35,7 +37,8 @@ throw new Exception(pht('usage: commit-hook ')); } -$engine = new DiffusionCommitHookEngine(); +$engine = id(new DiffusionCommitHookEngine()) + ->setStartTime($hook_start); $repository = id(new PhabricatorRepositoryQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php --- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php +++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php @@ -31,6 +31,7 @@ private $mercurialHook; private $mercurialCommits = array(); private $gitCommits = array(); + private $startTime; private $heraldViewerProjects; private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; @@ -70,6 +71,15 @@ return $this->requestIdentifier; } + public function setStartTime($start_time) { + $this->startTime = $start_time; + return $this; + } + + public function getStartTime() { + return $this->startTime; + } + public function setSubversionTransactionInfo($transaction, $repository) { $this->subversionTransaction = $transaction; $this->subversionRepository = $repository; @@ -1102,11 +1112,15 @@ private function newPushEvent() { $viewer = $this->getViewer(); + $hook_start = $this->getStartTime(); + $hook_end = microtime(true); + $event = PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) ->setRepositoryPHID($this->getRepository()->getPHID()) ->setRemoteAddress($this->getRemoteAddress()) ->setRemoteProtocol($this->getRemoteProtocol()) - ->setEpoch(PhabricatorTime::getNow()); + ->setEpoch(PhabricatorTime::getNow()) + ->setHookWait((int)(1000000 * ($hook_end - $hook_start))); $identifier = $this->getRequestIdentifier(); if (strlen($identifier)) { diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php --- a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php +++ b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php @@ -19,6 +19,7 @@ protected $writeWait; protected $readWait; protected $hostWait; + protected $hookWait; private $repository = self::ATTACHABLE; private $logs = self::ATTACHABLE; @@ -41,6 +42,7 @@ 'writeWait' => 'uint64?', 'readWait' => 'uint64?', 'hostWait' => 'uint64?', + 'hookWait' => 'uint64?', ), self::CONFIG_KEY_SCHEMA => array( 'key_repository' => array(