Skip to content

Commit c32fa06

Browse files
author
epriestley
committedNov 9, 2018
Use phutil_microseconds_since(...) to simplify some timing arithmetic
Summary: Depends on D19796. Simplify some timing code by using phutil_microseconds_since() instead of duplicate casting and arithmetic. Test Plan: Grepped for `1000000` to find these. Pulled, pushed, made a conduit call. This isn't exhaustive but it should be hard for these to break in a bad way since they're all just diagnostic. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D19797
1 parent b12e92e commit c32fa06

File tree

7 files changed

+9
-16
lines changed

7 files changed

+9
-16
lines changed
 

‎scripts/ssh/ssh-exec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
$ssh_log->setData(
308308
array(
309309
'c' => $err,
310-
'T' => (int)(1000000 * (microtime(true) - $ssh_start_time)),
310+
'T' => phutil_microseconds_since($ssh_start_time),
311311
));
312312

313313
exit($err);

‎src/applications/conduit/controller/PhabricatorConduitAPIController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ public function handleRequest(AphrontRequest $request) {
109109
$error_info = $ex->getMessage();
110110
}
111111

112-
$time_end = microtime(true);
113-
114112
$log
115113
->setCallerPHID(
116114
isset($conduit_user)
117115
? $conduit_user->getPHID()
118116
: null)
119117
->setError((string)$error_code)
120-
->setDuration(1000000 * ($time_end - $time_start));
118+
->setDuration(phutil_microseconds_since($time_start));
121119

122120
if (!PhabricatorEnv::isReadOnly()) {
123121
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();

‎src/applications/conduit/ssh/ConduitSSHWorkflow.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ public function execute(PhutilArgumentParser $args) {
7373
// if the response is large and the receiver is slow to read it.
7474
$this->getIOChannel()->flush();
7575

76-
$time_end = microtime(true);
77-
7876
$connection_id = idx($metadata, 'connectionID');
7977
$log = id(new PhabricatorConduitMethodCallLog())
8078
->setCallerPHID($this->getSSHUser()->getPHID())
8179
->setConnectionID($connection_id)
8280
->setMethod($method)
8381
->setError((string)$error_code)
84-
->setDuration(1000000 * ($time_end - $time_start))
82+
->setDuration(phutil_microseconds_since($time_start))
8583
->save();
8684
}
8785
}

‎src/applications/diffusion/engine/DiffusionCommitHookEngine.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1113,14 +1113,13 @@ private function newPushEvent() {
11131113
$viewer = $this->getViewer();
11141114

11151115
$hook_start = $this->getStartTime();
1116-
$hook_end = microtime(true);
11171116

11181117
$event = PhabricatorRepositoryPushEvent::initializeNewEvent($viewer)
11191118
->setRepositoryPHID($this->getRepository()->getPHID())
11201119
->setRemoteAddress($this->getRemoteAddress())
11211120
->setRemoteProtocol($this->getRemoteProtocol())
11221121
->setEpoch(PhabricatorTime::getNow())
1123-
->setHookWait((int)(1000000 * ($hook_end - $hook_start)));
1122+
->setHookWait(phutil_microseconds_since($hook_start));
11241123

11251124
$identifier = $this->getRequestIdentifier();
11261125
if (strlen($identifier)) {

‎src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,7 @@ private function synchronizeWorkingCopyFromBinding(
772772
try {
773773
$future->resolvex();
774774
} catch (Exception $ex) {
775-
$sync_end = microtime(true);
776-
$log->setSyncWait((int)(1000000 * ($sync_end - $sync_start)));
775+
$log->setSyncWait(phutil_microseconds_since($sync_start));
777776

778777
if ($ex instanceof CommandException) {
779778
if ($future->getWasKilledByTimeout()) {
@@ -806,10 +805,8 @@ private function synchronizeWorkingCopyFromBinding(
806805
throw $ex;
807806
}
808807

809-
$sync_end = microtime(true);
810-
811808
$log
812-
->setSyncWait((int)(1000000 * ($sync_end - $sync_start)))
809+
->setSyncWait(phutil_microseconds_since($sync_start))
813810
->setResultCode(0)
814811
->setResultType(PhabricatorRepositorySyncEvent::RESULT_SYNC)
815812
->save();

‎src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ public function executeTask() {
169169

170170
$t_start = microtime(true);
171171
$worker->executeTask();
172-
$t_end = microtime(true);
173-
$duration = (int)(1000000 * ($t_end - $t_start));
172+
$duration = phutil_microseconds_since($t_start);
174173

175174
$result = $this->archiveTask(
176175
PhabricatorWorkerArchiveTask::RESULT_SUCCESS,

‎support/startup/PhabricatorStartup.php

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static function getStartTime() {
6464
* @task info
6565
*/
6666
public static function getMicrosecondsSinceStart() {
67+
// This is the same as "phutil_microseconds_since()", but we may not have
68+
// loaded libphutil yet.
6769
return (int)(1000000 * (microtime(true) - self::getStartTime()));
6870
}
6971

0 commit comments

Comments
 (0)
Failed to load comments.