7b90cc14210f80e142559e2955af6aa34cc66667
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFClock.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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 import java.util.Map;
17
18 /**
19 * Clock description used in CTF traces
20 */
21 public class CTFClock {
22
23 private static final long ONE_BILLION_L = 1000000000L;
24 private static final double ONE_BILLION_D = 1000000000.0;
25
26 private static final String NAME = "name"; //$NON-NLS-1$
27 private static final String FREQ = "freq"; //$NON-NLS-1$
28 private static final String OFFSET = "offset"; //$NON-NLS-1$
29
30 private long fClockOffset = 0;
31 private double fClockScale = 1.0;
32 private double fClockAntiScale = 1.0;
33
34 /**
35 * Field properties.
36 */
37 private final Map<String, Object> fProperties = new HashMap<>();
38 /**
39 * Field name.
40 */
41 private String fName;
42 private boolean fIsScaled = false;
43
44 /**
45 * Default constructor
46 */
47 public CTFClock() {
48 }
49
50 /**
51 * Method addAttribute.
52 *
53 * @param key
54 * String
55 * @param value
56 * Object
57 */
58 public void addAttribute(String key, Object value) {
59 fProperties.put(key, value);
60 if (key.equals(NAME)) {
61 fName = (String) value;
62 }
63 if (key.equals(FREQ)) {
64 /*
65 * Long is converted to a double. the double is then dividing
66 * another double that double is saved. this is precise as long as
67 * the long is under 53 bits long. this is ok as long as we don't
68 * have a system with a frequency of > 1 600 000 000 GHz with
69 * 200 ppm precision
70 */
71 fIsScaled = !((Long) getProperty(FREQ)).equals(ONE_BILLION_L);
72 fClockScale = ONE_BILLION_D / ((Long) getProperty(FREQ)).doubleValue();
73 fClockAntiScale = 1.0 / fClockScale;
74
75 }
76 if (key.equals(OFFSET)) {
77 fClockOffset = (Long) getProperty(OFFSET);
78 }
79 }
80
81 /**
82 * Method getName.
83 *
84 * @return String
85 */
86 public String getName() {
87 return fName;
88 }
89
90 /**
91 * Method getProperty.
92 *
93 * @param key
94 * String
95 * @return Object
96 */
97 public Object getProperty(String key) {
98 return fProperties.get(key);
99 }
100
101 /**
102 * @return the clockOffset
103 * @since 2.0
104 */
105 public long getClockOffset() {
106 return fClockOffset;
107 }
108
109 /**
110 * @return the clockScale
111 * @since 2.0
112 */
113 public double getClockScale() {
114 return fClockScale;
115 }
116
117 /**
118 * @return the clockAntiScale
119 * @since 2.0
120 */
121 public double getClockAntiScale() {
122 return fClockAntiScale;
123 }
124
125 /**
126 * @return is the clock in ns or cycles?
127 * @since 2.0
128 */
129 public boolean isClockScaled() {
130 return fIsScaled;
131 }
132
133 }
This page took 0.037852 seconds and 4 git commands to generate.