ctf: Add comments to CTFClock
[deliverable/tracecompass.git] / ctf / 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/**
6bdb35a2
MK
19 * Clock description used in CTF traces.
20 *
21 * From the TSDL perspective, they describe the clock topology of the system, as well as to detail
22 * each clock parameter. In absence of clock description, it is assumed that all fields named
23 * timestamp use the same clock source, which increments once per nanosecond.
24 * <p>
25 * Describing a clock and how it is used by streams is threefold:
26 * <ol>
27 * <li>the clock and clock topology should be described in a clock description block</li>
28 * <li>a reference to this clock should be added within an integer type. (timestamp)</li>
29 * <li>stream declarations can reference the clock they use as a timestamp source</li></ol>
30 * In for trace compass's perspective, clock attributes are added when the trace is parsed. The ones
31 * used at this moment are:
32 * <ul><li>offsets</li><li>names</li><li>frequencies</li></ul>
33 *
34 * Most traces only have one clock source. As all events have timestamps offsetted by the same clock.
35 * It is however possible especially with mixed traces (hardware and software) to have different
36 * clock sources for a given event.
37 * <p>
38 * An individual event should only have one timestamp and therefore only one clock source though.
07002e0a 39 */
866e5b51
FC
40public class CTFClock {
41
0594c61c
AM
42 private static final long ONE_BILLION_L = 1000000000L;
43 private static final double ONE_BILLION_D = 1000000000.0;
44
1d7277f3
MK
45 private static final String NAME = "name"; //$NON-NLS-1$
46 private static final String FREQ = "freq"; //$NON-NLS-1$
47 private static final String OFFSET = "offset"; //$NON-NLS-1$
48
6b24f8f0
MK
49 private long fClockOffset = 0;
50 private double fClockScale = 1.0;
51 private double fClockAntiScale = 1.0;
1d7277f3 52
07002e0a
MK
53 /**
54 * Field properties.
55 */
6b24f8f0 56 private final Map<String, Object> fProperties = new HashMap<>();
07002e0a
MK
57 /**
58 * Field name.
59 */
6b24f8f0
MK
60 private String fName;
61 private boolean fIsScaled = false;
866e5b51 62
be6df2d8
AM
63 /**
64 * Default constructor
65 */
1d7277f3 66 public CTFClock() {
6bdb35a2 67 // The attributes are added later using addAttribute
1d7277f3 68 }
be6df2d8 69
07002e0a
MK
70 /**
71 * Method addAttribute.
1d7277f3
MK
72 *
73 * @param key
74 * String
75 * @param value
76 * Object
07002e0a 77 */
866e5b51 78 public void addAttribute(String key, Object value) {
6b24f8f0 79 fProperties.put(key, value);
1d7277f3 80 if (key.equals(NAME)) {
6b24f8f0 81 fName = (String) value;
866e5b51 82 }
1d7277f3
MK
83 if (key.equals(FREQ)) {
84 /*
85 * Long is converted to a double. the double is then dividing
86 * another double that double is saved. this is precise as long as
87 * the long is under 53 bits long. this is ok as long as we don't
88 * have a system with a frequency of > 1 600 000 000 GHz with
89 * 200 ppm precision
90 */
6b24f8f0
MK
91 fIsScaled = !((Long) getProperty(FREQ)).equals(ONE_BILLION_L);
92 fClockScale = ONE_BILLION_D / ((Long) getProperty(FREQ)).doubleValue();
93 fClockAntiScale = 1.0 / fClockScale;
1d7277f3
MK
94
95 }
96 if (key.equals(OFFSET)) {
6b24f8f0 97 fClockOffset = (Long) getProperty(OFFSET);
1d7277f3 98 }
866e5b51
FC
99 }
100
07002e0a
MK
101 /**
102 * Method getName.
1d7277f3 103 *
07002e0a
MK
104 * @return String
105 */
866e5b51 106 public String getName() {
6b24f8f0 107 return fName;
866e5b51
FC
108 }
109
07002e0a
MK
110 /**
111 * Method getProperty.
1d7277f3
MK
112 *
113 * @param key
114 * String
07002e0a
MK
115 * @return Object
116 */
866e5b51 117 public Object getProperty(String key) {
6b24f8f0 118 return fProperties.get(key);
866e5b51
FC
119 }
120
1d7277f3
MK
121 /**
122 * @return the clockOffset
123 */
124 public long getClockOffset() {
6b24f8f0 125 return fClockOffset;
1d7277f3
MK
126 }
127
128 /**
129 * @return the clockScale
130 */
131 public double getClockScale() {
6b24f8f0 132 return fClockScale;
1d7277f3
MK
133 }
134
135 /**
136 * @return the clockAntiScale
137 */
138 public double getClockAntiScale() {
6b24f8f0 139 return fClockAntiScale;
1d7277f3
MK
140 }
141
142 /**
143 * @return is the clock in ns or cycles?
144 */
145 public boolean isClockScaled() {
6b24f8f0 146 return fIsScaled;
1d7277f3
MK
147 }
148
866e5b51 149}
This page took 0.079911 seconds and 5 git commands to generate.