diff options
author | Alexa Panfil <alexapizza@google.com> | 2020-10-09 16:52:04 +0000 |
---|---|---|
committer | Alexa Panfil <alexapizza@google.com> | 2020-10-09 18:55:20 +0000 |
commit | a0d3680f494caa6275695fbd3397fd9b5805964d (patch) | |
tree | ce8382262e98c01552f4ed6010d8f58a29f16c89 | |
parent | b0b32501978c00018c3a046a09e474a1d783275a (diff) | |
download | jgit-a0d3680f494caa6275695fbd3397fd9b5805964d.tar.gz jgit-a0d3680f494caa6275695fbd3397fd9b5805964d.zip |
Compute time differences with Duration
Reason why this change is needed:
Currently the durations of fetch events are computed by
registering time instants with System.currentTimeMillis()
and calculating the differences with simple minus operation,
but multiple sources suggest that the best practice is to use
the Java 8 Duration and Instant objects.
What this patch does:
Get time measurements with Instant.now() instead of
System.currentTimeMillis() and calculate the duration of fetch
events (Reachability checks and Negotiation) using
Duration.between().toMillis().
Signed-off-by: Alexa Panfil <alexapizza@google.com>
Change-Id: I573a0a0562070083cf5a5a196d9710f69a7fa587
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 26c7ab7531..1242ef1b4a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -42,6 +42,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.text.MessageFormat; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -1008,7 +1010,7 @@ public class UploadPack { else advertised = refIdSet(getAdvertisedOrDefaultRefs().values()); - long negotiateStart = System.currentTimeMillis(); + Instant negotiateStart = Instant.now(); accumulator.advertised = advertised.size(); ProtocolV0Parser parser = new ProtocolV0Parser(transferConfig); @@ -1050,8 +1052,8 @@ public class UploadPack { if (!req.getClientShallowCommits().isEmpty()) walk.assumeShallow(req.getClientShallowCommits()); sendPack = negotiate(req, accumulator, pckOut); - accumulator.timeNegotiating += System.currentTimeMillis() - - negotiateStart; + accumulator.timeNegotiating = Duration + .between(negotiateStart, Instant.now()).toMillis(); if (sendPack && !biDirectionalPipe) { // Ensure the request was fully consumed. Any remaining input must @@ -1138,7 +1140,7 @@ public class UploadPack { } PackStatistics.Accumulator accumulator = new PackStatistics.Accumulator(); - long negotiateStart = System.currentTimeMillis(); + Instant negotiateStart = Instant.now(); ProtocolV2Parser parser = new ProtocolV2Parser(transferConfig); FetchV2Request req = parser.parseFetchRequest(pckIn); @@ -1244,8 +1246,8 @@ public class UploadPack { pckOut.writeString("packfile\n"); //$NON-NLS-1$ } - accumulator.timeNegotiating = System.currentTimeMillis() - - negotiateStart; + accumulator.timeNegotiating = Duration + .between(negotiateStart, Instant.now()).toMillis(); sendPack(accumulator, req, @@ -1795,12 +1797,13 @@ public class UploadPack { if (notAdvertisedWants != null) { accumulator.notAdvertisedWants = notAdvertisedWants.size(); - long startReachabilityChecking = System.currentTimeMillis(); + Instant startReachabilityChecking = Instant.now(); requestValidator.checkWants(this, notAdvertisedWants); - accumulator.reachabilityCheckDuration = System.currentTimeMillis() - - startReachabilityChecking; + accumulator.reachabilityCheckDuration = Duration + .between(startReachabilityChecking, Instant.now()) + .toMillis(); } AsyncRevObjectQueue q = walk.parseAny(wantIds, true); |