Do not use Stopwatch in PCEPRequest 08/100708/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Apr 2022 14:38:22 +0000 (16:38 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Apr 2022 17:18:17 +0000 (19:18 +0200)
While a Stopwatch is useful, we are not using its Ticker-based utility.
Use System.nanoTime() directly to keep track of our elapsed time,
improving our memory footprint slightly.

Change-Id: I12cb3c6070dcac56ab4d80ec18b9be3a647e9f00
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPRequest.java

index 4e117736cd209e8036f29b7873a9d218d7521a29..c2c3128a0d36994bcf8f1fbd0936b0a9c1c3a494 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.bgpcep.pcep.topology.provider;
 
-import com.google.common.base.Stopwatch;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.lang.invoke.MethodHandles;
@@ -39,7 +38,6 @@ final class PCEPRequest {
     }
 
     private static final Logger LOG = LoggerFactory.getLogger(PCEPRequest.class);
-    private static final long MINIMUM_ELAPSED_TIME = 1;
     private static final VarHandle STATE;
 
     static {
@@ -51,7 +49,7 @@ final class PCEPRequest {
     }
 
     private final SettableFuture<OperationResult> future = SettableFuture.create();
-    private final Stopwatch stopwatch = Stopwatch.createStarted();
+    private final long startNanos = System.nanoTime();
     private final Metadata metadata;
 
     // Manipulated via STATE
@@ -78,12 +76,11 @@ final class PCEPRequest {
     }
 
     long getElapsedMillis() {
-        final long elapsedNanos = stopwatch.elapsed().toNanos();
+        final long elapsedNanos = System.nanoTime() - startNanos;
         final long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(elapsedNanos);
-        if (elapsedMillis == 0 && elapsedNanos > 0) {
-            return MINIMUM_ELAPSED_TIME;
-        }
-        return elapsedMillis;
+
+        // FIXME: this is weird: it scales (0,1) up to 1, but otherwise scales down
+        return elapsedMillis == 0 && elapsedNanos > 0 ? 1 : elapsedMillis;
     }
 
     /**