1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.ctf
.core
.event
;
15 import java
.util
.HashMap
;
19 * Clock description used in CTF traces.
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.
25 * Describing a clock and how it is used by streams is threefold:
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>
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.
38 * An individual event should only have one timestamp and therefore only one clock source though.
40 public class CTFClock
{
42 private static final long ONE_BILLION_L
= 1000000000L;
43 private static final double ONE_BILLION_D
= 1000000000.0;
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$
49 private long fClockOffset
= 0;
50 private double fClockScale
= 1.0;
51 private double fClockAntiScale
= 1.0;
56 private final Map
<String
, Object
> fProperties
= new HashMap
<>();
61 private boolean fIsScaled
= false;
67 // The attributes are added later using addAttribute
71 * Method addAttribute.
78 public void addAttribute(String key
, Object value
) {
79 fProperties
.put(key
, value
);
80 if (key
.equals(NAME
)) {
81 fName
= (String
) value
;
83 if (key
.equals(FREQ
)) {
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
91 fIsScaled
= !((Long
) getProperty(FREQ
)).equals(ONE_BILLION_L
);
92 fClockScale
= ONE_BILLION_D
/ ((Long
) getProperty(FREQ
)).doubleValue();
93 fClockAntiScale
= 1.0 / fClockScale
;
96 if (key
.equals(OFFSET
)) {
97 fClockOffset
= (Long
) getProperty(OFFSET
);
106 public String
getName() {
111 * Method getProperty.
117 public Object
getProperty(String key
) {
118 return fProperties
.get(key
);
122 * @return the clockOffset
124 public long getClockOffset() {
129 * @return the clockScale
131 public double getClockScale() {
136 * @return the clockAntiScale
138 public double getClockAntiScale() {
139 return fClockAntiScale
;
143 * @return is the clock in ns or cycles?
145 public boolean isClockScaled() {
This page took 0.048118 seconds and 6 git commands to generate.