btf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFClock.java
index aa288da35a413ee4280cfe55051e6321ce6f2f1f..7b90cc14210f80e142559e2955af6aa34cc66667 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
 package org.eclipse.linuxtools.ctf.core.event;
 
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Clock description used in CTF traces
  */
 public class CTFClock {
 
+    private static final long ONE_BILLION_L = 1000000000L;
+    private static final double ONE_BILLION_D = 1000000000.0;
+
+    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 fClockOffset = 0;
+    private double fClockScale = 1.0;
+    private double fClockAntiScale = 1.0;
+
     /**
      * Field properties.
      */
-    final private HashMap<String, Object> properties = new HashMap<String, Object>();
+    private final Map<String, Object> fProperties = new HashMap<>();
     /**
      * Field name.
      */
-    private String name;
+    private String fName;
+    private boolean fIsScaled = 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$
-            this.name = (String) value;
+        fProperties.put(key, value);
+        if (key.equals(NAME)) {
+            fName = (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
+             */
+            fIsScaled = !((Long) getProperty(FREQ)).equals(ONE_BILLION_L);
+            fClockScale = ONE_BILLION_D / ((Long) getProperty(FREQ)).doubleValue();
+            fClockAntiScale = 1.0 / fClockScale;
+
+        }
+        if (key.equals(OFFSET)) {
+            fClockOffset = (Long) getProperty(OFFSET);
         }
     }
 
     /**
      * Method getName.
+     *
      * @return String
      */
     public String getName() {
-        return name;
+        return fName;
     }
 
     /**
      * Method getProperty.
-     * @param key String
+     *
+     * @param key
+     *            String
      * @return Object
      */
     public Object getProperty(String key) {
-        return properties.get(key);
+        return fProperties.get(key);
+    }
+
+    /**
+     * @return the clockOffset
+     * @since 2.0
+     */
+    public long getClockOffset() {
+        return fClockOffset;
+    }
+
+    /**
+     * @return the clockScale
+     * @since 2.0
+     */
+    public double getClockScale() {
+        return fClockScale;
+    }
+
+    /**
+     * @return the clockAntiScale
+     * @since 2.0
+     */
+    public double getClockAntiScale() {
+        return fClockAntiScale;
+    }
+
+    /**
+     * @return is the clock in ns or cycles?
+     * @since 2.0
+     */
+    public boolean isClockScaled() {
+        return fIsScaled;
     }
 
 }
This page took 0.026989 seconds and 5 git commands to generate.