[NO ISSUE][HYR] Align trace timestamps with epoch
Ensures that microseconds emitted in trace events are since epoch
Outputs human-readable date/timestamp at tracer initialization
Change-Id: I85f3d13994bba77eeda3ea15af1c275c7bc48203
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2058
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
index 4a46c19..444cd4f 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
@@ -18,9 +18,13 @@
*/
package org.apache.hyracks.util.trace;
+import java.util.concurrent.TimeUnit;
+
import org.apache.hyracks.util.trace.Tracer.Scope;
final class Event {
+ private static final long NANOTIME_DELTA_TO_EPOCH = System.nanoTime()
+ - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
public final String name;
public final String cat;
public final Tracer.Phase ph;
@@ -43,7 +47,7 @@
}
private static long timestamp() {
- return System.nanoTime() / 1000;
+ return (System.nanoTime() - NANOTIME_DELTA_TO_EPOCH) / 1000;
}
public static Event create(String name, String cat, Tracer.Phase ph, int pid, long tid, Scope scope, String args) {
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
index 4dc2394..cd152a2 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
@@ -19,7 +19,10 @@
package org.apache.hyracks.util.trace;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
+import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -31,6 +34,8 @@
public class Tracer {
protected static final Level TRACE_LOG_LEVEL = Level.INFO;
+ protected static final String CAT = "Tracer";
+ protected static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
protected final Logger traceLog;
protected String[] categories;
@@ -70,6 +75,13 @@
public Tracer(String name, String[] categories) {
this.traceLog = Logger.getLogger(Tracer.class.getName() + "@" + name);
this.categories = categories;
+ instant("Trace-Start", CAT, Scope.p, dateTimeStamp());
+ }
+
+ public static String dateTimeStamp() {
+ synchronized (DATE_FORMAT) {
+ return DATE_FORMAT.format(new Date());
+ }
}
public static Tracer none() {