Improve CTF timestamp output, will now output in y/m/d, h:m:s.ns or ns or s (double)
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 3 May 2012 17:03:31 +0000 (13:03 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 3 May 2012 17:17:14 +0000 (13:17 -0400)
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/RequestBenchmark.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTimestamp.java

index 5268c439d5b7bd52644c2013a868a53f3f34bc45..8876d7fb452775ca1ebd67c44fdc5a04f5d05091 100644 (file)
@@ -32,7 +32,7 @@ public class RequestBenchmark extends TmfEventRequest<CtfTmfEvent> {
     }
 
     // Path of the trace
-    public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1";
+    public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel";
 
     // *** Change this to run several time over the same trace
     public static final int NB_OF_PASS = 100;
@@ -61,10 +61,8 @@ public class RequestBenchmark extends TmfEventRequest<CtfTmfEvent> {
 
             // Create a new time range from -infinity to +infinity
             // That way, we will get "everything" in the trace
-            final CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE,
-                    (CtfTmfTrace) traces[0]);
-            final CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE,
-                    (CtfTmfTrace) traces[0]);
+            final CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE);
+            final CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE);
             final TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2);
 
             // We will issue a request for each "pass".
@@ -106,16 +104,18 @@ public class RequestBenchmark extends TmfEventRequest<CtfTmfEvent> {
         nbEvent = 0;
         prev = next;
         benchs.add(val);
-        if (benchs.size() == NB_OF_PASS)
+        if (benchs.size() == NB_OF_PASS) {
             try {
                 System.out.println("Nb events : " + nbEvent2);
 
-                for (final double value : benchs)
+                for (final double value : benchs) {
                     System.out.print(value + ", ");
+                }
                 fExperiment.sendRequest(null);
 
             } catch (final Exception e) {
             }
+        }
     }
 
     @Override
index 1500c504aed0ecdaacde085060ad13d998d53eb2..ea42c0e303be1dd99838a07d29fe5c610c0d6e66 100644 (file)
@@ -239,7 +239,7 @@ public final class CtfTmfEvent implements ITmfEvent {
     @Override
     public ITmfTimestamp getTimestamp() {
         if (fTimestamp == null) {
-            fTimestamp = new CtfTmfTimestamp(timestamp, fTrace);
+            fTimestamp = new CtfTmfTimestamp(timestamp);
         }
         return fTimestamp;
     }
index 284635ac6b5efbb2322dfc47dde9e33e15eff3d5..80b428cd3a51e28cfce846b5cb6cb2f4a428c2b3 100644 (file)
@@ -1,54 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 
 public class CtfTmfTimestamp extends TmfTimestamp {
 
-    final private CtfTmfTrace fTrace;
+    public enum TimestampType {
+        FULL_DATE, DAY, NANOS, SECONDS
+    }
+
+    private TimestampType type;
 
-    public CtfTmfTimestamp(long timestamp, CtfTmfTrace trace) {
-        fTrace = trace;
+    public CtfTmfTimestamp(long timestamp) {
         setValue(timestamp, -9, 0);
+        type = TimestampType.DAY;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = super.hashCode();
-        result = (prime * result) + ((fTrace == null) ? 0 : fTrace.hashCode());
-        return result;
+    public void setType(TimestampType value) {
+        type = value;
+    }
+
+    public TimestampType getType() {
+        return type;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse
+     * .linuxtools.tmf.core.event.ITmfTimestamp)
      */
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (!(obj instanceof CtfTmfTimestamp)) {
-            return false;
+    public ITmfTimestamp getDelta(ITmfTimestamp ts) {
+        TmfTimestamp parent = (TmfTimestamp) super.getDelta(ts);
+        long value = parent.getValue();
+        long exp = parent.getScale();
+        long diff = exp + 9;
+        for (int i = 0; i < diff; i++) {
+            value *= 10;
         }
-        CtfTmfTimestamp other = (CtfTmfTimestamp) obj;
-        if (fTrace == null) {
-            if (other.fTrace != null) {
-                return false;
-            }
-        } else if (!fTrace.equals(other.fTrace)) {
-            return false;
+        CtfTmfTimestamp retVal = new CtfTmfTimestamp(value);
+        if (value > 100000000) {
+            retVal.type = TimestampType.SECONDS;
+        } else {
+            retVal.type = TimestampType.NANOS;
         }
-        return true;
+        return retVal;
     }
 
     /*
@@ -58,6 +71,41 @@ public class CtfTmfTimestamp extends TmfTimestamp {
      */
     @Override
     public String toString() {
+        switch (type) {
+        case DAY: {
+            return dateToString();
+        }
+        case FULL_DATE: {
+            return toFullDateString();
+        }
+        case NANOS: {
+            return nanoToString();
+        }
+        case SECONDS:{
+            return secondsToString();
+        }
+        }
+        return super.toString();
+    }
+
+    private String secondsToString() {
+        double timestamp = getValue();
+        timestamp /= 1000000000;
+        StringBuilder retVal = new StringBuilder();
+        retVal.append(timestamp);
+        retVal.append(" s"); //$NON-NLS-1$
+        return retVal.toString();
+    }
+
+    private String nanoToString() {
+        final long timestamp = getValue();
+        StringBuilder retVal = new StringBuilder();
+        retVal.append(timestamp);
+        retVal.append(" ns"); //$NON-NLS-1$
+        return retVal.toString();
+    }
+
+    private String dateToString() {
         final long timestamp = getValue();
         final Date d = new Date(timestamp / 1000000);
         final DateFormat df = new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$
@@ -68,7 +116,7 @@ public class CtfTmfTimestamp extends TmfTimestamp {
         return output.toString();
     }
 
-    public String toFullDateString(){
+    private String toFullDateString() {
         final long timestamp = getValue();
         final Date d = new Date(timestamp / 1000000);
         final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
This page took 0.045764 seconds and 5 git commands to generate.