rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / ctf / core / event / CTFClock.java
CommitLineData
866e5b51 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
866e5b51
FC
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
f357bcd4 13package org.eclipse.tracecompass.ctf.core.event;
866e5b51
FC
14
15import java.util.HashMap;
0594c61c 16import java.util.Map;
866e5b51 17
07002e0a 18/**
be6df2d8 19 * Clock description used in CTF traces
07002e0a 20 */
866e5b51
FC
21public class CTFClock {
22
0594c61c
AM
23 private static final long ONE_BILLION_L = 1000000000L;
24 private static final double ONE_BILLION_D = 1000000000.0;
25
1d7277f3
MK
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
6b24f8f0
MK
30 private long fClockOffset = 0;
31 private double fClockScale = 1.0;
32 private double fClockAntiScale = 1.0;
1d7277f3 33
07002e0a
MK
34 /**
35 * Field properties.
36 */
6b24f8f0 37 private final Map<String, Object> fProperties = new HashMap<>();
07002e0a
MK
38 /**
39 * Field name.
40 */
6b24f8f0
MK
41 private String fName;
42 private boolean fIsScaled = false;
866e5b51 43
be6df2d8
AM
44 /**
45 * Default constructor
46 */
1d7277f3
MK
47 public CTFClock() {
48 }
be6df2d8 49
07002e0a
MK
50 /**
51 * Method addAttribute.
1d7277f3
MK
52 *
53 * @param key
54 * String
55 * @param value
56 * Object
07002e0a 57 */
866e5b51 58 public void addAttribute(String key, Object value) {
6b24f8f0 59 fProperties.put(key, value);
1d7277f3 60 if (key.equals(NAME)) {
6b24f8f0 61 fName = (String) value;
866e5b51 62 }
1d7277f3
MK
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 */
6b24f8f0
MK
71 fIsScaled = !((Long) getProperty(FREQ)).equals(ONE_BILLION_L);
72 fClockScale = ONE_BILLION_D / ((Long) getProperty(FREQ)).doubleValue();
73 fClockAntiScale = 1.0 / fClockScale;
1d7277f3
MK
74
75 }
76 if (key.equals(OFFSET)) {
6b24f8f0 77 fClockOffset = (Long) getProperty(OFFSET);
1d7277f3 78 }
866e5b51
FC
79 }
80
07002e0a
MK
81 /**
82 * Method getName.
1d7277f3 83 *
07002e0a
MK
84 * @return String
85 */
866e5b51 86 public String getName() {
6b24f8f0 87 return fName;
866e5b51
FC
88 }
89
07002e0a
MK
90 /**
91 * Method getProperty.
1d7277f3
MK
92 *
93 * @param key
94 * String
07002e0a
MK
95 * @return Object
96 */
866e5b51 97 public Object getProperty(String key) {
6b24f8f0 98 return fProperties.get(key);
866e5b51
FC
99 }
100
1d7277f3
MK
101 /**
102 * @return the clockOffset
103 */
104 public long getClockOffset() {
6b24f8f0 105 return fClockOffset;
1d7277f3
MK
106 }
107
108 /**
109 * @return the clockScale
110 */
111 public double getClockScale() {
6b24f8f0 112 return fClockScale;
1d7277f3
MK
113 }
114
115 /**
116 * @return the clockAntiScale
117 */
118 public double getClockAntiScale() {
6b24f8f0 119 return fClockAntiScale;
1d7277f3
MK
120 }
121
122 /**
123 * @return is the clock in ns or cycles?
124 */
125 public boolean isClockScaled() {
6b24f8f0 126 return fIsScaled;
1d7277f3
MK
127 }
128
866e5b51 129}
This page took 0.063378 seconds and 5 git commands to generate.