Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFClock.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.ctf.core.event;
14
15 import java.util.HashMap;
16
17 /**
18 * Clock description used in CTF traces
19 */
20 public class CTFClock {
21
22 private static final String NAME = "name"; //$NON-NLS-1$
23 private static final String FREQ = "freq"; //$NON-NLS-1$
24 private static final String OFFSET = "offset"; //$NON-NLS-1$
25
26 private long clockOffset = 0;
27 private double clockScale = 1.0;
28 private double clockAntiScale = 1.0;
29
30 /**
31 * Field properties.
32 */
33 final private HashMap<String, Object> properties = new HashMap<String, Object>();
34 /**
35 * Field name.
36 */
37 private String name;
38 private boolean isScaled = false;
39
40 /**
41 * Default constructor
42 */
43 public CTFClock() {
44 }
45
46 /**
47 * Method addAttribute.
48 *
49 * @param key
50 * String
51 * @param value
52 * Object
53 */
54 public void addAttribute(String key, Object value) {
55 this.properties.put(key, value);
56 if (key.equals(NAME)) {
57 this.name = (String) value;
58 }
59 if (key.equals(FREQ)) {
60 /*
61 * Long is converted to a double. the double is then dividing
62 * another double that double is saved. this is precise as long as
63 * the long is under 53 bits long. this is ok as long as we don't
64 * have a system with a frequency of > 1 600 000 000 GHz with
65 * 200 ppm precision
66 */
67 isScaled = !((Long) getProperty(FREQ)).equals(1000000000L);
68 clockScale = 1000000000.0 / ((Long) getProperty(FREQ)).doubleValue();
69 clockAntiScale = 1.0 / clockScale;
70
71 }
72 if (key.equals(OFFSET)) {
73 clockOffset = (Long) getProperty(OFFSET);
74 }
75 }
76
77 /**
78 * Method getName.
79 *
80 * @return String
81 */
82 public String getName() {
83 return name;
84 }
85
86 /**
87 * Method getProperty.
88 *
89 * @param key
90 * String
91 * @return Object
92 */
93 public Object getProperty(String key) {
94 return properties.get(key);
95 }
96
97 /**
98 * @return the clockOffset
99 */
100 public long getClockOffset() {
101 return clockOffset;
102 }
103
104 /**
105 * @return the clockScale
106 */
107 public double getClockScale() {
108 return clockScale;
109 }
110
111 /**
112 * @return the clockAntiScale
113 */
114 public double getClockAntiScale() {
115 return clockAntiScale;
116 }
117
118 /**
119 * @return is the clock in ns or cycles?
120 */
121 public boolean isClockScaled() {
122 return isScaled;
123 }
124
125 }
This page took 0.044475 seconds and 6 git commands to generate.