Commit | Line | Data |
---|---|---|
866e5b51 FC |
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 | ||
07002e0a | 17 | /** |
be6df2d8 | 18 | * Clock description used in CTF traces |
07002e0a | 19 | */ |
866e5b51 FC |
20 | public class CTFClock { |
21 | ||
1d7277f3 MK |
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 | ||
07002e0a MK |
30 | /** |
31 | * Field properties. | |
32 | */ | |
866e5b51 | 33 | final private HashMap<String, Object> properties = new HashMap<String, Object>(); |
07002e0a MK |
34 | /** |
35 | * Field name. | |
36 | */ | |
866e5b51 | 37 | private String name; |
1d7277f3 | 38 | private boolean isScaled = false; |
866e5b51 | 39 | |
be6df2d8 AM |
40 | /** |
41 | * Default constructor | |
42 | */ | |
1d7277f3 MK |
43 | public CTFClock() { |
44 | } | |
be6df2d8 | 45 | |
07002e0a MK |
46 | /** |
47 | * Method addAttribute. | |
1d7277f3 MK |
48 | * |
49 | * @param key | |
50 | * String | |
51 | * @param value | |
52 | * Object | |
07002e0a | 53 | */ |
866e5b51 FC |
54 | public void addAttribute(String key, Object value) { |
55 | this.properties.put(key, value); | |
1d7277f3 | 56 | if (key.equals(NAME)) { |
866e5b51 FC |
57 | this.name = (String) value; |
58 | } | |
1d7277f3 MK |
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 | } | |
866e5b51 FC |
75 | } |
76 | ||
07002e0a MK |
77 | /** |
78 | * Method getName. | |
1d7277f3 | 79 | * |
07002e0a MK |
80 | * @return String |
81 | */ | |
866e5b51 FC |
82 | public String getName() { |
83 | return name; | |
84 | } | |
85 | ||
07002e0a MK |
86 | /** |
87 | * Method getProperty. | |
1d7277f3 MK |
88 | * |
89 | * @param key | |
90 | * String | |
07002e0a MK |
91 | * @return Object |
92 | */ | |
866e5b51 FC |
93 | public Object getProperty(String key) { |
94 | return properties.get(key); | |
95 | } | |
96 | ||
1d7277f3 MK |
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 | ||
866e5b51 | 125 | } |