Add time scaling support
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFClock.java
index aa288da35a413ee4280cfe55051e6321ce6f2f1f..a68e595908a633dcb9d256973fee5cea5b2b6aee 100644 (file)
@@ -19,6 +19,14 @@ import java.util.HashMap;
  */
 public class CTFClock {
 
+    private static final String NAME = "name"; //$NON-NLS-1$
+    private static final String FREQ = "freq"; //$NON-NLS-1$
+    private static final String OFFSET = "offset"; //$NON-NLS-1$
+
+    private long clockOffset = 0;
+    private double clockScale = 1.0;
+    private double clockAntiScale = 1.0;
+
     /**
      * Field properties.
      */
@@ -27,26 +35,48 @@ public class CTFClock {
      * Field name.
      */
     private String name;
+    private boolean isScaled = false;
 
     /**
      * Default constructor
      */
-    public CTFClock() {}
+    public CTFClock() {
+    }
 
     /**
      * Method addAttribute.
-     * @param key String
-     * @param value Object
+     *
+     * @param key
+     *            String
+     * @param value
+     *            Object
      */
     public void addAttribute(String key, Object value) {
         this.properties.put(key, value);
-        if (key.equals("name")) { //$NON-NLS-1$
+        if (key.equals(NAME)) {
             this.name = (String) value;
         }
+        if (key.equals(FREQ)) {
+            /*
+             * Long is converted to a double. the double is then dividing
+             * another double that double is saved. this is precise as long as
+             * the long is under 53 bits long. this is ok as long as we don't
+             * have a system with a frequency of > 1 600 000 000 GHz with
+             * 200 ppm precision
+             */
+            isScaled = !((Long) getProperty(FREQ)).equals(1000000000L);
+            clockScale = 1000000000.0 / ((Long) getProperty(FREQ)).doubleValue();
+            clockAntiScale = 1.0 / clockScale;
+
+        }
+        if (key.equals(OFFSET)) {
+            clockOffset = (Long) getProperty(OFFSET);
+        }
     }
 
     /**
      * Method getName.
+     *
      * @return String
      */
     public String getName() {
@@ -55,11 +85,41 @@ public class CTFClock {
 
     /**
      * Method getProperty.
-     * @param key String
+     *
+     * @param key
+     *            String
      * @return Object
      */
     public Object getProperty(String key) {
         return properties.get(key);
     }
 
+    /**
+     * @return the clockOffset
+     */
+    public long getClockOffset() {
+        return clockOffset;
+    }
+
+    /**
+     * @return the clockScale
+     */
+    public double getClockScale() {
+        return clockScale;
+    }
+
+    /**
+     * @return the clockAntiScale
+     */
+    public double getClockAntiScale() {
+        return clockAntiScale;
+    }
+
+    /**
+     * @return is the clock in ns or cycles?
+     */
+    public boolean isClockScaled() {
+        return isScaled;
+    }
+
 }
This page took 0.02451 seconds and 5 git commands to generate.