[NO ISSUE][*HYR] Span enhancements
- add reset() to start the span over again
- add sleep() to sleep for the remainder of the span
Change-Id: I93799354f2e238b759d2ef11aed109ec96baaf21
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/6483
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Reviewed-by: Hussain Towaileb <hussainht@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
index 183cb6f..bc33e6d 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
@@ -21,18 +21,26 @@
import java.util.concurrent.TimeUnit;
public class Span {
- private final long startNanos;
private final long spanNanos;
+ private volatile long startNanos;
private Span(long span, TimeUnit unit) {
- startNanos = System.nanoTime();
spanNanos = unit.toNanos(span);
+ reset();
+ }
+
+ public void reset() {
+ startNanos = System.nanoTime();
}
public long getSpanNanos() {
return spanNanos;
}
+ public long getSpan(TimeUnit unit) {
+ return unit.convert(spanNanos, TimeUnit.NANOSECONDS);
+ }
+
public static Span start(long span, TimeUnit unit) {
return new Span(span, unit);
}
@@ -46,6 +54,15 @@
}
/**
+ * Sleep for the remainder of this span
+ *
+ * @throws InterruptedException
+ */
+ public void sleep() throws InterruptedException {
+ TimeUnit.NANOSECONDS.sleep(remaining(TimeUnit.NANOSECONDS));
+ }
+
+ /**
* Sleep for the minimum of the duration or the remaining of this span
*
* @param sleep