1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
;
12 import java
.util
.List
;
14 import org
.antlr
.runtime
.tree
.CommonTree
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.tracecompass
.ctf
.core
.event
.CTFClock
;
17 import org
.eclipse
.tracecompass
.ctf
.parser
.CTFParser
;
18 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.Activator
;
19 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ICommonTreeParser
;
20 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
23 * Clock metadata allows to describe the clock topology of the system, as well
24 * as to detail each clock parameter. In absence of clock description, it is
25 * assumed that all fields named timestamp use the same clock source, which
26 * increments once per nanosecond.
28 * Describing a clock and how it is used by streams is threefold: first, the
29 * clock and clock topology should be described in a clock description block,
34 name = cycle_counter_sync;
35 uuid = "62189bee-96dc-11e0-91a8-cfa3d89f3923";
36 description = "Cycle counter synchronized across CPUs";
37 freq = 1000000000; // frequency, in Hz
38 // precision in seconds is: 1000 * (1/freq)
41 // clock value offset from Epoch is:
42 // offset_s + (offset * (1/freq))
44 offset_s = 1326476837;
50 * The mandatory name field specifies the name of the clock identifier, which
51 * can later be used as a reference. The optional field uuid is the unique
52 * identifier of the clock. It can be used to correlate different traces that
53 * use the same clock. An optional textual description string can be added with
54 * the description field. The freq field is the initial frequency of the clock,
55 * in Hz. If the freq field is not present, the frequency is assumed to be
56 * 1000000000 (providing clock increment of 1 ns). The optional precision field
57 * details the uncertainty on the clock measurements, in (1/freq) units. The
58 * offset_s and offset fields indicate the offset from POSIX.1 Epoch, 1970-01-01
59 * 00:00:00 +0000 (UTC), to the zero of value of the clock. The offset_s field
60 * is in seconds. The offset field is in (1/freq) units. If any of the offset_s
61 * or offset field is not present, it is assigned the 0 value. The field
62 * absolute is TRUE if the clock is a global reference across different clock
63 * UUID (e.g. NTP time). Otherwise, absolute is FALSE, and the clock can be
64 * considered as synchronized only with other clocks that have the same UUID.
66 * Secondly, a reference to this clock should be added within an integer type:
70 size = 64; align = 1; signed = false;
71 map = clock.cycle_counter_sync.value;
75 * Thirdly, stream declarations can reference the clock they use as a timestamp
79 struct packet_context {
80 uint64_ccnt_t ccnt_begin;
81 uint64_ccnt_t ccnt_end;
87 event.header := struct {
88 uint64_ccnt_t timestamp;
91 packet.context := struct packet_context;
95 * For a N-bit integer type referring to a clock, if the integer overflows
96 * compared to the N low order bits of the clock prior value found in the same
97 * stream, then it is assumed that one, and only one, overflow occurred. It is
98 * therefore important that events encoding time on a small number of bits
99 * happen frequently enough to detect when more than one N-bit overflow occurs.
101 * In a packet context, clock field names ending with _begin and _end have a
102 * special meaning: this refers to the timestamps at, respectively, the
103 * beginning and the end of each packet.
105 * @author Matthew Khouzam - Initial API and implementation
106 * @author Efficios (documentation)
109 public final class ClockParser
implements ICommonTreeParser
{
114 public static final ClockParser INSTANCE
= new ClockParser();
116 private ClockParser() {
120 public CTFClock
parse(CommonTree clock
, ICommonTreeParserParameter unused
) throws ParseException
{
121 List
<CommonTree
> children
= clock
.getChildren();
122 CTFClock ctfClock
= new CTFClock();
123 for (CommonTree child
: children
) {
124 final String key
= child
.getChild(0).getChild(0).getChild(0).getText();
125 final CommonTree value
= (CommonTree
) child
.getChild(1).getChild(0).getChild(0);
126 final int type
= value
.getType();
127 final String text
= value
.getText();
129 case CTFParser
.INTEGER
:
130 case CTFParser
.DECIMAL_LITERAL
:
132 * Not a pretty hack, this is to make sure that there is no
133 * number overflow due to 63 bit integers. The offset should
134 * only really be an issue in the year 2262. the tracer in C/ASM
135 * can write an offset in an unsigned 64 bit long. In java, the
136 * last bit, being set to 1 will be read as a negative number,
137 * but since it is too big a positive it will throw an
138 * exception. this will happen in 2^63 ns from 1970. Therefore
139 * 293 years from 1970
143 numValue
= Long
.parseLong(text
);
144 } catch (NumberFormatException e
) {
145 Activator
.log(IStatus
.WARNING
, "Number conversion issue with " + text
+ ". Assigning " + key
+ " = 0."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
146 numValue
= Long
.valueOf(0L);
148 ctfClock
.addAttribute(key
, numValue
);
151 ctfClock
.addAttribute(key
, text
);