diff options
author | Marc-Andre Laperle | 2015-03-05 23:01:30 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2015-03-06 07:15:11 +0000 |
commit | 9c69e0d701f29b841fb52aff378b74b5267a5bdd (patch) | |
tree | ebd67565063682e060ec11cc1fa1b3110bff7e25 /lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf | |
parent | ea6ea585fe1fc68f842db9c3584d4cc5c3909acd (diff) | |
download | org.eclipse.linuxtools-9c69e0d701f29b841fb52aff378b74b5267a5bdd.tar.gz org.eclipse.linuxtools-9c69e0d701f29b841fb52aff378b74b5267a5bdd.tar.xz org.eclipse.linuxtools-9c69e0d701f29b841fb52aff378b74b5267a5bdd.zip |
Remove content of the lttng folder and corresponding target dependencies
The LTTng component (also known as TMF) of Linux Tools has moved to the
Trace Compass project. A README file was added to explain that the
code moved.
Change-Id: I939275594beccc78155f37671d1765539764eabc
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/43270
Tested-by: Hudson CI
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf')
51 files changed, 0 insertions, 9913 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CTFStrings.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CTFStrings.java deleted file mode 100644 index fd42aa1597..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/CTFStrings.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexandre Montplaisir - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * Non-externalized strings for use with the CTF plugin (event names, field - * names, etc.) - * - * @author Alexandre Montplaisir - * @since 2.2 - */ -@SuppressWarnings("nls") -@NonNullByDefault -public interface CTFStrings { - - /** Event name for lost events */ - static final String LOST_EVENT_NAME = "Lost event"; - - /** - * Name of the field in lost events indicating how many actual events were - * lost - */ - static final String LOST_EVENTS_FIELD = "Lost events"; - - /** - * Name of the field in lost events indicating the time range - */ - static final String LOST_EVENTS_DURATION = "duration"; -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFCallsite.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFCallsite.java deleted file mode 100644 index 79948d5cd6..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFCallsite.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - * - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event; - -/** - * Callsite information to help with cdt integration - * - * @author Matthew Khouzam - * - * @since 1.2 - */ -public class CTFCallsite implements Comparable<CTFCallsite> { - - private static final long MASK32 = 0x00000000ffffffffL; - - /** - * The event name - */ - private final String fEventName; - - /** - * the file name of the callsite - */ - private final String fFileName; - - /** - * the instruction pointer - */ - private final long fIp; - - /** - * the function name - */ - private final String fFunctionName; - - /** - * the line number of the callsite - */ - private final long fLineNumber; - - /** - * The callsite constructor - * - * @param en - * The event name - * @param func - * the function name - * @param ip - * the instruction pointer of the callsite - * @param fn - * the file name of the callsite - * @param line - * the line number of the callsite - */ - public CTFCallsite(String en, String func, long ip, String fn, long line) { - fEventName = en; - fFileName = fn; - fFunctionName = func; - fIp = ip; - fLineNumber = line; - } - - /** - * @return the eventName - */ - public String getEventName() { - return fEventName; - } - - /** - * @return the fileName - */ - public String getFileName() { - return fFileName; - } - - /** - * @return the ip - */ - public long getIp() { - return fIp; - } - - /** - * @return the functionName - */ - public String getFunctionName() { - return fFunctionName; - } - - /** - * @return the lineNumber - */ - public long getLineNumber() { - return fLineNumber; - } - - /* - * The callsites will be sorted by calling addresses. To do this we take IPs - * (instruction pointers) and compare them. Java only supports signed - * operation and since memory addresses are unsigned, we will convert the - * longs into integers that contain the high and low bytes and compare them. - */ - @Override - public int compareTo(CTFCallsite o) { - /* - * mask32 is 32 zeros followed by 32 ones, when we bitwise and this it - * will return the lower 32 bits - */ - - long other = o.fIp; - /* - * To get a high int: we downshift by 32 and bitwise and with the mask - * to get rid of the sign - * - * To get the low int: we bitwise and with the mask. - */ - long otherHigh = (other >> 32) & MASK32; - long otherLow = other & MASK32; - long ownHigh = (fIp >> 32) & MASK32; - long ownLow = fIp & MASK32; - /* are the high values different, if so ignore the lower values */ - if (ownHigh > otherHigh) { - return 1; - } - if (ownHigh < otherHigh ) { - return -1; - } - /* the high values are the same, compare the lower values */ - if (ownLow > otherLow) { - return 1; - } - if (ownLow < otherLow) { - return -1; - } - /* the values are identical */ - return 0; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((fEventName == null) ? 0 : fEventName.hashCode()); - result = prime * result + ((fFileName == null) ? 0 : fFileName.hashCode()); - result = prime * result + ((fFunctionName == null) ? 0 : fFunctionName.hashCode()); - result = prime * result + (int) (fIp ^ (fIp >>> 32)); - result = prime * result + (int) (fLineNumber ^ (fLineNumber >>> 32)); - return result; - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - CTFCallsite other = (CTFCallsite) obj; - if (fEventName == null) { - if (other.fEventName != null) { - return false; - } - } else if (!fEventName.equals(other.fEventName)) { - return false; - } - if (fFileName == null) { - if (other.fFileName != null) { - return false; - } - } else if (!fFileName.equals(other.fFileName)) { - return false; - } - if (fFunctionName == null) { - if (other.fFunctionName != null) { - return false; - } - } else if (!fFunctionName.equals(other.fFunctionName)) { - return false; - } - if (fIp != other.fIp) { - return false; - } - if (fLineNumber != other.fLineNumber) { - return false; - } - return true; - } - - @Override - public String toString() { - return fFileName + "/" + fFunctionName + ":" + fLineNumber; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java deleted file mode 100644 index 7b90cc1421..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event; - -import java.util.HashMap; -import java.util.Map; - -/** - * Clock description used in CTF traces - */ -public class CTFClock { - - private static final long ONE_BILLION_L = 1000000000L; - private static final double ONE_BILLION_D = 1000000000.0; - - private static final String NAME = "name"; //$NON-NLS-1$ - private static final String FREQ = "freq"; //$NON-NLS-1$ - private static final String OFFSET = "offset"; //$NON-NLS-1$ - - private long fClockOffset = 0; - private double fClockScale = 1.0; - private double fClockAntiScale = 1.0; - - /** - * Field properties. - */ - private final Map<String, Object> fProperties = new HashMap<>(); - /** - * Field name. - */ - private String fName; - private boolean fIsScaled = false; - - /** - * Default constructor - */ - public CTFClock() { - } - - /** - * Method addAttribute. - * - * @param key - * String - * @param value - * Object - */ - public void addAttribute(String key, Object value) { - fProperties.put(key, value); - if (key.equals(NAME)) { - fName = (String) value; - } - if (key.equals(FREQ)) { - /* - * Long is converted to a double. the double is then dividing - * another double that double is saved. this is precise as long as - * the long is under 53 bits long. this is ok as long as we don't - * have a system with a frequency of > 1 600 000 000 GHz with - * 200 ppm precision - */ - fIsScaled = !((Long) getProperty(FREQ)).equals(ONE_BILLION_L); - fClockScale = ONE_BILLION_D / ((Long) getProperty(FREQ)).doubleValue(); - fClockAntiScale = 1.0 / fClockScale; - - } - if (key.equals(OFFSET)) { - fClockOffset = (Long) getProperty(OFFSET); - } - } - - /** - * Method getName. - * - * @return String - */ - public String getName() { - return fName; - } - - /** - * Method getProperty. - * - * @param key - * String - * @return Object - */ - public Object getProperty(String key) { - return fProperties.get(key); - } - - /** - * @return the clockOffset - * @since 2.0 - */ - public long getClockOffset() { - return fClockOffset; - } - - /** - * @return the clockScale - * @since 2.0 - */ - public double getClockScale() { - return fClockScale; - } - - /** - * @return the clockAntiScale - * @since 2.0 - */ - public double getClockAntiScale() { - return fClockAntiScale; - } - - /** - * @return is the clock in ns or cycles? - * @since 2.0 - */ - public boolean isClockScaled() { - return fIsScaled; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java deleted file mode 100644 index f2fb8ca885..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.event.types.Definition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader; -import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; - -/** - * Representation of a particular instance of an event. - */ -public final class EventDefinition implements IDefinitionScope { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * A null event, can be used for testing or poison pilling - * - * @since 3.0 - */ - @NonNull - public static final EventDefinition NULL_EVENT = new EventDefinition(new EventDeclaration(), null, -1L, null, null, null, null); - - /** - * The corresponding event declaration. - */ - private final IEventDeclaration fDeclaration; - - /** - * The timestamp of the current event. - */ - private final long fTimestamp; - - /** - * The event context structure definition. - */ - private final StructDefinition fEventContext; - - private final StructDefinition fStreamContext; - - private final StructDefinition fPacketContext; - - /** - * The event fields structure definition. - */ - private final StructDefinition fFields; - - /** - * The StreamInputReader that reads this event definition. - */ - private final CTFStreamInputReader fStreamInputReader; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs an event definition. - * - * @param declaration - * The corresponding event declaration - * @param streamInputReader - * The SIR from where this EventDef was read - * @param timestamp - * event timestamp - * @param eventContext - * The event context - * @param packetContext - * the packet context - * @param streamContext - * the stream context - * @param fields - * The event fields - * @since 3.0 - */ - public EventDefinition(IEventDeclaration declaration, - CTFStreamInputReader streamInputReader, - long timestamp, - StructDefinition streamContext, - StructDefinition eventContext, - StructDefinition packetContext, - StructDefinition fields) { - fDeclaration = declaration; - fStreamInputReader = streamInputReader; - fTimestamp = timestamp; - fFields = fields; - fEventContext = eventContext; - fPacketContext = packetContext; - fStreamContext = streamContext; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public LexicalScope getScopePath() { - String eventName = fDeclaration.getName(); - if (eventName == null) { - return null; - } - LexicalScope myScope = LexicalScope.EVENT.getChild(eventName); - if (myScope == null) { - myScope = new LexicalScope(LexicalScope.EVENT, eventName); - } - return myScope; - } - - /** - * Gets the declaration (the form) of the data - * - * @return the event declaration - * @since 2.0 - */ - public IEventDeclaration getDeclaration() { - return fDeclaration; - } - - /** - * Gets the fields of a definition - * - * @return the fields of a definition in struct form. Can be null. - */ - public StructDefinition getFields() { - return fFields; - } - - /** - * Gets the context of this event without the context of the stream - * - * @return the context in struct form - * @since 1.2 - */ - public StructDefinition getEventContext() { - return fEventContext; - } - - /** - * Gets the context of this event within a stream - * - * @return the context in struct form - */ - public StructDefinition getContext() { - - /* Most common case so far */ - if (fStreamContext == null) { - return fEventContext; - } - - /* streamContext is not null, but the context of the event is null */ - if (fEventContext == null) { - return fStreamContext; - } - - // TODO: cache if this is a performance issue - - /* The stream context and event context are assigned. */ - StructDeclaration mergedDeclaration = new StructDeclaration(1); - - Builder<String> builder = ImmutableList.<String> builder(); - List<Definition> fieldValues = new ArrayList<>(); - - /* Add fields from the stream */ - for (String fieldName : fStreamContext.getFieldNames()) { - Definition definition = fStreamContext.getDefinition(fieldName); - mergedDeclaration.addField(fieldName, definition.getDeclaration()); - builder.add(fieldName); - fieldValues.add(definition); - } - - ImmutableList<String> fieldNames = builder.build(); - /* - * Add fields from the event context, overwrite the stream ones if - * needed. - */ - for (String fieldName : fEventContext.getFieldNames()) { - Definition definition = fEventContext.getDefinition(fieldName); - mergedDeclaration.addField(fieldName, definition.getDeclaration()); - if (fieldNames.contains(fieldName)) { - fieldValues.set((fieldNames.indexOf(fieldName)), definition); - } else { - builder.add(fieldName); - fieldValues.add(definition); - } - } - fieldNames = builder.build(); - StructDefinition mergedContext = new StructDefinition(mergedDeclaration, this, "context", //$NON-NLS-1$ - fieldNames, - fieldValues.toArray(new Definition[fieldValues.size()])); - return mergedContext; - } - - /** - * Gets the stream input reader that this event was made by - * - * @return the parent - * @since 3.0 - */ - public CTFStreamInputReader getStreamInputReader() { - return fStreamInputReader; - } - - /** - * Gets the context of packet the event is in. - * - * @return the packet context - */ - public StructDefinition getPacketContext() { - return fPacketContext; - } - - /** - * gets the CPU the event was generated by. Slightly LTTng specific - * - * @return The CPU the event was generated by - */ - public int getCPU() { - return fStreamInputReader.getCPU(); - } - - /** - * @return the timestamp - */ - public long getTimestamp() { - return fTimestamp; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public Definition lookupDefinition(String lookupPath) { - if (lookupPath.equals("context")) { //$NON-NLS-1$ - return fEventContext; - } else if (lookupPath.equals("fields")) { //$NON-NLS-1$ - return fFields; - } else { - return null; - } - } - - @Override - public String toString() { - Iterable<String> list; - StringBuilder retString = new StringBuilder(); - final String cr = System.getProperty("line.separator");//$NON-NLS-1$ - - retString.append("Event type: " + fDeclaration.getName() + cr); //$NON-NLS-1$ - retString.append("Timestamp: " + Long.toString(fTimestamp) + cr); //$NON-NLS-1$ - - if (fEventContext != null) { - list = fEventContext.getDeclaration().getFieldsList(); - - for (String field : list) { - retString.append(field - + " : " + fEventContext.getDefinition(field).toString() + cr); //$NON-NLS-1$ - } - } - - if (fFields != null) { - list = fFields.getDeclaration().getFieldsList(); - - for (String field : list) { - retString.append(field - + " : " + fFields.getDefinition(field).toString() + cr); //$NON-NLS-1$ - } - } - - return retString.toString(); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/IEventDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/IEventDeclaration.java deleted file mode 100644 index 6107114716..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/IEventDeclaration.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event; - -import java.util.Set; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.CTFStream; -import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader; - -/** - * Representation of one type of event. A bit like "int" or "long" but for trace - * events. - * - * @author Matthew Khouzam - * @since 2.0 - */ -public interface IEventDeclaration { - - /** - * Creates an instance of EventDefinition corresponding to this declaration. - * - * @param streamInputReader - * The StreamInputReader for which this definition is created. - * @param input - * the bitbuffer input source - * @param timestamp - * The timestamp when the event was taken - * @return A new EventDefinition. - * @throws CTFReaderException - * As a bitbuffer is used to read, it could have wrapped - * IOExceptions. - * @since 3.0 - */ - EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException; - - /** - * Gets the name of an event declaration - * - * @return the name - */ - String getName(); - - /** - * Gets the fields of an event declaration - * - * @return fields the fields in {@link StructDeclaration} format - */ - StructDeclaration getFields(); - - /** - * Gets the context of an event declaration - * - * @return context the fields in {@link StructDeclaration} format - */ - StructDeclaration getContext(); - - /** - * Gets the id of an event declaration - * - * @return The EventDeclaration ID - */ - Long getId(); - - /** - * Gets the {@link CTFStream} of an event declaration - * - * @return the stream - * @since 3.0 - */ - CTFStream getStream(); - - /** - * What is the log level of this event? - * - * @return the log level. - * @since 2.0 - */ - long getLogLevel(); - - /** - * Get the {@link Set} of names of the custom CTF attributes. - * - * @return The set of custom attributes - * @since 2.0 - */ - Set<String> getCustomAttributes(); - - /** - * Get the value of a given CTF attribute. - * - * @param key - * The CTF attribute name - * @return the CTF attribute - * @since 2.0 - */ - String getCustomAttribute(String key); - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java deleted file mode 100644 index 0556371273..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java +++ /dev/null @@ -1,687 +0,0 @@ -/*******************************************************************************. - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial Design and implementation + overhaul - * Francis Giraldeau - Initial API and implementation - * Philippe Proulx - Some refinement and optimization - * Etienne Bergeron <Etienne.Bergeron@gmail.com> - fix zero size read + cleanup - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.io; - -import java.nio.BufferUnderflowException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * <b><u>BitBuffer</u></b> - * <p> - * A bitwise buffer capable of accessing fields with bit offsets. - * - * @since 2.0 - */ -public final class BitBuffer { - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - /* default bit width */ - /** 8 bits to a char */ - public static final int BIT_CHAR = 8; - /** 16 bits to a short */ - public static final int BIT_SHORT = 16; - /** 32 bits to an int */ - public static final int BIT_INT = 32; - /** 32 bits to a float */ - public static final int BIT_FLOAT = 32; - /** 64 bits to a long */ - public static final int BIT_LONG = 64; - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final @NonNull ByteBuffer fBuffer; - private final long fBitCapacity; - - /** - * Bit-buffer's position, maximum value = Integer.MAX_VALUE * 8 - */ - private long fPosition; - private ByteOrder fByteOrder; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - /** - * Default constructor, makes a big-endian buffer - */ - @SuppressWarnings("null") - public BitBuffer() { - this(ByteBuffer.allocateDirect(0), ByteOrder.BIG_ENDIAN); - } - - /** - * Constructor, makes a big-endian buffer - * - * @param buf - * the bytebuffer to read - */ - public BitBuffer(@NonNull ByteBuffer buf) { - this(buf, ByteOrder.BIG_ENDIAN); - } - - /** - * Constructor that is fully parameterizable - * - * @param buf - * the buffer to read - * @param order - * the byte order (big-endian, little-endian, network?) - */ - public BitBuffer(@NonNull ByteBuffer buf, ByteOrder order) { - fBuffer = buf; - setByteOrder(order); - resetPosition(); - fBitCapacity = fBuffer.capacity() * BIT_CHAR; - } - - private void resetPosition() { - fPosition = 0; - } - - // ------------------------------------------------------------------------ - // 'Get' operations on buffer - // ------------------------------------------------------------------------ - - /** - * Relative <i>get</i> method for reading 32-bit integer. - * - * Reads next four bytes from the current bit position according to current - * byte order. - * - * @return The int value (signed) read from the buffer - * @throws CTFReaderException - * An error occurred reading the long. This exception can be - * raised if the buffer tries to read out of bounds - */ - public int getInt() throws CTFReaderException { - return getInt(BIT_INT, true); - } - - /** - * Relative <i>get</i> method for reading 64-bit integer. - * - * Reads next eight bytes from the current bit position according to current - * byte order. - * - * @return The long value (signed) read from the buffer - * @throws CTFReaderException - * An error occurred reading the long. This exception can be - * raised if the buffer tries to read out of bounds - * @since 3.0 - */ - public long getLong() throws CTFReaderException { - return get(BIT_LONG, true); - } - - /** - * Relative <i>get</i> method for reading long of <i>length</i> bits. - * - * Reads <i>length</i> bits starting at the current position. The result is - * signed extended if <i>signed</i> is true. The current position is - * increased of <i>length</i> bits. - * - * @param length - * The length in bits of this integer - * @param signed - * The sign extended flag - * @return The long value read from the buffer - * @throws CTFReaderException - * An error occurred reading the data. If more than 64 bits at a - * time are read, or the buffer is read beyond its end, this - * exception will be raised. - * @since 3.0 - */ - public long get(int length, boolean signed) throws CTFReaderException { - if (length > BIT_LONG) { - throw new CTFReaderException("Cannot read a long longer than 64 bits. Rquested: " + length); //$NON-NLS-1$ - } - if (length > BIT_INT) { - final int highShift = length - BIT_INT; - long a = getInt(); - long b = getInt(highShift, false); - long retVal; - /* Cast the signed-extended int into a unsigned int. */ - a &= 0xFFFFFFFFL; - b &= (1L << highShift) - 1L; - - retVal = (fByteOrder == ByteOrder.BIG_ENDIAN) ? ((a << highShift) | b) : ((b << BIT_INT) | a); - /* sign extend */ - if (signed) { - int signExtendBits = BIT_LONG - length; - retVal = (retVal << signExtendBits) >> signExtendBits; - } - return retVal; - } - long retVal = getInt(length, signed); - return (signed ? retVal : (retVal & 0xFFFFFFFFL)); - } - - /** - * Relative bulk <i>get</i> method. - * - * <p> - * This method transfers <strong>bytes</strong> from this buffer into the - * given destination array. This method currently only supports reads - * aligned to 8 bytes. It is up to the developer to shift the bits in - * post-processing to do unaligned reads. - * - * @param dst - * the bytes to write to - * @throws BufferUnderflowException - * - If there are fewer than length bytes remaining in this - * buffer - * @since 3.1 - */ - public void get(@NonNull byte[] dst) { - fBuffer.position((int) (fPosition / 8)); - fBuffer.get(dst); - fPosition += dst.length * 8; - } - - /** - * Relative <i>get</i> method for reading integer of <i>length</i> bits. - * - * Reads <i>length</i> bits starting at the current position. The result is - * signed extended if <i>signed</i> is true. The current position is - * increased of <i>length</i> bits. - * - * @param length - * The length in bits of this integer - * @param signed - * The sign extended flag - * @return The int value read from the buffer - * @throws CTFReaderException - * An error occurred reading the data. When the buffer is read - * beyond its end, this exception will be raised. - */ - private int getInt(int length, boolean signed) throws CTFReaderException { - - /* Nothing to read. */ - if (length == 0) { - return 0; - } - - /* Validate that the buffer has enough bits. */ - if (!canRead(length)) { - throw new CTFReaderException("Cannot read the integer, " + //$NON-NLS-1$ - "the buffer does not have enough remaining space. " + //$NON-NLS-1$ - "Requested:" + length); //$NON-NLS-1$ - } - - /* Get the value from the byte buffer. */ - int val = 0; - boolean gotIt = false; - - /* - * Try a fast read when the position is byte-aligned by using - * java.nio.ByteBuffer's native methods - */ - /* - * A faster alignment detection as the compiler cannot guaranty that pos - * is always positive. - */ - if ((fPosition & (BitBuffer.BIT_CHAR - 1)) == 0) { - switch (length) { - case BitBuffer.BIT_CHAR: - // Byte - val = fBuffer.get((int) (fPosition / 8)); - if (!signed) { - val = val & 0xff; - } - gotIt = true; - break; - - case BitBuffer.BIT_SHORT: - // Word - val = fBuffer.getShort((int) (fPosition / 8)); - if (!signed) { - val = val & 0xffff; - } - gotIt = true; - break; - - case BitBuffer.BIT_INT: - // Double word - val = fBuffer.getInt((int) (fPosition / 8)); - gotIt = true; - break; - - default: - break; - } - } - - /* When not byte-aligned, fall-back to a general decoder. */ - if (!gotIt) { - // Nothing read yet: use longer methods - if (fByteOrder == ByteOrder.LITTLE_ENDIAN) { - val = getIntLE(fPosition, length, signed); - } else { - val = getIntBE(fPosition, length, signed); - } - } - fPosition += length; - - return val; - } - - private int getIntBE(long index, int length, boolean signed) { - if ((length <= 0) || (length > BIT_INT)) { - throw new IllegalArgumentException("Length must be between 1-32 bits"); //$NON-NLS-1$ - } - long end = index + length; - int startByte = (int) (index / BIT_CHAR); - int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR); - int currByte, lshift, cshift, mask, cmask, cache; - int value = 0; - - currByte = startByte; - cache = fBuffer.get(currByte) & 0xFF; - boolean isNeg = (cache & (1 << (BIT_CHAR - (index % BIT_CHAR) - 1))) != 0; - if (signed && isNeg) { - value = ~0; - } - if (startByte == (endByte - 1)) { - cmask = cache >>> ((BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR); - if (((length) % BIT_CHAR) > 0) { - mask = ~((~0) << length); - cmask &= mask; - } - value <<= length; - value |= cmask; - return value; - } - cshift = (int) (index % BIT_CHAR); - if (cshift > 0) { - mask = ~((~0) << (BIT_CHAR - cshift)); - cmask = cache & mask; - lshift = BIT_CHAR - cshift; - value <<= lshift; - value |= cmask; - currByte++; - } - for (; currByte < (endByte - 1); currByte++) { - value <<= BIT_CHAR; - value |= fBuffer.get(currByte) & 0xFF; - } - lshift = (int) (end % BIT_CHAR); - if (lshift > 0) { - mask = ~((~0) << lshift); - cmask = fBuffer.get(currByte) & 0xFF; - cmask >>>= BIT_CHAR - lshift; - cmask &= mask; - value <<= lshift; - value |= cmask; - } else { - value <<= BIT_CHAR; - value |= fBuffer.get(currByte) & 0xFF; - } - return value; - } - - private int getIntLE(long index, int length, boolean signed) { - if ((length <= 0) || (length > BIT_INT)) { - throw new IllegalArgumentException("Length must be between 1-32 bits"); //$NON-NLS-1$ - } - long end = index + length; - int startByte = (int) (index / BIT_CHAR); - int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR); - int currByte, lshift, cshift, mask, cmask, cache, mod; - int value = 0; - - currByte = endByte - 1; - cache = fBuffer.get(currByte) & 0xFF; - mod = (int) (end % BIT_CHAR); - lshift = (mod > 0) ? mod : BIT_CHAR; - boolean isNeg = (cache & (1 << (lshift - 1))) != 0; - if (signed && isNeg) { - value = ~0; - } - if (startByte == (endByte - 1)) { - cmask = cache >>> (index % BIT_CHAR); - if (((length) % BIT_CHAR) > 0) { - mask = ~((~0) << length); - cmask &= mask; - } - value <<= length; - value |= cmask; - return value; - } - cshift = (int) (end % BIT_CHAR); - if (cshift > 0) { - mask = ~((~0) << cshift); - cmask = cache & mask; - value <<= cshift; - value |= cmask; - currByte--; - } - for (; currByte >= (startByte + 1); currByte--) { - value <<= BIT_CHAR; - value |= fBuffer.get(currByte) & 0xFF; - } - lshift = (int) (index % BIT_CHAR); - if (lshift > 0) { - mask = ~((~0) << (BIT_CHAR - lshift)); - cmask = fBuffer.get(currByte) & 0xFF; - cmask >>>= lshift; - cmask &= mask; - value <<= (BIT_CHAR - lshift); - value |= cmask; - } else { - value <<= BIT_CHAR; - value |= fBuffer.get(currByte) & 0xFF; - } - return value; - } - - // ------------------------------------------------------------------------ - // 'Put' operations on buffer - // ------------------------------------------------------------------------ - - /** - * Relative <i>put</i> method to write signed 32-bit integer. - * - * Write four bytes starting from current bit position in the buffer - * according to the current byte order. The current position is increased of - * <i>length</i> bits. - * - * @param value - * The int value to write - * @throws CTFReaderException - * An error occurred writing the data. If the buffer is written - * beyond its end, this exception will be raised. - */ - public void putInt(int value) throws CTFReaderException { - putInt(BIT_INT, value); - } - - /** - * Relative <i>put</i> method to write <i>length</i> bits integer. - * - * Writes <i>length</i> lower-order bits from the provided <i>value</i>, - * starting from current bit position in the buffer. Sequential bytes are - * written according to the current byte order. The sign bit is carried to - * the MSB if signed is true. The sign bit is included in <i>length</i>. The - * current position is increased of <i>length</i>. - * - * @param length - * The number of bits to write - * @param value - * The value to write - * @throws CTFReaderException - * An error occurred writing the data. If the buffer is written - * beyond its end, this exception will be raised. - */ - public void putInt(int length, int value) throws CTFReaderException { - final long curPos = fPosition; - - if (!canRead(length)) { - throw new CTFReaderException("Cannot write to bitbuffer, " //$NON-NLS-1$ - + "insufficient space. Requested: " + length); //$NON-NLS-1$ - } - if (length == 0) { - return; - } - if (fByteOrder == ByteOrder.LITTLE_ENDIAN) { - putIntLE(curPos, length, value); - } else { - putIntBE(curPos, length, value); - } - fPosition += length; - } - - private void putIntBE(long index, int length, int value) { - if ((length <= 0) || (length > BIT_INT)) { - throw new IllegalArgumentException("Length must be between 1-32 bits"); //$NON-NLS-1$ - } - long end = index + length; - int startByte = (int) (index / BIT_CHAR); - int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR); - int currByte, lshift, cshift, mask, cmask; - int correctedValue = value; - - /* - * mask v high bits. Works for unsigned and two complement signed - * numbers which value do not overflow on length bits. - */ - - if (length < BIT_INT) { - correctedValue &= ~(~0 << length); - } - - /* sub byte */ - if (startByte == (endByte - 1)) { - lshift = (int) ((BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR); - mask = ~((~0) << lshift); - if ((index % BIT_CHAR) > 0) { - mask |= (~(0)) << (BIT_CHAR - (index % BIT_CHAR)); - } - cmask = correctedValue << lshift; - /* - * low bits are cleared because of left-shift and high bits are - * already cleared - */ - cmask &= ~mask; - int b = fBuffer.get(startByte) & 0xFF; - fBuffer.put(startByte, (byte) ((b & mask) | cmask)); - return; - } - - /* head byte contains MSB */ - currByte = endByte - 1; - cshift = (int) (end % BIT_CHAR); - if (cshift > 0) { - lshift = BIT_CHAR - cshift; - mask = ~((~0) << lshift); - cmask = correctedValue << lshift; - cmask &= ~mask; - int b = fBuffer.get(currByte) & 0xFF; - fBuffer.put(currByte, (byte) ((b & mask) | cmask)); - correctedValue >>>= cshift; - currByte--; - } - - /* middle byte(s) */ - for (; currByte >= (startByte + 1); currByte--) { - fBuffer.put(currByte, (byte) correctedValue); - correctedValue >>>= BIT_CHAR; - } - /* end byte contains LSB */ - if ((index % BIT_CHAR) > 0) { - mask = (~0) << (BIT_CHAR - (index % BIT_CHAR)); - cmask = correctedValue & ~mask; - int b = fBuffer.get(currByte) & 0xFF; - fBuffer.put(currByte, (byte) ((b & mask) | cmask)); - } else { - fBuffer.put(currByte, (byte) correctedValue); - } - } - - private void putIntLE(long index, int length, int value) { - if ((length <= 0) || (length > BIT_INT)) { - throw new IllegalArgumentException("Length must be between 1-32 bits"); //$NON-NLS-1$ - } - long end = index + length; - int startByte = (int) (index / BIT_CHAR); - int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR); - int currByte, lshift, cshift, mask, cmask; - int correctedValue = value; - - /* - * mask v high bits. Works for unsigned and two complement signed - * numbers which value do not overflow on length bits. - */ - - if (length < BIT_INT) { - correctedValue &= ~(~0 << length); - } - - /* sub byte */ - if (startByte == (endByte - 1)) { - lshift = (int) (index % BIT_CHAR); - mask = ~((~0) << lshift); - if ((end % BIT_CHAR) > 0) { - mask |= (~(0)) << (end % BIT_CHAR); - } - cmask = correctedValue << lshift; - /* - * low bits are cleared because of left-shift and high bits are - * already cleared - */ - cmask &= ~mask; - int b = fBuffer.get(startByte) & 0xFF; - fBuffer.put(startByte, (byte) ((b & mask) | cmask)); - return; - } - - /* head byte */ - currByte = startByte; - cshift = (int) (index % BIT_CHAR); - if (cshift > 0) { - mask = ~((~0) << cshift); - cmask = correctedValue << cshift; - cmask &= ~mask; - int b = fBuffer.get(currByte) & 0xFF; - fBuffer.put(currByte, (byte) ((b & mask) | cmask)); - correctedValue >>>= BIT_CHAR - cshift; - currByte++; - } - - /* middle byte(s) */ - for (; currByte < (endByte - 1); currByte++) { - fBuffer.put(currByte, (byte) correctedValue); - correctedValue >>>= BIT_CHAR; - } - /* end byte */ - if ((end % BIT_CHAR) > 0) { - mask = (~0) << (end % BIT_CHAR); - cmask = correctedValue & ~mask; - int b = fBuffer.get(currByte) & 0xFF; - fBuffer.put(currByte, (byte) ((b & mask) | cmask)); - } else { - fBuffer.put(currByte, (byte) correctedValue); - } - } - - // ------------------------------------------------------------------------ - // Buffer attributes handling - // ------------------------------------------------------------------------ - - /** - * Can this buffer be read for thus amount of bits? - * - * @param length - * the length in bits to read - * @return does the buffer have enough room to read the next "length" - */ - public boolean canRead(int length) { - return ((fPosition + length) <= fBitCapacity); - } - - /** - * Sets the order of the buffer. - * - * @param order - * The order of the buffer. - */ - public void setByteOrder(ByteOrder order) { - fByteOrder = order; - fBuffer.order(order); - } - - /** - * Sets the order of the buffer. - * - * @return The order of the buffer. - */ - public ByteOrder getByteOrder() { - return fByteOrder; - } - - /** - * Sets the position in the buffer. - * - * @param newPosition - * The new position of the buffer. - * @throws CTFReaderException - * Thrown on out of bounds exceptions - * @since 3.0 - */ - public void position(long newPosition) throws CTFReaderException { - - - if (newPosition > fBitCapacity) { - throw new CTFReaderException("Out of bounds exception on a position move, attempting to access position: " + newPosition); //$NON-NLS-1$ - } - fPosition = newPosition; - } - - /** - * - * Sets the position in the buffer. - * - * @return order The position of the buffer. - * @since 3.0 - */ - public long position() { - return fPosition; - } - - /** - * Sets the byte buffer - * - * @param buf - * the byte buffer - */ - @Deprecated - public void setByteBuffer(ByteBuffer buf) { - /* - * to avoid "The method setByteBuffer(ByteBuffer) from the type - * BitBuffer can be declared as static" - */ - long data = fPosition; - fPosition = data; - throw new UnsupportedOperationException("Bytebuffers are now final"); //$NON-NLS-1$ - - } - - /** - * Gets the byte buffer - * - * @return The byte buffer - */ - public ByteBuffer getByteBuffer() { - return fBuffer; - } - - /** - * Resets the bitbuffer. - */ - public void clear() { - resetPosition(); - fBuffer.clear(); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderScope.java deleted file mode 100644 index e5d3d89855..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderScope.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * A lttng specific speedup node (the packet header with ID and V) of a lexical - * scope - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public class EventHeaderScope extends LexicalScope { - - /** - * Event header id string - */ - public static final LexicalScope EVENT_HEADER_ID = new LexicalScope(EVENT_HEADER, "id"); //$NON-NLS-1$ - - /** - * Event header v as in variant string - */ - public static final LexicalScope EVENT_HEADER_V = new EventHeaderVScope(EVENT_HEADER, "v"); //$NON-NLS-1$ - - /** - * The scope constructor - * - * @param parent - * The parent node, can be null, but shouldn't - * @param name - * the name of the field - */ - public EventHeaderScope(LexicalScope parent, String name) { - super(parent, name); - } - - @Override - @Nullable - public LexicalScope getChild(String name) { - if (name.equals(EVENT_HEADER_ID.getName())) { - return EVENT_HEADER_ID; - } - if (name.equals(EVENT_HEADER_V.getName())) { - return EVENT_HEADER_V; - } - return super.getChild(name); - } - - @Override - public String toString() { - return "event.header"; //$NON-NLS-1$ - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderVScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderVScope.java deleted file mode 100644 index 7b213c2caa..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderVScope.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * A lttng specific speedup node (v variant for event headers) of a lexical - * scope they normally contain a timestamp - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public class EventHeaderVScope extends LexicalScope { - - /** - * Packet header v id string - */ - public static final LexicalScope PACKET_HEADER_V_ID = new LexicalScope(PACKET_HEADER, "id"); //$NON-NLS-1$ - /** - * Packet header v timestamp string - */ - public static final LexicalScope PACKET_HEADER_V_TIMESTAMP = new LexicalScope(PACKET_HEADER, "timestamp"); //$NON-NLS-1$ - - /** - * The scope constructor - * - * @param parent - * The parent node, can be null, but shouldn't - * @param name - * the name of the field - */ - public EventHeaderVScope(LexicalScope parent, String name) { - super(parent, name); - } - - @Override - @Nullable - public LexicalScope getChild(String name) { - if (name.equals(PACKET_HEADER_V_TIMESTAMP.getName())) { - return PACKET_HEADER_V_TIMESTAMP; - } - if (name.equals(PACKET_HEADER_V_ID.getName())) { - return PACKET_HEADER_V_ID; - } - return super.getChild(name); - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/FieldsScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/FieldsScope.java deleted file mode 100644 index 1740cd7bc8..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/FieldsScope.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * A lttng specific speedup node field scope of a lexical scope - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public class FieldsScope extends LexicalScope { - - /** - * ret field - */ - public static final LexicalScope FIELDS_RET = new LexicalScope(FIELDS, "_ret"); //$NON-NLS-1$ - - /** - * tid field - */ - public static final LexicalScope FIELDS_TID = new LexicalScope(FIELDS, "_tid"); //$NON-NLS-1$ - - /** - * The scope constructor - * - * @param parent - * The parent node, can be null, but shouldn't - * @param name - * the name of the field - */ - public FieldsScope(LexicalScope parent, String name) { - super(parent, name); - } - - @Override - @Nullable - public LexicalScope getChild(String name) { - if (name.equals(FIELDS_RET.getName())) { - return FIELDS_RET; - } - if (name.equals(FIELDS_TID.getName())) { - return FIELDS_TID; - } - return super.getChild(name); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/IDefinitionScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/IDefinitionScope.java deleted file mode 100644 index 864a574a1e..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/IDefinitionScope.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import org.eclipse.linuxtools.ctf.core.event.types.Definition; - -/** - * The scope of a CTF definition. Used for compound types. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - * @since 3.0 - */ -public interface IDefinitionScope { - - /** - * Gets the path in a C style for the scope. - * - * @return the path - * @since 3.0 - */ - LexicalScope getScopePath(); - - /** - * Looks up in this definition scope. - * - * @param lookupPath - * The path to look up - * @return The Definition that was read - */ - // TODO: change to IDefintion - Definition lookupDefinition(String lookupPath); -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/LexicalScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/LexicalScope.java deleted file mode 100644 index 6eb9422de5..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/LexicalScope.java +++ /dev/null @@ -1,291 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -import com.google.common.base.Joiner; - -/** - * A node of a lexical scope - * - * @author Matthew Khouzam - * @since 3.0 - */ -@NonNullByDefault -public class LexicalScope implements Comparable<LexicalScope> { - /** - * Empty string - * - * @since 3.0 - */ - public static final LexicalScope ROOT = new RootScope(); - - /** - * Trace string - * - * @since 3.0 - */ - public static final LexicalScope TRACE = new LexicalScope(ROOT, "trace"); //$NON-NLS-1$ - - /** - * Env string - * - * @since 3.0 - */ - public static final LexicalScope ENV = new LexicalScope(ROOT, "env"); //$NON-NLS-1$ - - /** - * Stream string - * - * @since 3.0 - */ - public static final LexicalScope STREAM = new LexicalScope(ROOT, "stream"); //$NON-NLS-1$ - - /** - * Event string - * - * @since 3.0 - */ - public static final LexicalScope EVENT = new LexicalScope(ROOT, "event"); //$NON-NLS-1$ - - /** - * Variant string - * - * @since 3.0 - */ - public static final LexicalScope VARIANT = new LexicalScope(ROOT, "variant"); //$NON-NLS-1$ - - /** - * packet string - * - * @since 3.0 - */ - public static final LexicalScope PACKET = new LexicalScope(ROOT, "packet"); //$NON-NLS-1$ - - /** - * Packet header string - * - * @since 3.0 - * - */ - public static final LexicalScope PACKET_HEADER = new PacketHeaderScope(); - - /** - * Stream packet scope - * - * @since 3.0 - */ - public static final LexicalScope STREAM_PACKET = new LexicalScope(STREAM, "packet"); //$NON-NLS-1$ - - /** - * Stream Packet header string - * - * @since 3.0 - */ - public static final LexicalScope STREAM_PACKET_CONTEXT = new LexicalScope(STREAM_PACKET, "context"); //$NON-NLS-1$ - - /** - * Trace packet scope - * - * @since 3.0 - */ - public static final LexicalScope TRACE_PACKET = new LexicalScope(TRACE, "packet"); //$NON-NLS-1$ - - /** - * Stream event scope - * - * @since 3.0 - */ - public static final LexicalScope STREAM_EVENT = new LexicalScope(STREAM, "event"); //$NON-NLS-1$ - - /** - * Trace packet header string - * - * @since 3.0 - */ - public static final LexicalScope TRACE_PACKET_HEADER = new LexicalScope(TRACE_PACKET, "header"); //$NON-NLS-1$ - - /** - * Stream event context - * - * @since 3.0 - */ - public static final LexicalScope STREAM_EVENT_CONTEXT = new LexicalScope(STREAM_EVENT, "context"); //$NON-NLS-1$ - - /** - * Stream event header - * - * @since 3.0 - */ - public static final LexicalScope STREAM_EVENT_HEADER = new LexicalScope(STREAM_EVENT, "header"); //$NON-NLS-1$ - - /** - * Event header - * - * @since 3.1 - */ - public static final LexicalScope EVENT_HEADER = new EventHeaderScope(EVENT, "header"); //$NON-NLS-1$ - - /** - * Fields in an event - * - * @since 3.0 - */ - public static final LexicalScope FIELDS = new FieldsScope(ROOT, "fields"); //$NON-NLS-1$ - - /** - * Context of an event - * - * @since 3.0 - */ - public static final LexicalScope CONTEXT = new LexicalScope(ROOT, "context"); //$NON-NLS-1$ - - /** - * Sorted list of parent paths - * - * @since 3.0 - */ - public static final LexicalScope[] PARENT_PATHS = { - ROOT, - CONTEXT, - FIELDS, - PACKET_HEADER, - STREAM_EVENT_CONTEXT, - STREAM_EVENT_HEADER, - STREAM_PACKET_CONTEXT, - TRACE_PACKET_HEADER - }; - - private int hash = 0; - private final String fName; - private final String fPath; - private final Map<String, LexicalScope> fChildren; - - /** - * The scope constructor - * - * @param parent - * The parent node, can be null, but shouldn't - * @param name - * the name of the field - */ - @SuppressWarnings("null") - public LexicalScope(@Nullable LexicalScope parent, String name) { - fName = name; - if (parent != null) { - String pathString = Joiner.on('.').skipNulls().join(parent.fPath, parent.getName()); - /* - * if joiner return null, we get an NPE... so we won't assign fPath - * to null - */ - if (pathString.startsWith(".")) { //$NON-NLS-1$ - /* - * substring throws an exception or returns a string, it won't - * return null - */ - pathString = pathString.substring(1); - } - fPath = pathString; - parent.addChild(fName, this); - } else { - fPath = ""; //$NON-NLS-1$ - } - @NonNull - Map<String, LexicalScope> children = - Collections.synchronizedMap(new HashMap<String, LexicalScope>()); - fChildren = children; - } - - /** - * Adds a child lexical scope - * - * @param name - * the name of the child - * @param child - * the child - */ - private void addChild(String name, LexicalScope child) { - fChildren.put(name, child); - } - - /** - * Get the name - * - * @return the name - */ - public String getName() { - return fName; - } - - /** - * Gets a child of a given name - * - * @param name - * the child - * @return the scope, can be null - */ - @Nullable - public LexicalScope getChild(String name) { - return fChildren.get(name); - } - - @Override - public String toString() { - return (fPath.isEmpty() ? fName : fPath + '.' + fName); - } - - @Override - public int compareTo(@Nullable LexicalScope other) { - if (other == null) { - throw new IllegalArgumentException(); - } - int comp = fPath.compareTo(other.fPath); - if (comp == 0) { - return fName.compareTo(other.fName); - } - return comp; - } - - @Override - public synchronized int hashCode() { - if (hash == 0) { - final int prime = 31; - hash = prime * (prime + fName.hashCode()) + fPath.hashCode(); - } - return hash; - } - - @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - LexicalScope other = (LexicalScope) obj; - if (!fName.equals(other.fName)) { - return false; - } - return fPath.equals(other.fPath); - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/PacketHeaderScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/PacketHeaderScope.java deleted file mode 100644 index a47101c6fb..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/PacketHeaderScope.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * A lttng specific speedup node (the packet header with magic, uuid and stream - * id ) of a lexical scope the sole reason to have this is to accelerate tostring() - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public class PacketHeaderScope extends LexicalScope { - - /** - * Constructor - */ - public PacketHeaderScope() { - super(PACKET, "header"); //$NON-NLS-1$ - } - - @Override - public String toString() { - return "packet.header"; //$NON-NLS-1$ - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/RootScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/RootScope.java deleted file mode 100644 index ab187df2b7..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/RootScope.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.scope; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * A lttng specific speedup node a root with accelerated returns for some scopes - * of a lexical scope - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public class RootScope extends LexicalScope { - - /** - * The scope constructor - */ - public RootScope() { - super(null, ""); //$NON-NLS-1$ - } - - @Override - @Nullable - public LexicalScope getChild(String name) { - /* - * This happens ~40 % of the time - */ - if (name.equals(EVENT_HEADER.toString())) { - return EVENT_HEADER; - } - /* - * This happens ~30 % of the time - */ - if (name.equals(FIELDS.toString())) { - return FIELDS; - } - /* - * This happens ~30 % of the time - */ - if (name.equals(CONTEXT.toString())) { - return CONTEXT; - } - /* - * This happens ~1 % of the time - */ - if (name.equals(PACKET_HEADER.toString())) { - return PACKET_HEADER; - } - return super.getChild(name); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/AbstractArrayDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/AbstractArrayDefinition.java deleted file mode 100644 index f724f25c97..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/AbstractArrayDefinition.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.List; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * Array definition, used for compound definitions and fixed length strings - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public abstract class AbstractArrayDefinition extends Definition { - - /** - * Constructor - * - * @param declaration - * the event declaration - * - * @param definitionScope - * the definition is in a scope, (normally a struct) what is it? - * @param fieldName - * the name of the definition. (it is a field in the parent - * scope) - */ - public AbstractArrayDefinition(IDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName) { - super(declaration, definitionScope, fieldName); - } - - /** - * Get the defintions, an array is a collection of definitions - * - * @return the definitions - */ - public abstract List<Definition> getDefinitions(); - -}
\ No newline at end of file diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java deleted file mode 100644 index fcbc3f3c76..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.List; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.common.collect.Multimap; - -/** - * A CTF array declaration - * - * Arrays are fixed-length. Their length is declared in the type declaration - * within the meta-data. They contain an array of "inner type" elements, which - * can refer to any type not containing the type of the array being declared (no - * circular dependency). The length is the number of elements in an array. - * - * @deprecated use - * {@link org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration} - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -@Deprecated -public class ArrayDeclaration extends CompoundDeclaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final int fLength; - private final IDeclaration fElemType; - - /** - * <pre> - * Cache where we can pre-generate the children names - * Key: parent name - * Value: children names - * ex: field → {field[0], field[1], … field[n]} - * </pre> - * - * TODO: investigate performance - */ - private final Multimap<String, String> fChildrenNames = ArrayListMultimap.<String, String> create(); - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param length - * how many elements in the array - * @param elemType - * what type of element is in the array - */ - public ArrayDeclaration(int length, IDeclaration elemType) { - fLength = length; - fElemType = elemType; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public IDeclaration getElementType() { - return fElemType; - } - - /** - * - * @return how many elements in the array - */ - public int getLength() { - return fLength; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Deprecated - @Override - public ArrayDefinition createDefinition(IDefinitionScope definitionScope, - @NonNull String fieldName, BitBuffer input) throws CTFReaderException { - alignRead(input); - List<Definition> definitions = read(input, definitionScope, fieldName); - return new ArrayDefinition(this, definitionScope, fieldName, definitions); - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - - @NonNull - private List<Definition> read(@NonNull BitBuffer input, IDefinitionScope definitionScope, String fieldName) throws CTFReaderException { - Builder<Definition> definitions = new ImmutableList.Builder<>(); - if (!fChildrenNames.containsKey(fieldName)) { - for (int i = 0; i < fLength; i++) { - fChildrenNames.put(fieldName, fieldName + '[' + i + ']'); - } - } - List<String> elemNames = (List<String>) fChildrenNames.get(fieldName); - for (int i = 0; i < fLength; i++) { - String name = elemNames.get(i); - if (name == null) { - throw new IllegalStateException(); - } - definitions.add(fElemType.createDefinition(definitionScope, name, input)); - } - @SuppressWarnings("null") - @NonNull ImmutableList<Definition> ret = definitions.build(); - return ret; - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - long val = (long) fLength * fElemType.getMaximumSize(); - return (int) Math.min(Integer.MAX_VALUE, val); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java deleted file mode 100644 index 3c0ca255fe..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.List; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; - -/** - * A CTF array definition - * - * Arrays are fixed-length. Their length is declared in the type declaration - * within the meta-data. They contain an array of "inner type" elements, which - * can refer to any type not containing the type of the array being declared (no - * circular dependency). The length is the number of elements in an array. - * - * @deprecated use {@link AbstractArrayDefinition} - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -@NonNullByDefault -@Deprecated -public final class ArrayDefinition extends AbstractArrayDefinition{ - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final ImmutableList<Definition> fDefinitions; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param definitions - * the content of the array - * @since 3.0 - */ - public ArrayDefinition(ArrayDeclaration declaration, - @Nullable IDefinitionScope definitionScope, - String fieldName, - List<Definition> definitions) { - super(declaration, definitionScope, fieldName); - @SuppressWarnings("null") - @NonNull ImmutableList<Definition> list = ImmutableList.copyOf(definitions); - fDefinitions = list; - - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public List<Definition> getDefinitions() { - return fDefinitions; - } - - /** - * Get the element at i - * - * @param i the index (cannot be negative) - * @return The element at I, if I > length, null, if I < 0, the method throws an out of bounds exception - */ - @Nullable - public Definition getElem(int i) { - if (i > fDefinitions.size()) { - return null; - } - - return fDefinitions.get(i); - } - - @Override - public ArrayDeclaration getDeclaration() { - return (ArrayDeclaration) super.getDeclaration(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public String toString() { - StringBuilder b = new StringBuilder(); - - if (getDeclaration().isString()) { - for (Definition def : fDefinitions) { - IntegerDefinition character = (IntegerDefinition) def; - - if (character.getValue() == 0) { - break; - } - - b.append(character.toString()); - } - } else { - b.append('['); - Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$ - b.append(joiner.join(fDefinitions)); - b.append(']'); - } - - @SuppressWarnings("null") - @NonNull String ret = b.toString(); - return ret; - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java deleted file mode 100644 index fc4c0c02c9..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - - -/** - * Parent of sequences and arrays - * - * @author Matthew Khouzam - * @since 3.1 - */ -public abstract class CompoundDeclaration extends Declaration { - - /** - * Get the element type - * - * @return the type of element in the array - */ - public abstract IDeclaration getElementType(); - - @Override - public long getAlignment() { - return getElementType().getAlignment(); - } - - /** - * Sometimes, strings are encoded as an array of 1-byte integers (each one - * being an UTF-8 byte). - * - * @return true if this array is in fact an UTF-8 string. false if it's a - * "normal" array of generic Definition's. - */ - public boolean isString(){ - IDeclaration elementType = getElementType(); - if (elementType instanceof IntegerDeclaration) { - IntegerDeclaration elemInt = (IntegerDeclaration) elementType; - return elemInt.isCharacter(); - } - return false; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Declaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Declaration.java deleted file mode 100644 index df30eaf4dc..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Declaration.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * Declaration base, it helps for basic functionality that is often called, so - * performance is often a high priority in this class - * - * @author Matthew Khouzam - * @since 3.0 - */ -public abstract class Declaration implements IDeclaration { - - @Override - public LexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName) { - if (definitionScope != null) { - final LexicalScope parentPath = definitionScope.getScopePath(); - if (parentPath != null) { - LexicalScope myScope = parentPath.getChild(fieldName); - if (myScope == null) { - myScope = new LexicalScope(parentPath, fieldName); - } - return myScope; - } - } - LexicalScope child = LexicalScope.ROOT.getChild(fieldName); - if (child != null) { - return child; - } - return new LexicalScope(LexicalScope.ROOT, fieldName); - } - - /** - * Offset the buffer position wrt the current alignment. - * - * @param input - * The bitbuffer that is being read - * @throws CTFReaderException - * Happens when there is an out of bounds exception - * @since 3.0 - */ - protected final void alignRead(BitBuffer input) throws CTFReaderException { - long mask = getAlignment() - 1; - /* - * The alignment is a power of 2 - */ - long pos = input.position(); - if ((pos & mask) == 0) { - return; - } - pos = (pos + mask) & ~mask; - input.position(pos); - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java deleted file mode 100644 index 46c64d0452..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; - -/** - * A CTF definition - * - * A definition is like an object of a declaration class. It fills the - * declaration with values. <br> - * An example: <br> - * int i = 0; <br> - * <b>int</b> is the declaration.<br> - * <b>i</b> is the definition.<br> - * <b>0</b> is the value assigned to the definition, not the declaration.<br> - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public abstract class Definition implements IDefinition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final String fFieldName; - - /** The complete path of this field */ - private final @NonNull LexicalScope fPath; - - private final IDefinitionScope fDefinitionScope; - - @NonNull - private final IDeclaration fDeclaration; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the event declaration - * @param definitionScope - * the definition is in a scope, (normally a struct) what is it? - * @param fieldName - * the name of the definition. (it is a field in the parent - * scope) - * @since 3.0 - */ - public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) { - this(declaration, definitionScope, fieldName, declaration.getPath(definitionScope, fieldName)); - } - - /** - * Constructor This one takes the scope and thus speeds up definition - * creation - * - * - * @param declaration - * the event declaration - * - * @param definitionScope - * the definition is in a scope, (normally a struct) what is it? - * - * @param fieldName - * the name of the defintions. it is a field in the parent scope. - * - * @param scope - * the scope - * @since 3.1 - */ - public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull LexicalScope scope) { - fDeclaration = declaration; - fDefinitionScope = definitionScope; - fFieldName = fieldName; - fPath = scope; - } - - // ------------------------------------------------------------------------ - // Getters - // ------------------------------------------------------------------------ - - /** - * Get the field name in its container. - * - * @return The field name - * @since 2.0 - */ - protected String getFieldName() { - return fFieldName; - } - - @Override - public LexicalScope getScopePath() { - return fPath; - } - - /** - * Get the definition scope in which this definition is found. - * - * The complete path of a definition is thus the path of the definition - * scope DOT the name of the definition (name of the field in its container) - * - * @return The definition scope - * @since 3.0 - */ - protected IDefinitionScope getDefinitionScope() { - return fDefinitionScope; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public IDeclaration getDeclaration() { - return fDeclaration; - } - - @Override - public String toString() { - return fPath.toString() + '[' + Integer.toHexString(hashCode()) + ']'; - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java deleted file mode 100644 index a529d1ee6d..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Encoding.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * CTF encoding types - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -@NonNullByDefault -public enum Encoding { - /** UTF-8 encoding */ - UTF8, - /** Ascii encoding */ - ASCII, - /** No encoding, maybe not even text */ - NONE -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java deleted file mode 100644 index 304cb9ad2f..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTF enum declaration. - * - * The definition of a enum point basic data type. It will take the data from a - * trace and store it (and make it fit) as an integer and a string. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class EnumDeclaration extends Declaration implements ISimpleDatatypeDeclaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final EnumTable fTable = new EnumTable(); - private final IntegerDeclaration fContainerType; - private final Set<String> fLabels = new HashSet<>(); - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * constructor - * - * @param containerType - * the enum is an int, this is the type that the data is - * contained in. If you have 1000 possible values, you need at - * least a 10 bit enum. If you store 2 values in a 128 bit int, - * you are wasting space. - */ - public EnumDeclaration(IntegerDeclaration containerType) { - fContainerType = containerType; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * - * @return The container type - */ - public IntegerDeclaration getContainerType() { - return fContainerType; - } - - @Override - public long getAlignment() { - return this.getContainerType().getAlignment(); - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - return fContainerType.getMaximumSize(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public EnumDefinition createDefinition(IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException { - alignRead(input); - IntegerDefinition value = getContainerType().createDefinition(definitionScope, fieldName, input); - return new EnumDefinition(this, definitionScope, fieldName, value); - } - - /** - * Add a value. Do not overlap, this is <em><strong>not</strong></em> an - * interval tree. - * - * @param low - * lowest value that this int can be to have label as a return - * string - * @param high - * highest value that this int can be to have label as a return - * string - * @param label - * the name of the value. - * @return was the value be added? true == success - */ - public boolean add(long low, long high, String label) { - fLabels.add(label); - return fTable.add(low, high, label); - } - - /** - * Check if the label for a value (enum a{day=0,night=1} would return "day" - * for query(0) - * - * @param value - * the value to lookup - * @return the label of that value, can be null - */ - public String query(long value) { - return fTable.query(value); - } - - /** - * Gets a set of labels of the enum - * - * @return A set of labels of the enum, can be empty but not null - * @since 3.0 - */ - public Set<String> getLabels() { - return Collections.unmodifiableSet(fLabels); - } - - /* - * Maps integer range -> string. A simple list for now, but feel free to - * optimize it. Babeltrace suggests an interval tree. - */ - private class EnumTable { - - private final List<LabelAndRange> ranges = new LinkedList<>(); - - public EnumTable() { - } - - public boolean add(long low, long high, String label) { - LabelAndRange newRange = new LabelAndRange(low, high, label); - - for (LabelAndRange r : ranges) { - if (r.intersects(newRange)) { - return false; - } - } - - ranges.add(newRange); - - return true; - } - - /** - * Return the first label that matches a value - * - * @param value - * the value to query - * @return the label corresponding to that value - */ - public String query(long value) { - for (LabelAndRange r : ranges) { - if (r.intersects(value)) { - return r.getLabel(); - } - } - return null; - } - - } - - private static class LabelAndRange { - - private final long low, high; - private final String fLabel; - - /** - * Get the label - * - * @return the label - */ - public String getLabel() { - return fLabel; - } - - public LabelAndRange(long low, long high, String str) { - this.low = low; - this.high = high; - this.fLabel = str; - } - - public boolean intersects(long i) { - return (i >= this.low) && (i <= this.high); - } - - public boolean intersects(LabelAndRange other) { - return this.intersects(other.low) - || this.intersects(other.high); - } - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] enum[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java deleted file mode 100644 index 09f6927f50..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * A CTF enum definition. - * - * The definition of a enum point basic data type. It will take the data from a - * trace and store it (and make it fit) as an integer and a string. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class EnumDefinition extends SimpleDatatypeDefinition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final long fIntegerValue; - - private final String fValue; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param intValue - * the value of the enum - * @since 3.0 - */ - public EnumDefinition(@NonNull EnumDeclaration declaration, - IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) { - super(declaration, definitionScope, fieldName); - - fIntegerValue = intValue.getValue(); - fValue = declaration.query(fIntegerValue); - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Gets the value of the enum in string format so - * "Enum a{DAY="0", NIGHT="1"}; will return "DAY" - * - * @return the value of the enum. - */ - public String getValue() { - return fValue; - } - - @Override - public String getStringValue() { - return getValue(); - } - - /** - * Gets the value of the enum in string format so - * "Enum a{DAY="0", NIGHT="1"}; will return 0 - * - * @return the value of the enum. - */ - @Override - public Long getIntegerValue() { - return fIntegerValue; - } - - @Override - public EnumDeclaration getDeclaration() { - return (EnumDeclaration) super.getDeclaration(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public String toString() { - return "{ value = " + getValue() + //$NON-NLS-1$ - ", container = " + fIntegerValue + //$NON-NLS-1$ - " }"; //$NON-NLS-1$ - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java deleted file mode 100644 index 084cae691f..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.nio.ByteOrder; - -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTF float declaration. - * - * The declaration of a floating point basic data type. - * - * @version 1.0 - * @author Matthew Khouzam - */ -public final class FloatDeclaration extends Declaration implements ISimpleDatatypeDeclaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final int fMantissa; - private final int fExponent; - private final ByteOrder fByteOrder; - private final long fAlignement; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param exponent - * The exponent size in bits - * @param mantissa - * The mantissa size in bits (+1 for sign) (see CTF spec) - * @param byteOrder - * The byte order - * @param alignment - * The alignment. Should be ≥ 1 - */ - public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder, - long alignment) { - fMantissa = mantissa; - fExponent = exponent; - fByteOrder = byteOrder; - fAlignement = Math.max(alignment, 1); - - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * @return the mant - */ - public int getMantissa() { - return fMantissa; - } - - /** - * @return the exp - */ - public int getExponent() { - return fExponent; - } - - /** - * @return the byteOrder - */ - public ByteOrder getByteOrder() { - return fByteOrder; - } - - @Override - public long getAlignment() { - return fAlignement; - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - return fMantissa + fExponent + 1; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public FloatDefinition createDefinition(IDefinitionScope definitionScope, - String fieldName, BitBuffer input) throws CTFReaderException { - ByteOrder byteOrder = input.getByteOrder(); - input.setByteOrder(fByteOrder); - double value = read(input); - input.setByteOrder(byteOrder); - return new FloatDefinition(this, definitionScope, fieldName, value); - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] float[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - - private double read(BitBuffer input) throws CTFReaderException { - /* Offset the buffer position wrt the current alignment */ - alignRead(input); - final int exp = getExponent(); - final int mant = getMantissa(); - double value = Double.NaN; - if ((exp + mant) == 32) { - value = readRawFloat32(input, mant, exp); - } else if ((exp + mant) == 64) { - value = readRawFloat64(input, mant, exp); - } - return value; - } - - private static double readRawFloat32(BitBuffer input, final int manBits, - final int expBits) throws CTFReaderException { - long temp = input.get(32, false); - return createFloat(temp, manBits - 1, expBits); - } - - private static double readRawFloat64(BitBuffer input, final int manBits, - final int expBits) throws CTFReaderException { - long temp = input.get(64, false); - return createFloat(temp, manBits - 1, expBits); - } - - /** - * Create a float from the raw value, Mathematicians beware. - * - * @param rawValue - * The raw value( up to 64 bits) - * @param manBits - * number of bits in the mantissa - * @param expBits - * number of bits in the exponent - */ - private static double createFloat(long rawValue, final int manBits, - final int expBits) { - long manShift = 1L << (manBits); - long manMask = manShift - 1; - long expMask = (1L << expBits) - 1; - - int exp = (int) ((rawValue >> (manBits)) & expMask) + 1; - long man = (rawValue & manMask); - final int offsetExponent = exp - (1 << (expBits - 1)); - double expPow = Math.pow(2.0, offsetExponent); - double ret = man * 1.0f; - ret /= manShift; - ret += 1.0; - ret *= expPow; - return ret; - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java deleted file mode 100644 index aa6d6db27d..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * A CTF float definition. - * - * The definition of a floating point basic data type. It will take the data - * from a trace and store it (and make it fit) as a double. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class FloatDefinition extends Definition { - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final double fValue; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param value - * field value - * @since 3.0 - */ - public FloatDefinition(@NonNull FloatDeclaration declaration, - IDefinitionScope definitionScope, @NonNull String fieldName, double value) { - super(declaration, definitionScope, fieldName); - fValue = value; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * The value of a float stored, fit into a double. This should be extended - * for exotic floats if this is necessary. - * - * @return the value of the float field fit into a double. - */ - public double getValue() { - return fValue; - } - - @Override - public FloatDeclaration getDeclaration() { - return (FloatDeclaration) super.getDeclaration(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public String toString() { - return String.valueOf(fValue); - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ICompositeDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ICompositeDefinition.java deleted file mode 100644 index df27c9a067..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ICompositeDefinition.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.List; - -/** - * Interface for data definitions containing heterogenous definitions - * (subfields) - * - * @author Matthew Khouzam - * @since 3.1 - */ -public interface ICompositeDefinition extends IDefinition { - - /** - * Gets the definition of the field - * - * @param fieldName - * the fieldname - * @return The definitions of all the fields - */ - Definition getDefinition(String fieldName); - - /** - * Gets an array of the field names - * - * @return the field names array - */ - List<String> getFieldNames(); - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java deleted file mode 100644 index 6f0f50712b..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTF data type declaration. - * - * An example: <br> - * int i = 0; <br> - * <b>int</b> is the declaration.<br> - * <b>i</b> is the definition.<br> - * <b>0</b> is the value assigned to the definition, not the declaration.<br> - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public interface IDeclaration { - - /** - * Create a definition from this declaration - * - * @param definitionScope - * the definition scope, the parent where the definition will be - * placed - * @param fieldName - * the name of the definition - * @param input - * a bitbuffer to read from - * @return a reference to the definition - * @throws CTFReaderException - * error in reading - * @since 3.0 - */ - Definition createDefinition(IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull BitBuffer input) throws CTFReaderException; - - /** - * Get the path of a definition - * - * @param definitionScope - * the scope of the definition - * @param fieldName - * the name of the definition - * @return the path of the definition - * @since 3.0 - */ - public @NonNull LexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName); - - /** - * The minimum alignment. if the field is 32 bits, the definition will pad - * all the data up to (position%32==0) - * - * @return the alignment in bits - */ - long getAlignment(); - - /** - * The MAXIMUM size of this declaration - * - * @return the maximum size - * @since 3.0 - */ - int getMaximumSize(); - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinition.java deleted file mode 100644 index ef6d2294b2..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDefinition.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; - -/** - * Interface for data definitions. A definition is when a value is given to a - * declaration - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public interface IDefinition { - - /** - * Get the complete path of this field. - * - * @return The path - */ - LexicalScope getScopePath(); - - /** - * Get the declaration of this definition - * - * @return the declaration of a datatype - */ - IDeclaration getDeclaration(); - -}
\ No newline at end of file diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IEventHeaderDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IEventHeaderDeclaration.java deleted file mode 100644 index f9de437fd7..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IEventHeaderDeclaration.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * Event header declaration abstract class - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public interface IEventHeaderDeclaration extends IDeclaration { - /** - * The id of an event - */ - String ID = "id"; //$NON-NLS-1$ - /** - * The name of a timestamp field - */ - String TIMESTAMP = "timestamp"; //$NON-NLS-1$ - /** - * Extended header - */ - String EXTENDED = "extended"; //$NON-NLS-1$ - /** - * Compact header (not to be confused with compact vs large) - */ - String COMPACT = "compact"; //$NON-NLS-1$ -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ISimpleDatatypeDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ISimpleDatatypeDeclaration.java deleted file mode 100644 index a67556a696..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ISimpleDatatypeDeclaration.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -/** - * Common interface for simple CTF data types (which do not contain sub-fields). - * - * @author Matthew Khouzam - * @since 3.1 - */ -public interface ISimpleDatatypeDeclaration { - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java deleted file mode 100644 index 486553f2cb..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java +++ /dev/null @@ -1,474 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - * Simon Marchi - Initial API and implementation - * Marc-Andre Laperle - Add min/maximum for validation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.math.BigInteger; -import java.nio.ByteOrder; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTF integer declaration. - * - * The declaration of a integer basic data type. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -@NonNullByDefault -public class IntegerDeclaration extends Declaration implements ISimpleDatatypeDeclaration { - - // ------------------------------------------------------------------------ - // Helpers - // ------------------------------------------------------------------------ - - /** - * unsigned int 32 bits big endian - * - * @since 3.0 - */ - public static final IntegerDeclaration UINT_32B_DECL = new IntegerDeclaration(32, false, ByteOrder.BIG_ENDIAN); - /** - * unsigned int 32 bits little endian - * - * @since 3.0 - */ - public static final IntegerDeclaration UINT_32L_DECL = new IntegerDeclaration(32, false, ByteOrder.LITTLE_ENDIAN); - /** - * signed int 32 bits big endian - * - * @since 3.0 - */ - public static final IntegerDeclaration INT_32B_DECL = new IntegerDeclaration(32, true, ByteOrder.BIG_ENDIAN); - /** - * signed int 32 bits little endian - * - * @since 3.0 - */ - public static final IntegerDeclaration INT_32L_DECL = new IntegerDeclaration(32, true, ByteOrder.LITTLE_ENDIAN); - /** - * unsigned int 32 bits big endian - * - * @since 3.0 - */ - public static final IntegerDeclaration UINT_64B_DECL = new IntegerDeclaration(64, false, ByteOrder.BIG_ENDIAN); - /** - * unsigned int 64 bits little endian - * - * @since 3.0 - */ - public static final IntegerDeclaration UINT_64L_DECL = new IntegerDeclaration(64, false, ByteOrder.LITTLE_ENDIAN); - /** - * signed int 64 bits big endian - * - * @since 3.0 - */ - public static final IntegerDeclaration INT_64B_DECL = new IntegerDeclaration(64, true, ByteOrder.BIG_ENDIAN); - /** - * signed int 64 bits little endian - * - * @since 3.0 - */ - public static final IntegerDeclaration INT_64L_DECL = new IntegerDeclaration(64, true, ByteOrder.LITTLE_ENDIAN); - /** - * unsigned 8 bit int endianness doesn't matter since it's 8 bits (byte) - * - * @since 3.0 - */ - public static final IntegerDeclaration UINT_8_DECL = new IntegerDeclaration(8, false, ByteOrder.BIG_ENDIAN); - /** - * signed 8 bit int endianness doesn't matter since it's 8 bits (char) - * - * @since 3.0 - */ - public static final IntegerDeclaration INT_8_DECL = new IntegerDeclaration(8, true, ByteOrder.BIG_ENDIAN); - /** - * Unsigned 5 bit int, used for event headers - * - * @since 3.1 - */ - public static final IntegerDeclaration UINT_5B_DECL = new IntegerDeclaration(5, false, ByteOrder.BIG_ENDIAN); - /** - * Unsigned 5 bit int, used for event headers - * - * @since 3.1 - */ - public static final IntegerDeclaration UINT_5L_DECL = new IntegerDeclaration(5, false, ByteOrder.LITTLE_ENDIAN); - /** - * Unsigned 5 bit int, used for event headers - * - * @since 3.1 - */ - public static final IntegerDeclaration UINT_27B_DECL = new IntegerDeclaration(27, false, ByteOrder.BIG_ENDIAN); - /** - * Unsigned 5 bit int, used for event headers - * - * @since 3.1 - */ - public static final IntegerDeclaration UINT_27L_DECL = new IntegerDeclaration(27, false, ByteOrder.LITTLE_ENDIAN); - /** - * Unsigned 16 bit int, used for event headers - * - * @since 3.1 - */ - public static final IntegerDeclaration UINT_16B_DECL = new IntegerDeclaration(16, false, ByteOrder.BIG_ENDIAN); - /** - * Unsigned 16 bit int, used for event headers - * - * @since 3.1 - */ - public static final IntegerDeclaration UINT_16L_DECL = new IntegerDeclaration(16, false, ByteOrder.LITTLE_ENDIAN); - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final int fLength; - private final boolean fSigned; - private final int fBase; - private final ByteOrder fByteOrder; - private final Encoding fEncoding; - private final long fAlignment; - private final String fClock; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Factory, some common types cached - * - * @param len - * The length in bits - * @param signed - * Is the integer signed? false == unsigned - * @param base - * The base (10-16 are most common) - * @param byteOrder - * Big-endian little-endian or other - * @param encoding - * ascii, utf8 or none. - * @param clock - * The clock path, can be null - * @param alignment - * The minimum alignment. Should be >= 1 - * @return the integer declaration - * @since 3.0 - */ - public static IntegerDeclaration createDeclaration(int len, boolean signed, int base, - @Nullable ByteOrder byteOrder, Encoding encoding, String clock, long alignment) { - if (encoding.equals(Encoding.NONE) && (alignment == 8) && (clock.equals("")) && base == 10) { //$NON-NLS-1$ - switch (len) { - case 5: - if (!signed) { - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return UINT_5B_DECL; - } - return UINT_5L_DECL; - } - break; - case 8: - return signed ? INT_8_DECL : UINT_8_DECL; - case 16: - if (!signed) { - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return UINT_16B_DECL; - } - return UINT_16L_DECL; - } - break; - case 27: - if (!signed) { - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return UINT_27B_DECL; - } - return UINT_27L_DECL; - } - break; - case 32: - if (signed) { - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return INT_32B_DECL; - } - return INT_32L_DECL; - } - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return UINT_32B_DECL; - } - return UINT_32L_DECL; - case 64: - if (signed) { - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return INT_64B_DECL; - } - return INT_64L_DECL; - } - if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) { - return UINT_64B_DECL; - } - return UINT_64L_DECL; - default: - } - } - return new IntegerDeclaration(len, signed, base, byteOrder, encoding, clock, alignment); - } - - /** - * Constructor - * - * @param len - * The length in bits - * @param signed - * Is the integer signed? false == unsigned - * @param base - * The base (10-16 are most common) - * @param byteOrder - * Big-endian little-endian or other - * @param encoding - * ascii, utf8 or none. - * @param clock - * The clock path, can be null - * @param alignment - * The minimum alignment. Should be ≥ 1 - */ - private IntegerDeclaration(int len, boolean signed, int base, - @Nullable ByteOrder byteOrder, Encoding encoding, String clock, long alignment) { - if (len <= 0 || len == 1 && signed) { - throw new IllegalArgumentException(); - } - - fLength = len; - fSigned = signed; - fBase = base; - - @SuppressWarnings("null") - @NonNull - ByteOrder actualByteOrder = (byteOrder == null ? ByteOrder.nativeOrder() : byteOrder); - fByteOrder = actualByteOrder; - - fEncoding = encoding; - fClock = clock; - fAlignment = Math.max(alignment, 1); - } - - private IntegerDeclaration(int len, boolean signed, @Nullable ByteOrder byteOrder) { - this(len, signed, 10, byteOrder, Encoding.NONE, "", 8); //$NON-NLS-1$ - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Is the integer signed? - * - * @return the is the integer signed - */ - public boolean isSigned() { - return fSigned; - } - - /** - * Get the integer base commonly decimal or hex - * - * @return the integer base - */ - public int getBase() { - return fBase; - } - - /** - * Get the byte order - * - * @return the byte order - */ - public ByteOrder getByteOrder() { - return fByteOrder; - } - - /** - * Get encoding, chars are 8 bit ints - * - * @return the encoding - */ - public Encoding getEncoding() { - return fEncoding; - } - - /** - * Is the integer a character (8 bits and encoded?) - * - * @return is the integer a char - */ - public boolean isCharacter() { - return (fLength == 8) && (fEncoding != Encoding.NONE); - } - - /** - * Is the integer an unsigned byte (8 bits and no sign)? - * - * @return is the integer an unsigned byte - * @since 3.1 - */ - public boolean isUnsignedByte() { - return (fLength == 8) && (!fSigned); - } - - /** - * Get the length in bits for this integer - * - * @return the length of the integer - */ - public int getLength() { - return fLength; - } - - @Override - public long getAlignment() { - return fAlignment; - } - - /** - * The integer's clock, since timestamps are stored in ints - * - * @return the integer's clock, can be null. (most often it is) - */ - public String getClock() { - return fClock; - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - return fLength; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public IntegerDefinition createDefinition(@Nullable IDefinitionScope definitionScope, - String fieldName, BitBuffer input) throws CTFReaderException { - ByteOrder byteOrder = input.getByteOrder(); - input.setByteOrder(fByteOrder); - long value = read(input); - input.setByteOrder(byteOrder); - return new IntegerDefinition(this, definitionScope, fieldName, value); - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] integer[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - - /** - * Get the maximum value for this integer declaration. - * - * @return The maximum value for this integer declaration - * @since 2.0 - */ - public BigInteger getMaxValue() { - /* - * Compute the number of bits able to represent an unsigned number, - * ignoring sign bit. - */ - int significantBits = fLength - (fSigned ? 1 : 0); - /* - * For a given N significant bits, compute the maximal value which is (1 - * << N) - 1. - */ - - @SuppressWarnings("null") - @NonNull - BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).subtract(BigInteger.ONE); - return ret; - } - - /** - * Get the minimum value for this integer declaration. - * - * @return The minimum value for this integer declaration - * @since 2.0 - */ - public BigInteger getMinValue() { - if (!fSigned) { - @SuppressWarnings("null") - @NonNull - BigInteger ret = BigInteger.ZERO; - return ret; - } - - /* - * Compute the number of bits able to represent an unsigned number, - * without the sign bit. - */ - int significantBits = fLength - 1; - /* - * For a given N significant bits, compute the minimal value which is - - * (1 << N). - */ - @SuppressWarnings("null") - @NonNull - BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).negate(); - return ret; - } - - private long read(BitBuffer input) throws CTFReaderException { - /* Offset the buffer position wrt the current alignment */ - alignRead(input); - - boolean signed = isSigned(); - int length = getLength(); - long bits = 0; - - /* - * Is the endianness of this field the same as the endianness of the - * input buffer? If not, then temporarily set the buffer's endianness to - * this field's just to read the data - */ - ByteOrder previousByteOrder = input.getByteOrder(); - if ((getByteOrder() != input.getByteOrder())) { - input.setByteOrder(getByteOrder()); - } - - if (length > 64) { - throw new CTFReaderException("Cannot read an integer with over 64 bits. Length given: " + length); //$NON-NLS-1$ - } - - bits = input.get(length, signed); - - /* - * Put the input buffer's endianness back to original if it was changed - */ - if (previousByteOrder != input.getByteOrder()) { - input.setByteOrder(previousByteOrder); - } - - return bits; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java deleted file mode 100644 index 15486c7c7e..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.math.BigInteger; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * A CTF integer definition. - * - * The definition of a integer basic data type. It will take the data from a - * trace and store it (and make it fit) as a long. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class IntegerDefinition extends SimpleDatatypeDefinition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final long fValue; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param value - * integer value - * @since 3.0 - */ - public IntegerDefinition(@NonNull IntegerDeclaration declaration, - IDefinitionScope definitionScope, @NonNull String fieldName, long value) { - super(declaration, definitionScope, fieldName); - fValue = value; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Gets the value of the integer - * - * @return the value of the integer (in long) - */ - public long getValue() { - return fValue; - } - - @Override - public IntegerDeclaration getDeclaration() { - return (IntegerDeclaration) super.getDeclaration(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public Long getIntegerValue() { - return getValue(); - } - - @Override - public String getStringValue() { - return this.toString(); - } - - @Override - public String toString() { - if (getDeclaration().isCharacter()) { - char c = (char) fValue; - return Character.toString(c); - } - return formatNumber(fValue, getDeclaration().getBase(), getDeclaration().isSigned()); - } - - /** - * Print a numeric value as a string in a given base - * - * @param value - * The value to print as string - * @param base - * The base for this value - * @param signed - * Is the value signed or not - * @return formatted number string - * @since 3.0 - */ - public static final String formatNumber(long value, int base, boolean signed) { - String s; - /* Format the number correctly according to the integer's base */ - switch (base) { - case 2: - s = "0b" + Long.toBinaryString(value); //$NON-NLS-1$ - break; - case 8: - s = "0" + Long.toOctalString(value); //$NON-NLS-1$ - break; - case 16: - s = "0x" + Long.toHexString(value); //$NON-NLS-1$ - break; - case 10: - default: - /* For non-standard base, we'll just print it as a decimal number */ - if (!signed && value < 0) { - /* - * Since there are no 'unsigned long', handle this case with - * BigInteger - */ - BigInteger bigInteger = BigInteger.valueOf(value); - /* - * we add 2^64 to the negative number to get the real unsigned - * value - */ - bigInteger = bigInteger.add(BigInteger.valueOf(1).shiftLeft(64)); - s = bigInteger.toString(); - } else { - s = Long.toString(value); - } - break; - } - return s; - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ScopedDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ScopedDefinition.java deleted file mode 100644 index 4519831463..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ScopedDefinition.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; - -/** - * Scoped defintion. a defintion where you can lookup various datatypes - * - * TODO: replace by default methods and an interface when java 8 is upon us - * - * @author Matthew Khouzam - * @since 3.1 - */ -@NonNullByDefault -public abstract class ScopedDefinition extends Definition implements IDefinitionScope { - - /** - * Constructor - * - * @param declaration - * the event declaration - * @param definitionScope - * the definition is in a scope, (normally a struct) what is it? - * @param fieldName - * the name of the definition. (it is a field in the parent - * scope) - */ - public ScopedDefinition(IDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName) { - super(declaration, definitionScope, fieldName); - } - - /** - * Constructor This one takes the scope and thus speeds up definition - * creation - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param scope - * the lexical scope - * @since 3.1 - */ - public ScopedDefinition(StructDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName, LexicalScope scope) { - super(declaration, definitionScope, fieldName, scope); - } - - /** - * Lookup an array in a struct. If the name returns a non-array (like an - * int) then the method returns null - * - * @param name - * the name of the array - * @return the array or null. - */ - public @Nullable AbstractArrayDefinition lookupArrayDefinition(String name) { - Definition def = lookupDefinition(name); - return (AbstractArrayDefinition) ((def instanceof AbstractArrayDefinition) ? def : null); - } - - /** - * Lookup an array in a struct. If the name returns a non-array (like an - * int) then the method returns null - * - * @param name - * the name of the array - * @return the array or null. - * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)} - */ - @Deprecated - @Nullable - public ArrayDefinition lookupArray(String name) { - Definition def = lookupDefinition(name); - return (ArrayDefinition) ((def instanceof ArrayDefinition) ? def : null); - } - - /** - * Lookup an enum in a struct. If the name returns a non-enum (like an int) - * then the method returns null - * - * @param name - * the name of the enum - * @return the enum or null if a definition is not found or it does not - * match the desired datatype. - */ - @Nullable - public EnumDefinition lookupEnum(String name) { - Definition def = lookupDefinition(name); - return (EnumDefinition) ((def instanceof EnumDefinition) ? def : null); - } - - /** - * Lookup an integer in a struct. If the name returns a non-integer (like an - * float) then the method returns null - * - * @param name - * the name of the integer - * @return the integer or null if a definition is not found or it does not - * match the desired datatype. - */ - @Nullable - public IntegerDefinition lookupInteger(String name) { - Definition def = lookupDefinition(name); - return (IntegerDefinition) ((def instanceof IntegerDefinition) ? def : null); - } - - /** - * Lookup a sequence in a struct. If the name returns a non-sequence (like - * an int) then the method returns null - * - * @param name - * the name of the sequence - * @return the sequence or null if a definition is not found or it does not - * match the desired datatype. - * @since 3.0 - * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)} - */ - @Deprecated - @Nullable - public SequenceDefinition lookupSequence(String name) { - Definition def = lookupDefinition(name); - return (SequenceDefinition) ((def instanceof SequenceDefinition) ? def : null); - } - - /** - * Lookup a string in a struct. If the name returns a non-string (like an - * int) then the method returns null - * - * @param name - * the name of the string - * @return the string or null if a definition is not found or it does not - * match the desired datatype. - */ - @Nullable - public StringDefinition lookupString(String name) { - Definition def = lookupDefinition(name); - return (StringDefinition) ((def instanceof StringDefinition) ? def : null); - } - - /** - * Lookup a struct in a struct. If the name returns a non-struct (like an - * int) then the method returns null - * - * @param name - * the name of the struct - * @return the struct or null if a definition is not found or it does not - * match the desired datatype. - */ - @Nullable - public StructDefinition lookupStruct(String name) { - Definition def = lookupDefinition(name); - return (StructDefinition) ((def instanceof StructDefinition) ? def : null); - } - - /** - * Lookup a variant in a struct. If the name returns a non-variant (like an - * int) then the method returns null - * - * @param name - * the name of the variant - * @return the variant or null if a definition is not found or it does not - * match the desired datatype. - */ - @Nullable - public VariantDefinition lookupVariant(String name) { - Definition def = lookupDefinition(name); - return (VariantDefinition) ((def instanceof VariantDefinition) ? def : null); - } -}
\ No newline at end of file diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java deleted file mode 100644 index 68e0ff7a6c..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.common.collect.Multimap; - -/** - * A CTF sequence declaration. - * - * An array where the size is fixed but declared in the trace, unlike array - * where it is declared with a literal - * @deprecated use {@link org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration} - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -@Deprecated -public class SequenceDeclaration extends CompoundDeclaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final IDeclaration fElemType; - private final String fLengthName; - private final Multimap<String, String> fPaths = ArrayListMultimap.<String, String>create(); - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param lengthName - * the name of the field describing the length - * @param elemType - * The element type - */ - public SequenceDeclaration(String lengthName, IDeclaration elemType) { - fElemType = elemType; - fLengthName = lengthName; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public IDeclaration getElementType() { - return fElemType; - } - - /** - * Gets the name of the length field - * - * @return the name of the length field - */ - public String getLengthName() { - return fLengthName; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @SuppressWarnings("null") // immutablelist - @Override - public SequenceDefinition createDefinition( - IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException { - IDefinition lenDef = null; - - if (definitionScope != null) { - lenDef = definitionScope.lookupDefinition(getLengthName()); - } - - if (lenDef == null) { - throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$ - } - - if (!(lenDef instanceof IntegerDefinition)) { - throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$ - } - - IntegerDefinition lengthDefinition = (IntegerDefinition) lenDef; - - if (lengthDefinition.getDeclaration().isSigned()) { - throw new CTFReaderException("Sequence length must not be signed"); //$NON-NLS-1$ - } - - long length = lengthDefinition.getValue(); - if ((length > Integer.MAX_VALUE) || (!input.canRead((int) length * fElemType.getMaximumSize()))) { - throw new CTFReaderException("Sequence length too long " + length); //$NON-NLS-1$ - } - - Collection<String> collection = fPaths.get(fieldName); - while (collection.size() < length) { - fPaths.put(fieldName, fieldName + '[' + collection.size() + ']'); - } - List<String> paths = (List<String>) fPaths.get(fieldName); - Builder<Definition> definitions = new ImmutableList.Builder<>(); - for (int i = 0; i < length; i++) { - definitions.add(fElemType.createDefinition(definitionScope, paths.get(i), input)); - } - return new SequenceDefinition(this, definitionScope, fieldName, definitions.build()); - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] sequence[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - return Integer.MAX_VALUE; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java deleted file mode 100644 index 3f0a290048..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.List; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; - -/** - * A CTF sequence definition (a fixed-size array). - * - * An array where the size is fixed but declared in the trace, unlike array - * where it is declared with a literal - * - * @deprecated use {@link AbstractArrayDefinition} - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -@Deprecated -public final class SequenceDefinition extends Definition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final ImmutableList<Definition> fDefinitions; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param definitions - * Definitions - * @since 3.0 - */ - public SequenceDefinition(@NonNull SequenceDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, List<Definition> definitions) { - super(declaration, definitionScope, fieldName); - fDefinitions = ImmutableList.copyOf(definitions); - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public SequenceDeclaration getDeclaration() { - return (SequenceDeclaration) super.getDeclaration(); - } - - /** - * The length of the sequence in number of elements so a sequence of 5 - * GIANT_rediculous_long_ints is the same as a sequence of 5 bits. (5) - * - * @return the length of the sequence - */ - public int getLength() { - return fDefinitions.size(); - } - - /** - * Get the element at i - * - * @param i - * the index (cannot be negative) - * @return The element at I, if I > length, null, if I < 0, the method - * throws an out of bounds exception - */ - public Definition getElem(int i) { - if (i > fDefinitions.size()) { - return null; - } - return fDefinitions.get(i); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public String toString() { - StringBuilder b = new StringBuilder(); - - if (getDeclaration().isString()) { - for (Definition def : fDefinitions) { - IntegerDefinition character = (IntegerDefinition) def; - - if (character.getValue() == 0) { - break; - } - - b.append(character.toString()); - } - } else { - b.append('['); - Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$ - b.append(joiner.join(fDefinitions)); - b.append(']'); - } - - return b.toString(); - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SimpleDatatypeDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SimpleDatatypeDefinition.java deleted file mode 100644 index 492d19f20c..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SimpleDatatypeDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * Simple Datatype definition is a datatype that allows the addition of - * getIntegerValue and getStringValue to a class. - * - * @author Matthew Khouzam - * @since 1.2 - */ -public abstract class SimpleDatatypeDefinition extends Definition { - - /** - * Create a new SimpleDatatypeDefinition - * - * @param declaration - * definition's declaration - * @param definitionScope - * The scope of this definition - * @param fieldName - * The name of the field matching this definition in the parent - * scope - * @since 3.0 - */ - public SimpleDatatypeDefinition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, - @NonNull String fieldName) { - super(declaration, definitionScope, fieldName); - } - - /** - * Gets the value in integer form - * - * @return the integer in a Long, can be null - */ - public Long getIntegerValue() { - return null; - } - - /** - * Gets the value in string form - * - * @return the integer in a String, can be null - */ - public String getStringValue() { - return null; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java deleted file mode 100644 index 710f75aa4e..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTF string declaration. - * - * Strings are an array of bytes of variable size and are terminated by a '\0' - * "NULL" character. Their encoding is described in the TSDL meta-data. In - * absence of encoding attribute information, the default encoding is UTF-8. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public class StringDeclaration extends Declaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final Encoding fEncoding; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Generate a UTF8 string declaration - */ - public StringDeclaration() { - fEncoding = Encoding.UTF8; - } - - /** - * Generate an encoded string declaration - * @param encoding the encoding, utf8 or ascii - */ - public StringDeclaration(Encoding encoding) { - fEncoding = encoding; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * - * @return the character encoding. - */ - public Encoding getEncoding() { - return fEncoding; - } - - @Override - public long getAlignment() { - // See ctf 4.2.5: Strings are always aligned on byte size. - return 8; - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - return Integer.MAX_VALUE; - } - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public StringDefinition createDefinition(IDefinitionScope definitionScope, - String fieldName, BitBuffer input) throws CTFReaderException { - String value = read(input); - return new StringDefinition(this, definitionScope, fieldName, value); - } - - private String read(BitBuffer input) throws CTFReaderException { - /* Offset the buffer position wrt the current alignment */ - alignRead(input); - - StringBuilder sb = new StringBuilder(); - char c = (char) input.get(8, false); - while (c != 0) { - sb.append(c); - c = (char) input.get(8, false); - } - return sb.toString(); - } - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] string[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java deleted file mode 100644 index 853605248c..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * A CTF string definition (similar to a C null-terminated byte array). - * - * Strings are an array of bytes of variable size and are terminated by a '\0' - * "NULL" character. Their encoding is described in the TSDL meta-data. In - * absence of encoding attribute information, the default encoding is UTF-8. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class StringDefinition extends Definition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final String fString; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param fieldName - * the field name - * @param value - * The String value - * @since 3.0 - */ - public StringDefinition(@NonNull StringDeclaration declaration, - IDefinitionScope definitionScope, @NonNull String fieldName, String value) { - super(declaration, definitionScope, fieldName); - fString = value; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public StringDeclaration getDeclaration() { - return (StringDeclaration) super.getDeclaration(); - } - - /** - * Gets the string (value) - * - * @return the string - */ - public String getValue() { - return fString; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public String toString() { - return '\"' + getValue() + '\"'; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java deleted file mode 100644 index a356e8650a..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTF structure declaration. - * - * A structure is similar to a C structure, it is a compound data type that - * contains other datatypes in fields. they are stored in an hashmap and indexed - * by names which are strings. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public class StructDeclaration extends Declaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** linked list of field names. So fieldName->fieldValue */ - private final @NonNull Map<String, IDeclaration> fFieldMap = new LinkedHashMap<>(); - - /** maximum bit alignment */ - private long fMaxAlign; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * The struct declaration, add fields later - * - * @param align - * the minimum alignment of the struct. (if a struct is 8bit - * aligned and has a 32 bit aligned field, the struct becomes 32 - * bit aligned. - */ - public StructDeclaration(long align) { - fMaxAlign = Math.max(align, 1); - } - - /** - * Struct declaration constructor - * - * @param names - * the names of all the fields - * @param declarations - * all the fields - * @since 3.0 - */ - public StructDeclaration(String[] names, Declaration[] declarations) { - fMaxAlign = 1; - - for (int i = 0; i < names.length; i++) { - addField(names[i], declarations[i]); - } - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Get current alignment - * - * @return the alignment of the struct and all its fields - */ - public long getMaxAlign() { - return fMaxAlign; - } - - /** - * Query if the struct has a given field - * - * @param name - * the name of the field, scopeless please - * @return does the field exist? - */ - public boolean hasField(String name) { - return fFieldMap.containsKey(name); - } - - /** - * Get the fields of the struct as a map. - * - * @return a Map of the fields (key is the name) - * @since 2.0 - */ - public Map<String, IDeclaration> getFields() { - return fFieldMap; - } - - /** - * Get the field declaration corresponding to a field name. - * - * @param fieldName - * The field name - * @return The declaration of the field, or null if there is no such field. - * @since 3.1 - */ - @Nullable - public IDeclaration getField(String fieldName) { - return fFieldMap.get(fieldName); - } - - /** - * Gets the field list. Very important since the map of fields does not - * retain the order of the fields. - * - * @return the field list. - * @since 3.0 - */ - public Iterable<String> getFieldsList() { - return fFieldMap.keySet(); - } - - @Override - public long getAlignment() { - return this.fMaxAlign; - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - int maxSize = 0; - for (IDeclaration field : fFieldMap.values()) { - maxSize += field.getMaximumSize(); - } - return Math.min(maxSize, Integer.MAX_VALUE); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public StructDefinition createDefinition(IDefinitionScope definitionScope, - String fieldName, BitBuffer input) throws CTFReaderException { - alignRead(input); - final Definition[] myFields = new Definition[fFieldMap.size()]; - StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldName, fFieldMap.keySet(), myFields); - fillStruct(input, myFields, structDefinition); - return structDefinition; - } - - /** - * Create a definition from this declaration. This is a faster constructor - * as it has a lexical scope and this does not need to look it up. - * - * @param definitionScope - * the definition scope, the parent where the definition will be - * placed - * @param fieldScope - * the scope of the definition - * @param input - * a bitbuffer to read from - * @return a reference to the definition - * @throws CTFReaderException - * error in reading - * @since 3.1 - */ - public StructDefinition createDefinition(IDefinitionScope definitionScope, - LexicalScope fieldScope, @NonNull BitBuffer input) throws CTFReaderException { - alignRead(input); - final Definition[] myFields = new Definition[fFieldMap.size()]; - /* - * Key set is NOT null - */ - @SuppressWarnings("null") - StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldScope, fieldScope.getName(), fFieldMap.keySet(), myFields); - fillStruct(input, myFields, structDefinition); - return structDefinition; - } - - /** - * Add a field to the struct - * - * @param name - * the name of the field, scopeless - * @param declaration - * the declaration of the field - */ - public void addField(String name, IDeclaration declaration) { - fFieldMap.put(name, declaration); - fMaxAlign = Math.max(fMaxAlign, declaration.getAlignment()); - } - - @SuppressWarnings("null") - private void fillStruct(@NonNull BitBuffer input, final Definition[] myFields, StructDefinition structDefinition) throws CTFReaderException { - Iterator<Map.Entry<String, IDeclaration>> iter = fFieldMap.entrySet().iterator(); - for (int i = 0; i < fFieldMap.size(); i++) { - Map.Entry<String, IDeclaration> entry = iter.next(); - myFields[i] = entry.getValue().createDefinition(structDefinition, entry.getKey(), input); - } - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] struct[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + fFieldMap.entrySet().hashCode(); - result = (prime * result) + (int) (fMaxAlign ^ (fMaxAlign >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof StructDeclaration)) { - return false; - } - StructDeclaration other = (StructDeclaration) obj; - if (!fFieldMap.entrySet().equals(other.fFieldMap.entrySet())) { - return false; - } - if (fMaxAlign != other.fMaxAlign) { - return false; - } - return true; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java deleted file mode 100644 index c3962e8bdf..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; - -/** - * A CTF structure definition (similar to a C structure). - * - * A structure is similar to a C structure, it is a compound data type that - * contains other datatypes in fields. they are stored in an hashmap and indexed - * by names which are strings. - * - * TODO: move me to internal - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class StructDefinition extends ScopedDefinition implements ICompositeDefinition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final ImmutableList<String> fFieldNames; - private final Definition[] fDefinitions; - private Map<String, Definition> fDefinitionsMap = null; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * *DEPRECATED* TODO: To remove once we break the API... - * - * Not marked with the annotation to not annoy callers using a List, which - * is still as valid with the new constructor. But the compiler gives an - * error even though a Iterable is a List too... - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param structFieldName - * the field name - * @param fieldNames - * the list of fields - * @param definitions - * the definitions - * @since 3.1 - */ - public StructDefinition(@NonNull StructDeclaration declaration, - IDefinitionScope definitionScope, - @NonNull String structFieldName, - List<String> fieldNames, - Definition[] definitions) { - this(declaration, definitionScope, structFieldName, (Iterable<String>) fieldNames, definitions); - } - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param structFieldName - * the field name - * @param fieldNames - * the list of fields - * @param definitions - * the definitions - * @since 3.1 - */ - public StructDefinition(@NonNull StructDeclaration declaration, - IDefinitionScope definitionScope, - @NonNull String structFieldName, - Iterable<String> fieldNames, - Definition[] definitions) { - super(declaration, definitionScope, structFieldName); - fFieldNames = ImmutableList.copyOf(fieldNames); - fDefinitions = definitions; - if (fFieldNames.isEmpty()) { - fDefinitionsMap = Collections.EMPTY_MAP; - } - } - - /** - * Constructor This one takes the scope and thus speeds up definition - * creation - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param scope - * the scope of this variable - * @param structFieldName - * the field name - * @param fieldNames - * the list of fields - * @param definitions - * the definitions - * @since 3.1 - */ - public StructDefinition(@NonNull StructDeclaration declaration, - IDefinitionScope definitionScope, @NonNull LexicalScope scope, - @NonNull String structFieldName, @NonNull Iterable<String> fieldNames, Definition[] definitions) { - super(declaration, definitionScope, structFieldName, scope); - fFieldNames = ImmutableList.copyOf(fieldNames); - fDefinitions = definitions; - if (fFieldNames.isEmpty()) { - fDefinitionsMap = Collections.EMPTY_MAP; - } - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public Definition getDefinition(String fieldName) { - if (fDefinitionsMap == null) { - /* Build the definitions map */ - Builder<String, Definition> mapBuilder = new ImmutableMap.Builder<>(); - for (int i = 0; i < fFieldNames.size(); i++) { - if (fDefinitions[i] != null) { - mapBuilder.put(fFieldNames.get(i), fDefinitions[i]); - } - } - fDefinitionsMap = mapBuilder.build(); - } - return fDefinitionsMap.get(fieldName); - } - - @Override - public List<String> getFieldNames() { - return fFieldNames; - } - - @Override - public StructDeclaration getDeclaration() { - return (StructDeclaration) super.getDeclaration(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public Definition lookupDefinition(String lookupPath) { - /* - * The fields are created in order of appearance, so if a variant or - * sequence refers to a field that is after it, the field's definition - * will not be there yet in the hashmap. - */ - int val = fFieldNames.indexOf(lookupPath); - if (val != -1) { - return fDefinitions[val]; - } - String lookupUnderscored = "_" + lookupPath; //$NON-NLS-1$ - val = fFieldNames.indexOf(lookupUnderscored); - if (val != -1) { - return fDefinitions[val]; - } - return null; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - - builder.append("{ "); //$NON-NLS-1$ - - if (fFieldNames != null) { - List<String> fields = new LinkedList<>(); - for (String field : fFieldNames) { - String appendee = field + " = " + lookupDefinition(field).toString(); //$NON-NLS-1$ - fields.add(appendee); - } - Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$ - builder.append(joiner.join(fields)); - } - - builder.append(" }"); //$NON-NLS-1$ - - return builder.toString(); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java deleted file mode 100644 index b32572ca92..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; - -/** - * A CTFC variant declaration. - * - * A variant is similar to a C union, only taking the minimum size of the types, - * it is a compound data type that contains other datatypes in fields. they are - * stored in an hashmap and indexed by names which are strings. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public class VariantDeclaration extends Declaration { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private String fTag = null; - private static final long ALIGNMENT = 1; - private final Map<String, IDeclaration> fFields = Collections.synchronizedMap(new HashMap<String, IDeclaration>()); - private EnumDefinition fTagDef; - private IDeclaration fDeclarationToPopulate; - private IDefinitionScope fPrevDefinitionScope; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - */ - public VariantDeclaration() { - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * @return Does the variant have a tag - */ - public boolean isTagged() { - return fTag != null; - } - - /** - * Lookup if a field exists in the variant - * - * @param fieldTag - * the field tag name - * @return true = field tag exists - */ - public boolean hasField(String fieldTag) { - return fFields.containsKey(fieldTag); - } - - /** - * Sets the tag in a variant - * - * @param tag - * the tag - */ - public void setTag(String tag) { - fTag = tag; - fTagDef = null; - } - - /** - * Gets current variant tag - * - * @return the variant tag. - */ - public String getTag() { - return fTag; - } - - /** - * Gets the fields of the variant - * - * @return the fields of the variant - * @since 2.0 - */ - public Map<String, IDeclaration> getFields() { - return this.fFields; - } - - @Override - public long getAlignment() { - return ALIGNMENT; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public VariantDefinition createDefinition(IDefinitionScope definitionScope, - String fieldName, BitBuffer input) throws CTFReaderException { - alignRead(input); - if (fPrevDefinitionScope != definitionScope) { - fTagDef = null; - fPrevDefinitionScope = definitionScope; - } - EnumDefinition tagDef = fTagDef; - if (tagDef == null) { - Definition def = definitionScope.lookupDefinition(fTag); - tagDef = (EnumDefinition) ((def instanceof EnumDefinition) ? def : null); - } - if (tagDef == null) { - throw new CTFReaderException("Tag is not defined " + fTag); //$NON-NLS-1$ - } - String varFieldName = tagDef.getStringValue(); - fDeclarationToPopulate = fFields.get(varFieldName); - if (fDeclarationToPopulate == null) { - throw new CTFReaderException("Unknown enum selector for variant " + //$NON-NLS-1$ - definitionScope.getScopePath().toString()); - } - Definition fieldValue = fDeclarationToPopulate.createDefinition(definitionScope, fieldName, input); - return new VariantDefinition(this, definitionScope, varFieldName, fieldName, fieldValue); - } - - /** - * Add a field to this CTF Variant - * - * @param fieldTag - * The tag of the new field - * @param declaration - * The Declaration of this new field - */ - public void addField(String fieldTag, IDeclaration declaration) { - fFields.put(fieldTag, declaration); - } - - /** - * gets the tag definition - * - * @return the fTagDef - * @since 3.0 - */ - public EnumDefinition getTagDef() { - return fTagDef; - } - - /** - * @since 3.0 - */ - @Override - public int getMaximumSize() { - Collection<IDeclaration> values = fFields.values(); - int maxSize = 0; - for (IDeclaration field : values) { - maxSize = Math.max(maxSize, field.getMaximumSize()); - } - return maxSize; - } - - @Override - public String toString() { - /* Only used for debugging */ - return "[declaration] variant[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java deleted file mode 100644 index 6302f863f6..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.event.types; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; - -/** - * A CTF variant definition (similar to a C union). - * - * A variant is similar to a C union, only taking the minimum size of the types, - * it is a compound data type that contains other datatypes in fields. they are - * stored in an hashmap and indexed by names which are strings. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class VariantDefinition extends ScopedDefinition { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private final Definition fDefinition; - private final String fCurrentField; - private final String fFieldName; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param declaration - * the parent declaration - * @param definitionScope - * the parent scope - * @param selectedField - * the selected field - * @param fieldName - * the field name - * @param fieldValue - * the field value - * @since 3.0 - */ - public VariantDefinition(@NonNull VariantDeclaration declaration, - IDefinitionScope definitionScope, String selectedField, @NonNull String fieldName, Definition fieldValue) { - super(declaration, definitionScope, fieldName); - - fFieldName = fieldName; - fCurrentField = selectedField; - fDefinition = fieldValue; - - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - @Override - public VariantDeclaration getDeclaration() { - return (VariantDeclaration) super.getDeclaration(); - } - - /** - * Get the current field name - * - * @return the current field name - */ - public String getCurrentFieldName() { - return fCurrentField; - } - - /** - * Get the current field - * - * @return the current field - */ - public Definition getCurrentField() { - return fDefinition; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public Definition lookupDefinition(String lookupPath) { - if (lookupPath == null) { - return null; - } - if (lookupPath.equals(fFieldName)) { - return fDefinition; - } - return getDefinitionScope().lookupDefinition(lookupPath); - } - - @Override - public String toString() { - return "{ " + getCurrentFieldName() + //$NON-NLS-1$ - " = " + getCurrentField() + //$NON-NLS-1$ - " }"; //$NON-NLS-1$ - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java deleted file mode 100644 index c124a870de..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFReaderException.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexandre Montplaisir - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -/** - * General exception that is thrown when there is a problem somewhere with the - * CTF trace reader. - * - * @version 1.0 - * @author Alexandre Montplaisir - */ -public class CTFReaderException extends Exception { - - private static final long serialVersionUID = 2065258365219777672L; - - /** - * Default constructor with no message. - */ - public CTFReaderException() { - super(); - } - - /** - * Constructor with an attached message. - * - * @param message - * The message attached to this exception - */ - public CTFReaderException(String message) { - super(message); - } - - /** - * Re-throw an exception into this type. - * - * @param e - * The previous Exception we caught - */ - public CTFReaderException(Exception e) { - super(e); - } - - /** - * Constructor with an attached message and re-throw an exception into this type. - * - * @param message - * The message attached to this exception - * @param exception - * The previous Exception caught - * @since 2.0 - */ - public CTFReaderException(String message, Throwable exception) { - super(message, exception); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFResponse.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFResponse.java deleted file mode 100644 index 262ff3cd10..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; - -/** - * A response to a request - * - * @author Matthew Khouzam - * @since 3.0 - * - */ -public enum CTFResponse { - /** - * The operation was successful - */ - OK, - /** - * The operation cannot be yet completed - */ - WAIT, - /** - * The operation was finished - */ - FINISH, - /** - * The operation failed - */ - ERROR -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStream.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStream.java deleted file mode 100644 index 8b94e3a69a..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStream.java +++ /dev/null @@ -1,384 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IEventHeaderDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration; -import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; - -/** - * <b><u>Stream</u></b> - * <p> - * Represents a stream in a trace. - * - * @since 3.0 - */ -public class CTFStream { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * The numerical ID of the stream - */ - private Long fId = null; - - /** - * Declarations of the stream-specific structures - */ - private StructDeclaration fPacketContextDecl = null; - private IDeclaration fEventHeaderDecl = null; - private StructDeclaration fEventContextDecl = null; - - /** - * The trace to which the stream belongs - */ - private CTFTrace fTrace = null; - - /** - * Maps event ids to events - */ - private final ArrayList<IEventDeclaration> fEvents = new ArrayList<>(); - - private boolean fEventUnsetId = false; - - /** - * The inputs associated to this stream - */ - private final Set<CTFStreamInput> fInputs = new HashSet<>(); - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs a Stream that belongs to a Trace - * - * @param trace - * The trace to which belongs this stream. - */ - public CTFStream(CTFTrace trace) { - fTrace = trace; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Sets the id of a stream - * - * @param id - * the id of a stream - */ - public void setId(long id) { - fId = id; - } - - /** - * Gets the id of a stream - * - * @return id the id of a stream - */ - public Long getId() { - return fId; - } - - /** - * Is the id of a stream set - * - * @return If the ID is set or not - */ - public boolean isIdSet() { - return fId != null; - } - - /** - * - * @return is the event header set (timestamp and stuff) (see Ctf Spec) - */ - public boolean isEventHeaderSet() { - return fEventHeaderDecl != null; - } - - /** - * - * @return is the event context set (pid and stuff) (see Ctf Spec) - */ - public boolean isEventContextSet() { - return fEventContextDecl != null; - } - - /** - * - * @return Is the packet context set (see Ctf Spec) - */ - public boolean isPacketContextSet() { - return fPacketContextDecl != null; - } - - /** - * Sets the event header - * - * @param eventHeader - * the current event header for all events in this stream - */ - public void setEventHeader(StructDeclaration eventHeader) { - fEventHeaderDecl = eventHeader; - } - - /** - * Sets the event header, this typically has the id and the timestamp - * - * @param eventHeader - * the current event header for all events in this stream - * @since 3.1 - */ - public void setEventHeader(IEventHeaderDeclaration eventHeader) { - fEventHeaderDecl = eventHeader; - } - - /** - * - * @param eventContext - * the context for all events in this stream - */ - public void setEventContext(StructDeclaration eventContext) { - fEventContextDecl = eventContext; - } - - /** - * - * @param packetContext - * the packet context for all packets in this stream - */ - public void setPacketContext(StructDeclaration packetContext) { - fPacketContextDecl = packetContext; - } - - /** - * - * @return the event header declaration in structdeclaration form - * @deprecated use {@link CTFStream#getEventHeaderDeclaration()} - */ - @Deprecated - public StructDeclaration getEventHeaderDecl() { - return (StructDeclaration) ((fEventHeaderDecl instanceof StructDeclaration) ? fEventHeaderDecl : null); - } - - /** - * Gets the event header declaration - * - * @return the event header declaration in declaration form - * @since 3.1 - */ - public IDeclaration getEventHeaderDeclaration() { - return fEventHeaderDecl; - } - - /** - * - * @return the event context declaration in structdeclaration form - */ - public StructDeclaration getEventContextDecl() { - return fEventContextDecl; - } - - /** - * - * @return the packet context declaration in structdeclaration form - */ - public StructDeclaration getPacketContextDecl() { - return fPacketContextDecl; - } - - /** - * - * @return the set of all stream inputs for this stream - */ - public Set<CTFStreamInput> getStreamInputs() { - return fInputs; - } - - /** - * - * @return the parent trace - */ - public CTFTrace getTrace() { - return fTrace; - } - - /** - * - * @return all the event declarations for this stream, using the id as a key - * for the hashmap. - * @deprecated use {@link CTFStream#getEventDeclarations()} - */ - @Deprecated - public Map<Long, IEventDeclaration> getEvents() { - throw new UnsupportedOperationException(); - } - - /** - * Get all the event declarations in this stream. - * - * @return The event declarations for this stream - * @since 3.2 - */ - public @NonNull Collection<IEventDeclaration> getEventDeclarations() { - List<IEventDeclaration> retVal = new ArrayList<>(fEvents); - retVal.removeAll(Collections.<IEventDeclaration> singletonList(null)); - return retVal; - } - - /** - * Get the event declaration for a given ID. - * - * @param eventId - * The ID, can be {@link EventDeclaration#UNSET_EVENT_ID}, or any - * positive value - * @return The event declaration with the given ID for this stream, or - * 'null' if there are no declaration with this ID - * @throws IllegalArgumentException - * If the passed ID is invalid - * @since 3.2 - */ - public @Nullable IEventDeclaration getEventDeclaration(int eventId) { - int eventIndex = (eventId == EventDeclaration.UNSET_EVENT_ID) ? 0 : eventId; - if (eventIndex < 0) { - /* Any negative value other than UNSET_EVENT_ID is invalid */ - throw new IllegalArgumentException("Event ID cannot be negative."); //$NON-NLS-1$ - } - if (eventIndex >= fEvents.size()) { - /* This ID could be valid, but there are no declarations with it */ - return null; - } - return fEvents.get(eventIndex); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * Adds an event to the event list. - * - * An event in a stream can omit its id if it is the only event in this - * stream. An event for which no id has been specified has a null id. It is - * thus not possible to add an event with the null key if the map is not - * empty. It is also not possible to add an event to the map if the null key - * is present in the map. - * - * @param event - * The event to add - * @throws ParseException - * If there was a problem reading the event or adding it to the - * stream - */ - public void addEvent(IEventDeclaration event) throws ParseException { - if (fEventUnsetId) { - throw new ParseException("Event without id with multiple events in a stream"); //$NON-NLS-1$ - } - int id = ((EventDeclaration) event).id(); - - /* - * If there is an event without id (the null key), it must be the only - * one - */ - if (id == EventDeclaration.UNSET_EVENT_ID) { - if (!fEvents.isEmpty()) { - throw new ParseException("Event without id with multiple events in a stream"); //$NON-NLS-1$ - } - fEventUnsetId = true; - fEvents.add(event); - } else { - /* Check if an event with the same ID already exists */ - if (fEvents.size() > id && fEvents.get(id) != null) { - throw new ParseException("Event id already exists"); //$NON-NLS-1$ - } - ensureSize(fEvents, id); - /* Put the event in the list */ - fEvents.set(id, event); - } - } - - /** - * Add a list of event declarations to this stream. There must be no overlap - * between the two lists of event declarations. This will merge the two - * lists and preserve the indexes of both lists. - * - * @param events - * list of the events to add - * @throws CTFReaderException - * if the list already contains data - * @since 3.2 - */ - public void addEvents(Collection<IEventDeclaration> events) throws CTFReaderException { - if (fEventUnsetId) { - throw new CTFReaderException("Cannot add to a stream with an unidentified event"); //$NON-NLS-1$ - } - if (fEvents.isEmpty()) { - fEvents.addAll(events); - return; - } - for (IEventDeclaration event : events) { - if (event != null) { - int index = event.getId().intValue(); - ensureSize(fEvents, index); - if (fEvents.get(index) != null) { - throw new CTFReaderException("Both lists have an event defined at position " + index); //$NON-NLS-1$ - } - fEvents.set(index, event); - } - } - } - - private static void ensureSize(ArrayList<? extends Object> list, int index) { - list.ensureCapacity(index); - while (list.size() <= index) { - list.add(null); - } - } - - /** - * Add an input to this Stream - * - * @param input - * The StreamInput to add. - */ - public void addInput(CTFStreamInput input) { - fInputs.add(input); - } - - @Override - public String toString() { - return "Stream [id=" + fId + ", packetContextDecl=" + fPacketContextDecl //$NON-NLS-1$ //$NON-NLS-2$ - + ", eventHeaderDecl=" + fEventHeaderDecl //$NON-NLS-1$ - + ", eventContextDecl=" + fEventContextDecl + ", trace=" + fTrace //$NON-NLS-1$ //$NON-NLS-2$ - + ", events=" + fEvents + ", inputs=" + fInputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java deleted file mode 100644 index db8c6371c6..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java +++ /dev/null @@ -1,494 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileChannel.MapMode; -import java.nio.file.StandardOpenOption; -import java.util.UUID; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.event.types.Definition; -import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.IDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.internal.ctf.core.SafeMappedByteBuffer; -import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; - -/** - * <b><u>StreamInput</u></b> - * <p> - * Represents a trace file that belongs to a certain stream. - * - * @since 3.0 - */ -// TODO: remove AutoCloseable -public class CTFStreamInput implements IDefinitionScope, AutoCloseable { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * The associated Stream - */ - private final CTFStream fStream; - - /** - * Information on the file (used for debugging) - */ - @NonNull - private final File fFile; - - /** - * The packet index of this input - */ - private final StreamInputPacketIndex fIndex; - - private long fTimestampEnd; - - /** - * Definition of trace packet header - */ - private StructDeclaration fTracePacketHeaderDecl = null; - - /** - * Definition of trace stream packet context - */ - private StructDeclaration fStreamPacketContextDecl = null; - - /** - * Total number of lost events in this stream - */ - private long fLostSoFar = 0; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs a StreamInput. - * - * @param stream - * The stream to which this StreamInput belongs to. - * @param file - * Information about the trace file (for debugging purposes). - */ - public CTFStreamInput(CTFStream stream, @NonNull File file) { - fStream = stream; - fFile = file; - fIndex = new StreamInputPacketIndex(); - } - - @Override - public void close() throws IOException { - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Gets the stream the streamInput wrapper is wrapping - * - * @return the stream the streamInput wrapper is wrapping - */ - public CTFStream getStream() { - return fStream; - } - - /** - * The common streamInput Index - * - * @return the stream input Index - */ - StreamInputPacketIndex getIndex() { - return fIndex; - } - - /** - * Gets the filename of the streamInput file. - * - * @return the filename of the streaminput file. - */ - public String getFilename() { - return fFile.getName(); - } - - /** - * Gets the last read timestamp of a stream. (this is not necessarily the - * last time in the stream.) - * - * @return the last read timestamp - */ - public long getTimestampEnd() { - return fTimestampEnd; - } - - /** - * Sets the last read timestamp of a stream. (this is not necessarily the - * last time in the stream.) - * - * @param timestampEnd - * the last read timestamp - */ - public void setTimestampEnd(long timestampEnd) { - fTimestampEnd = timestampEnd; - } - - /** - * Useless for streaminputs - */ - @Override - public LexicalScope getScopePath() { - return LexicalScope.STREAM; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @Override - public Definition lookupDefinition(String lookupPath) { - /* TODO: lookup in different dynamic scopes is not supported yet. */ - return null; - } - - /** - * Create the index for this trace file. - */ - public void setupIndex() { - - /* - * The BitBuffer to extract data from the StreamInput - */ - BitBuffer bitBuffer = new BitBuffer(); - bitBuffer.setByteOrder(getStream().getTrace().getByteOrder()); - - /* - * Create the definitions we need to read the packet headers + contexts - */ - if (getStream().getTrace().getPacketHeader() != null) { - fTracePacketHeaderDecl = getStream().getTrace().getPacketHeader(); - } - - if (getStream().getPacketContextDecl() != null) { - fStreamPacketContextDecl = getStream().getPacketContextDecl(); - } - - } - - /** - * Adds the next packet header index entry to the index of a stream input. - * - * <strong>This method is slow and can corrupt data if not used - * properly</strong> - * - * @return true if there are more packets to add - * @throws CTFReaderException - * If there was a problem reading the packed header - */ - public boolean addPacketHeaderIndex() throws CTFReaderException { - long currentPos = 0L; - if (!fIndex.getEntries().isEmpty()) { - StreamInputPacketIndexEntry pos = fIndex.getEntries().lastElement(); - currentPos = computeNextOffset(pos); - } - long fileSize = getStreamSize(); - if (currentPos < fileSize) { - - StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry( - currentPos); - createPacketIndexEntry(fileSize, currentPos, packetIndex); - fIndex.addEntry(packetIndex); - return true; - } - return false; - } - - private long getStreamSize() { - return fFile.length(); - } - - private long createPacketIndexEntry(long fileSizeBytes, long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex) - throws CTFReaderException { - - long pos = readPacketHeader(fileSizeBytes, packetOffsetBytes, packetIndex); - - /* Basic validation */ - if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) { - throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$ - } - - if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex - .getOffsetBytes()) * 8)) { - throw new CTFReaderException("Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$ - } - - /* - * Offset in the file, in bits - */ - packetIndex.setDataOffsetBits(pos); - - /* - * Update the counting packet offset - */ - return computeNextOffset(packetIndex); - } - - /** - * @param packetIndex - * @return - */ - private static long computeNextOffset( - StreamInputPacketIndexEntry packetIndex) { - return packetIndex.getOffsetBytes() - + ((packetIndex.getPacketSizeBits() + 7) / 8); - } - - private long readPacketHeader(long fileSizeBytes, - long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex) throws CTFReaderException { - long position = -1; - /* - * Initial size, it should map at least the packet header + context - * size. - * - * TODO: use a less arbitrary size. - */ - long mapSize = 4096; - /* - * If there is less data remaining than what we want to map, reduce the - * map size. - */ - if ((fileSizeBytes - packetIndex.getOffsetBytes()) < mapSize) { - mapSize = fileSizeBytes - packetIndex.getOffsetBytes(); - } - - /* - * Map the packet. - */ - try (FileChannel fc = FileChannel.open(fFile.toPath(), StandardOpenOption.READ)) { - ByteBuffer map = SafeMappedByteBuffer.map(fc, MapMode.READ_ONLY, packetOffsetBytes, mapSize); - if (map == null) { - throw new CTFReaderException("Failed to allocate mapped byte buffer"); //$NON-NLS-1$ - } - /* - * create a packet bit buffer to read the packet header - */ - BitBuffer bitBuffer = new BitBuffer(map); - bitBuffer.setByteOrder(getStream().getTrace().getByteOrder()); - /* - * Read the trace packet header if it exists. - */ - if (fTracePacketHeaderDecl != null) { - parseTracePacketHeader(fTracePacketHeaderDecl, bitBuffer); - } - - /* - * Read the stream packet context if it exists. - */ - if (fStreamPacketContextDecl != null) { - parsePacketContext(fileSizeBytes, fStreamPacketContextDecl, - bitBuffer, packetIndex); - } else { - setPacketContextNull(fileSizeBytes, packetIndex); - } - - position = bitBuffer.position(); - } catch (IOException e) { - throw new CTFReaderException(e); - } - return position; - } - - private void parseTracePacketHeader(StructDeclaration tracePacketHeaderDecl, - @NonNull BitBuffer bitBuffer) throws CTFReaderException { - StructDefinition tracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(fStream.getTrace(), LexicalScope.TRACE_PACKET_HEADER, bitBuffer); - - /* - * Check the CTF magic number - */ - IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef - .lookupDefinition("magic"); //$NON-NLS-1$ - if (magicDef != null) { - int magic = (int) magicDef.getValue(); - if (magic != Utils.CTF_MAGIC) { - throw new CTFReaderException( - "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$ - } - } - - /* - * Check the trace UUID - */ - ArrayDefinition uuidDef = - (ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$ - if (uuidDef != null) { - UUID uuid = Utils.getUUIDfromDefinition(uuidDef); - - if (!getStream().getTrace().getUUID().equals(uuid)) { - throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ - } - } - - /* - * Check that the stream id did not change - */ - IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef - .lookupDefinition("stream_id"); //$NON-NLS-1$ - if (streamIDDef != null) { - long streamID = streamIDDef.getValue(); - - if (streamID != getStream().getId()) { - throw new CTFReaderException("Stream ID changing within a StreamInput"); //$NON-NLS-1$ - } - } - } - - /** - * Gets the wrapped file - * - * @return the file - */ - @NonNull - File getFile() { - return fFile; - } - - private static void setPacketContextNull(long fileSizeBytes, - StreamInputPacketIndexEntry packetIndex) { - /* - * If there is no packet context, infer the content and packet size from - * the file size (assume that there is only one packet and no padding) - */ - packetIndex.setContentSizeBits(fileSizeBytes * 8); - packetIndex.setPacketSizeBits(fileSizeBytes * 8); - } - - private void parsePacketContext(long fileSizeBytes, - StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer, - StreamInputPacketIndexEntry packetIndex) throws CTFReaderException { - StructDefinition streamPacketContextDef = streamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT, bitBuffer); - - for (String field : streamPacketContextDef.getDeclaration() - .getFieldsList()) { - IDefinition id = streamPacketContextDef.lookupDefinition(field); - if (id instanceof IntegerDefinition) { - packetIndex.addAttribute(field, - ((IntegerDefinition) id).getValue()); - } else if (id instanceof FloatDefinition) { - packetIndex.addAttribute(field, - ((FloatDefinition) id).getValue()); - } else if (id instanceof EnumDefinition) { - packetIndex.addAttribute(field, - ((EnumDefinition) id).getValue()); - } else if (id instanceof StringDefinition) { - packetIndex.addAttribute(field, - ((StringDefinition) id).getValue()); - } - } - - Long contentSize = (Long) packetIndex.lookupAttribute("content_size"); //$NON-NLS-1$ - Long packetSize = (Long) packetIndex.lookupAttribute("packet_size"); //$NON-NLS-1$ - Long tsBegin = (Long) packetIndex.lookupAttribute("timestamp_begin"); //$NON-NLS-1$ - Long tsEnd = (Long) packetIndex.lookupAttribute("timestamp_end"); //$NON-NLS-1$ - String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$ - // LTTng Specific - Long cpuId = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$ - Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$ - - /* Read the content size in bits */ - if (contentSize != null) { - packetIndex.setContentSizeBits(contentSize.intValue()); - } else if (packetSize != null) { - packetIndex.setContentSizeBits(packetSize.longValue()); - } else { - packetIndex.setContentSizeBits((int) (fileSizeBytes * 8)); - } - - /* Read the packet size in bits */ - if (packetSize != null) { - packetIndex.setPacketSizeBits(packetSize.intValue()); - } else if (packetIndex.getContentSizeBits() != 0) { - packetIndex.setPacketSizeBits(packetIndex.getContentSizeBits()); - } else { - packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8)); - } - - /* Read the begin timestamp */ - if (tsBegin != null) { - packetIndex.setTimestampBegin(tsBegin.longValue()); - } - - /* Read the end timestamp */ - if (tsEnd != null) { - if (tsEnd == -1) { - tsEnd = Long.MAX_VALUE; - } - packetIndex.setTimestampEnd(tsEnd.longValue()); - setTimestampEnd(packetIndex.getTimestampEnd()); - } - - if (device != null) { - packetIndex.setTarget(device); - } - - if (cpuId != null) { - packetIndex.setTarget("CPU" + cpuId.toString()); //$NON-NLS-1$ - } - - if (lostEvents != null) { - packetIndex.setLostEvents(lostEvents - fLostSoFar); - fLostSoFar = lostEvents; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + fFile.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof CTFStreamInput)) { - return false; - } - CTFStreamInput other = (CTFStreamInput) obj; - if (!fFile.equals(other.fFile)) { - return false; - } - return true; - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java deleted file mode 100644 index 29ef23f9ff..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java +++ /dev/null @@ -1,542 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ -package org.eclipse.linuxtools.ctf.core.trace; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel.MapMode; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.linuxtools.ctf.core.CTFStrings; -import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.event.types.Definition; -import org.eclipse.linuxtools.ctf.core.event.types.ICompositeDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.IEventHeaderDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.SimpleDatatypeDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; -import org.eclipse.linuxtools.internal.ctf.core.SafeMappedByteBuffer; -import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration; -import org.eclipse.linuxtools.internal.ctf.core.event.types.composite.EventHeaderDefinition; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; - -import com.google.common.collect.ImmutableList; - -/** - * CTF trace packet reader. Reads the events of a packet of a trace file. - * - * @author Matthew Khouzam - * @author Simon Marchi - * @since 3.0 - */ -public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseable { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** BitBuffer used to read the trace file. */ - @Nullable - private BitBuffer fBitBuffer; - - /** StreamInputReader that uses this StreamInputPacketReader. */ - private final CTFStreamInputReader fStreamInputReader; - - /** Trace packet header. */ - private final StructDeclaration fTracePacketHeaderDecl; - - /** Stream packet context definition. */ - private final StructDeclaration fStreamPacketContextDecl; - - /** Stream event header definition. */ - private final IDeclaration fStreamEventHeaderDecl; - - /** Stream event context definition. */ - private final StructDeclaration fStreamEventContextDecl; - - private ICompositeDefinition fCurrentTracePacketHeaderDef; - private ICompositeDefinition fCurrentStreamEventHeaderDef; - private ICompositeDefinition fCurrentStreamPacketContextDef; - /** Reference to the index entry of the current packet. */ - private StreamInputPacketIndexEntry fCurrentPacket = null; - - /** - * Last timestamp recorded. - * - * Needed to calculate the complete timestamp values for the events with - * compact headers. - */ - private long fLastTimestamp = 0; - - /** CPU id of current packet. */ - private int fCurrentCpu = 0; - - private int fLostEventsInThisPacket; - - private long fLostEventsDuration; - - private boolean fHasLost = false; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs a StreamInputPacketReader. - * - * @param streamInputReader - * The StreamInputReader to which this packet reader belongs to. - */ - public CTFStreamInputPacketReader(CTFStreamInputReader streamInputReader) { - fStreamInputReader = streamInputReader; - - /* Set the BitBuffer's byte order. */ - ByteBuffer allocateDirect = ByteBuffer.allocateDirect(0); - if (allocateDirect == null) { - throw new IllegalStateException("Unable to allocate 0 bytes!"); //$NON-NLS-1$ - } - fBitBuffer = new BitBuffer(allocateDirect); - - final CTFStream currentStream = streamInputReader.getStreamInput().getStream(); - fTracePacketHeaderDecl = currentStream.getTrace().getPacketHeader(); - fStreamPacketContextDecl = currentStream.getPacketContextDecl(); - fStreamEventHeaderDecl = currentStream.getEventHeaderDeclaration(); - fStreamEventContextDecl = currentStream.getEventContextDecl(); - } - - /** - * Get the event context defintiion - * - * @param input - * the bitbuffer to read from - * @return an context definition, can be null - * @throws CTFReaderException - * out of bounds exception or such - */ - public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFReaderException { - return fStreamEventContextDecl.createDefinition(fStreamInputReader.getStreamInput(), LexicalScope.STREAM_EVENT_CONTEXT, input); - } - - /** - * Get the stream context defintiion - * - * @param input - * the bitbuffer to read from - * @return an context definition, can be null - * @throws CTFReaderException - * out of bounds exception or such - * @deprecated it was not used - */ - @Deprecated - public StructDefinition getStreamEventHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException { - if (!(fStreamEventHeaderDecl instanceof StructDeclaration)) { - throw new IllegalStateException("Definition is not a struct definition, this is a deprecated method that doesn't work so well, stop using it."); //$NON-NLS-1$ - } - return ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(this, LexicalScope.STREAM_EVENT_HEADER, input); - } - - /** - * Get the packet context defintiion - * - * @param input - * the bitbuffer to read from - * @return an context definition, can be null - * @throws CTFReaderException - * out of bounds exception or such - */ - public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFReaderException { - return fStreamPacketContextDecl.createDefinition(fStreamInputReader.getStreamInput(), LexicalScope.STREAM_PACKET_CONTEXT, input); - } - - /** - * Get the event header defintiion - * - * @param input - * the bitbuffer to read from - * @return an header definition, can be null - * @throws CTFReaderException - * out of bounds exception or such - */ - public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException { - return fTracePacketHeaderDecl.createDefinition(fStreamInputReader.getStreamInput().getStream().getTrace(), LexicalScope.TRACE_PACKET_HEADER, input); - } - - /** - * Dispose the StreamInputPacketReader - */ - @Override - public void close() { - fBitBuffer = null; - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Gets the current packet - * - * @return the current packet - */ - StreamInputPacketIndexEntry getCurrentPacket() { - return fCurrentPacket; - } - - /** - * Gets the CPU (core) number - * - * @return the CPU (core) number - */ - public int getCPU() { - return fCurrentCpu; - } - - @Override - public LexicalScope getScopePath() { - return LexicalScope.PACKET; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - @NonNull - private ByteBuffer getByteBufferAt(long position, long size) throws CTFReaderException, IOException { - ByteBuffer map = SafeMappedByteBuffer.map(fStreamInputReader.getFc(), MapMode.READ_ONLY, position, size); - if (map == null) { - throw new CTFReaderException("Failed to allocate mapped byte buffer"); //$NON-NLS-1$ - } - return map; - } - /** - * Changes the current packet to the given one. - * - * @param currentPacket - * The index entry of the packet to switch to. - * @throws CTFReaderException - * If we get an error reading the packet - */ - void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) throws CTFReaderException { - StreamInputPacketIndexEntry prevPacket = null; - fCurrentPacket = currentPacket; - - if (fCurrentPacket != null) { - /* - * Change the map of the BitBuffer. - */ - ByteBuffer bb = null; - try { - bb = getByteBufferAt( - fCurrentPacket.getOffsetBytes(), - (fCurrentPacket.getPacketSizeBits() + 7) / 8); - } catch (IOException e) { - throw new CTFReaderException(e.getMessage(), e); - } - - BitBuffer bitBuffer = new BitBuffer(bb); - fBitBuffer = bitBuffer; - /* - * Read trace packet header. - */ - if (fTracePacketHeaderDecl != null) { - fCurrentTracePacketHeaderDef = getTracePacketHeaderDefinition(bitBuffer); - } - - /* - * Read stream packet context. - */ - if (fStreamPacketContextDecl != null) { - fCurrentStreamPacketContextDef = getStreamPacketContextDefinition(bitBuffer); - - /* Read CPU ID */ - if (getCurrentPacket().getTarget() != null) { - fCurrentCpu = (int) getCurrentPacket().getTargetId(); - } - - /* Read number of lost events */ - fLostEventsInThisPacket = (int) getCurrentPacket().getLostEvents(); - if (fLostEventsInThisPacket != 0) { - fHasLost = true; - /* - * Compute the duration of the lost event time range. If the - * current packet is the first packet, duration will be set - * to 1. - */ - long lostEventsStartTime; - int index = fStreamInputReader.getStreamInput().getIndex().getEntries().indexOf(currentPacket); - if (index == 0) { - lostEventsStartTime = currentPacket.getTimestampBegin() + 1; - } else { - prevPacket = fStreamInputReader.getStreamInput().getIndex().getEntries().get(index - 1); - lostEventsStartTime = prevPacket.getTimestampEnd(); - } - fLostEventsDuration = Math.abs(lostEventsStartTime - currentPacket.getTimestampBegin()); - } - } - - /* - * Use the timestamp begin of the packet as the reference for the - * timestamp reconstitution. - */ - fLastTimestamp = currentPacket.getTimestampBegin(); - } else { - fBitBuffer = null; - fLastTimestamp = 0; - } - } - - /** - * Returns whether it is possible to read any more events from this packet. - * - * @return True if it is possible to read any more events from this packet. - */ - public boolean hasMoreEvents() { - BitBuffer bitBuffer = fBitBuffer; - StreamInputPacketIndexEntry currentPacket = fCurrentPacket; - if (currentPacket != null && bitBuffer != null) { - return fHasLost || (bitBuffer.position() < currentPacket.getContentSizeBits()); - } - return false; - } - - /** - * Reads the next event of the packet into the right event definition. - * - * @return The event definition containing the event data that was just - * read. - * @throws CTFReaderException - * If there was a problem reading the trace - */ - public EventDefinition readNextEvent() throws CTFReaderException { - /* Default values for those fields */ - // compromise since we cannot have 64 bit addressing of arrays yet. - int eventID = (int) EventDeclaration.UNSET_EVENT_ID; - long timestamp = 0; - if (fHasLost) { - fHasLost = false; - EventDeclaration lostEventDeclaration = EventDeclaration.getLostEventDeclaration(); - StructDeclaration lostFields = lostEventDeclaration.getFields(); - // this is a hard coded map, we know it's not null - IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_FIELD); - if (lostFieldsDecl == null) - { - throw new IllegalStateException("Lost events count not declared!"); //$NON-NLS-1$ - } - IntegerDeclaration lostEventsDurationDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_DURATION); - if (lostEventsDurationDecl == null) { - throw new IllegalStateException("Lost events duration not declared!"); //$NON-NLS-1$ - } - IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, fLostEventsDuration); - IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fLostEventsInThisPacket); - IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef }; - /* this is weird notation, but it's the java notation */ - final ImmutableList<String> fieldNameList = ImmutableList.<String> builder().add(CTFStrings.LOST_EVENTS_FIELD).add(CTFStrings.LOST_EVENTS_DURATION).build(); - return new EventDefinition( - lostEventDeclaration, - fStreamInputReader, - fLastTimestamp, - null, - null, - null, - new StructDefinition( - lostFields, - this, "fields", //$NON-NLS-1$ - fieldNameList, - fields - )); - - } - - final BitBuffer currentBitBuffer = fBitBuffer; - if (currentBitBuffer == null) { - return null; - } - final long posStart = currentBitBuffer.position(); - /* Read the stream event header. */ - if (fStreamEventHeaderDecl != null) { - if (fStreamEventHeaderDecl instanceof IEventHeaderDeclaration) { - fCurrentStreamEventHeaderDef = (ICompositeDefinition) fStreamEventHeaderDecl.createDefinition(null, "", currentBitBuffer); //$NON-NLS-1$ - EventHeaderDefinition ehd = (EventHeaderDefinition) fCurrentStreamEventHeaderDef; - eventID = ehd.getId(); - timestamp = calculateTimestamp(ehd.getTimestamp(), ehd.getTimestampLength()); - } else { - fCurrentStreamEventHeaderDef = ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(null, LexicalScope.EVENT_HEADER, currentBitBuffer); - StructDefinition StructEventHeaderDef = (StructDefinition) fCurrentStreamEventHeaderDef; - /* Check for the event id. */ - IDefinition idDef = StructEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$ - SimpleDatatypeDefinition simpleIdDef = null; - if (idDef instanceof SimpleDatatypeDefinition) { - simpleIdDef = ((SimpleDatatypeDefinition) idDef); - } else if (idDef != null) { - throw new CTFReaderException("Id defintion not an integer, enum or float definiton in event header."); //$NON-NLS-1$ - } - - /* - * Get the timestamp from the event header (may be overridden - * later on) - */ - IntegerDefinition timestampDef = StructEventHeaderDef.lookupInteger("timestamp"); //$NON-NLS-1$ - - /* Check for the variant v. */ - IDefinition variantDef = StructEventHeaderDef.lookupDefinition("v"); //$NON-NLS-1$ - if (variantDef instanceof VariantDefinition) { - - /* Get the variant current field */ - StructDefinition variantCurrentField = (StructDefinition) ((VariantDefinition) variantDef).getCurrentField(); - - /* - * Try to get the id field in the current field of the - * variant. If it is present, it overrides the previously - * read event id. - */ - IDefinition vIdDef = variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$ - if (vIdDef instanceof IntegerDefinition) { - simpleIdDef = (SimpleDatatypeDefinition) vIdDef; - } - - /* - * Get the timestamp. This would overwrite any previous - * timestamp definition - */ - timestampDef = variantCurrentField.lookupInteger("timestamp"); //$NON-NLS-1$ - } - if (simpleIdDef != null) { - eventID = simpleIdDef.getIntegerValue().intValue(); - } - if (timestampDef != null) { - timestamp = calculateTimestamp(timestampDef); - } // else timestamp remains 0 - } - } - /* Get the right event definition using the event id. */ - IEventDeclaration eventDeclaration = fStreamInputReader.getStreamInput().getStream().getEventDeclaration(eventID); - if (eventDeclaration == null) { - throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$ - } - EventDefinition eventDef = eventDeclaration.createDefinition(fStreamInputReader, currentBitBuffer, timestamp); - - /* - * Set the event timestamp using the timestamp calculated by - * updateTimestamp. - */ - - if (posStart == currentBitBuffer.position()) { - throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$ - } - - return eventDef; - } - - /** - * Calculates the timestamp value of the event, possibly using the timestamp - * from the last event. - * - * @param timestampDef - * Integer definition of the timestamp. - * @return The calculated timestamp value. - */ - private long calculateTimestamp(IntegerDefinition timestampDef) { - int len = timestampDef.getDeclaration().getLength(); - final long value = timestampDef.getValue(); - - return calculateTimestamp(value, len); - } - - private long calculateTimestamp(final long value, int len) { - long newval; - long majorasbitmask; - /* - * If the timestamp length is 64 bits, it is a full timestamp. - */ - if (len == 64) { - fLastTimestamp = value; - return fLastTimestamp; - } - - /* - * Bit mask to keep / remove all old / new bits. - */ - majorasbitmask = (1L << len) - 1; - - /* - * If the new value is smaller than the corresponding bits of the last - * timestamp, we assume an overflow of the compact representation. - */ - newval = value; - if (newval < (fLastTimestamp & majorasbitmask)) { - newval = newval + (1L << len); - } - - /* Keep only the high bits of the old value */ - fLastTimestamp = fLastTimestamp & ~majorasbitmask; - - /* Then add the low bits of the new value */ - fLastTimestamp = fLastTimestamp + newval; - - return fLastTimestamp; - } - - @Override - public Definition lookupDefinition(String lookupPath) { - if (lookupPath.equals(LexicalScope.STREAM_PACKET_CONTEXT.toString())) { - return (Definition) fCurrentStreamPacketContextDef; - } - if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER.toString())) { - return (Definition) fCurrentTracePacketHeaderDef; - } - return null; - } - - /** - * Get stream event header - * - * @return the stream event header - * @deprecated use - * {@link CTFStreamInputPacketReader#getStreamEventHeaderDefinition()} - */ - @Deprecated - public StructDefinition getCurrentStreamEventHeader() { - return (StructDefinition) ((fCurrentStreamEventHeaderDef instanceof StructDefinition) ? fCurrentStreamEventHeaderDef : null); - } - - /** - * Get stream event header - * - * @return the stream event header - * @since 3.1 - */ - public ICompositeDefinition getStreamEventHeaderDefinition() { - return fCurrentStreamEventHeaderDef; - } - - /** - * Get the current packet event header - * - * @return the current packet event header - */ - public StructDefinition getCurrentPacketEventHeader() { - if (fCurrentTracePacketHeaderDef instanceof StructDefinition) { - return (StructDefinition) fCurrentTracePacketHeaderDef; - } - return null; - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java deleted file mode 100644 index c7965b3988..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java +++ /dev/null @@ -1,495 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteOrder; -import java.nio.channels.FileChannel; -import java.nio.file.StandardOpenOption; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.internal.ctf.core.Activator; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; - -import com.google.common.collect.ImmutableList; - -/** - * A CTF trace event reader. Reads the events of a trace file. - * - * @author Matthew Khouzam - * @author Simon Marchi - * @since 3.0 - */ -public class CTFStreamInputReader implements AutoCloseable { - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * The StreamInput we are reading. - */ - private final @NonNull File fFile; - - private final @NonNull CTFStreamInput fStreamInput; - - private final FileChannel fFileChannel; - - /** - * The packet reader used to read packets from this trace file. - */ - private final CTFStreamInputPacketReader fPacketReader; - - /** - * Iterator on the packet index - */ - private int fPacketIndex; - - /** - * Reference to the current event of this trace file (iow, the last on that - * was read, the next one to be returned) - */ - private EventDefinition fCurrentEvent = null; - - private int fId; - - private CTFTraceReader fParent; - - /** - * Live trace reading - */ - private boolean fLive = false; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - /** - * Constructs a StreamInputReader that reads a StreamInput. - * - * @param streamInput - * The StreamInput to read. - * @throws CTFReaderException - * If the file cannot be opened - */ - public CTFStreamInputReader(CTFStreamInput streamInput) throws CTFReaderException { - if (streamInput == null) { - throw new IllegalArgumentException("stream cannot be null"); //$NON-NLS-1$ - } - fStreamInput = streamInput; - fFile = fStreamInput.getFile(); - try { - fFileChannel = FileChannel.open(fFile.toPath(), StandardOpenOption.READ); - } catch (IOException e) { - throw new CTFReaderException(e); - } - fPacketReader = new CTFStreamInputPacketReader(this); - /* - * Get the iterator on the packet index. - */ - fPacketIndex = 0; - /* - * Make first packet the current one. - */ - goToNextPacket(); - } - - /** - * Dispose the StreamInputReader, closes the file channel and its packet - * reader - * - * @throws IOException - * If an I/O error occurs - */ - @Override - public void close() throws IOException { - fFileChannel.close(); - fPacketReader.close(); - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Gets the current event in this stream - * - * @return the current event in the stream, null if the stream is - * finished/empty/malformed - */ - public EventDefinition getCurrentEvent() { - return fCurrentEvent; - } - - /** - * Gets the byte order for a trace - * - * @return the trace byte order - */ - public ByteOrder getByteOrder() { - return fStreamInput.getStream().getTrace().getByteOrder(); - } - - /** - * Gets the name of the stream (it's an id and a number) - * - * @return gets the stream name (it's a number) - */ - public int getName() { - return fId; - } - - /** - * Sets the name of the stream - * - * @param name - * the name of the stream, (it's a number) - */ - public void setName(int name) { - fId = name; - } - - /** - * Gets the CPU of a stream. It's the same as the one in /proc or running - * the asm CPUID instruction - * - * @return The CPU id (a number) - */ - public int getCPU() { - return fPacketReader.getCPU(); - } - - /** - * Gets the filename of the stream being read - * - * @return The filename of the stream being read - */ - public String getFilename() { - return fStreamInput.getFilename(); - } - - /* - * for internal use only - */ - CTFStreamInput getStreamInput() { - return fStreamInput; - } - - /** - * Gets the event definition set for this StreamInput - * - * @return Unmodifiable set with the event definitions - */ - public Iterable<IEventDeclaration> getEventDeclarations() { - return ImmutableList.copyOf(fStreamInput.getStream().getEventDeclarations()); - } - - /** - * Set the trace to live mode - * - * @param live - * whether the trace is read live or not - */ - public void setLive(boolean live) { - fLive = live; - } - - /** - * Get if the trace is to read live or not - * - * @return whether the trace is live or not - */ - public boolean isLive() { - return fLive; - } - - /** - * Get the event context of the stream - * - * @return the event context declaration of the stream - */ - public StructDeclaration getStreamEventContextDecl() { - return getStreamInput().getStream().getEventContextDecl(); - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - /** - * Reads the next event in the current event variable. - * - * @return If an event has been successfully read. - * @throws CTFReaderException - * if an error occurs - */ - public CTFResponse readNextEvent() throws CTFReaderException { - - /* - * Change packet if needed - */ - if (!fPacketReader.hasMoreEvents()) { - final StreamInputPacketIndexEntry prevPacket = fPacketReader - .getCurrentPacket(); - if (prevPacket != null || fLive) { - goToNextPacket(); - } - - } - - /* - * If an event is available, read it. - */ - if (fPacketReader.hasMoreEvents()) { - setCurrentEvent(fPacketReader.readNextEvent()); - return CTFResponse.OK; - } - this.setCurrentEvent(null); - return fLive ? CTFResponse.WAIT : CTFResponse.FINISH; - } - - /** - * Change the current packet of the packet reader to the next one. - * - * @throws CTFReaderException - * if an error occurs - */ - private void goToNextPacket() throws CTFReaderException { - fPacketIndex++; - // did we already index the packet? - if (getPacketSize() >= (fPacketIndex + 1)) { - fPacketReader.setCurrentPacket(getPacket()); - } else { - // go to the next packet if there is one, index it at the same time - if (fStreamInput.addPacketHeaderIndex()) { - fPacketIndex = getPacketSize() - 1; - fPacketReader.setCurrentPacket(getPacket()); - } else { - // out of packets - fPacketReader.setCurrentPacket(null); - } - } - } - - /** - * @return - */ - private int getPacketSize() { - return fStreamInput.getIndex().getEntries().size(); - } - - /** - * Changes the location of the trace file reader so that the current event - * is the first event with a timestamp greater or equal the given timestamp. - * - * @param timestamp - * The timestamp to seek to. - * @return The offset compared to the current position - * @throws CTFReaderException - * if an error occurs - */ - public long seek(long timestamp) throws CTFReaderException { - long offset = 0; - - gotoPacket(timestamp); - - /* - * index up to the desired timestamp. - */ - while ((fPacketReader.getCurrentPacket() != null) - && (fPacketReader.getCurrentPacket().getTimestampEnd() < timestamp)) { - try { - fStreamInput.addPacketHeaderIndex(); - goToNextPacket(); - } catch (CTFReaderException e) { - // do nothing here - Activator.log(e.getMessage()); - } - } - if (fPacketReader.getCurrentPacket() == null) { - gotoPacket(timestamp); - } - - /* - * Advance until either of these conditions are met: - * - * - reached the end of the trace file (the given timestamp is after the - * last event) - * - * - found the first event with a timestamp greater or equal the given - * timestamp. - */ - readNextEvent(); - boolean done = (this.getCurrentEvent() == null); - while (!done && (this.getCurrentEvent().getTimestamp() < timestamp)) { - readNextEvent(); - done = (this.getCurrentEvent() == null); - offset++; - } - return offset; - } - - /** - * @param timestamp - * the time to seek - * @throws CTFReaderException - * if an error occurs - */ - private void gotoPacket(long timestamp) throws CTFReaderException { - fPacketIndex = fStreamInput.getIndex().search(timestamp) - .previousIndex(); - /* - * Switch to this packet. - */ - goToNextPacket(); - } - - /** - * Seeks the last event of a stream and returns it. - * - * @throws CTFReaderException - * if an error occurs - */ - public void goToLastEvent() throws CTFReaderException { - /* - * Search in the index for the packet to search in. - */ - final int len = fStreamInput.getIndex().getEntries().size(); - - /* - * Go to beginning of trace. - */ - seek(0); - /* - * if the trace is empty. - */ - if ((len == 0) || (fPacketReader.hasMoreEvents() == false)) { - /* - * This means the trace is empty. abort. - */ - return; - } - /* - * Go to the last packet that contains events. - */ - for (int pos = len - 1; pos > 0; pos--) { - fPacketIndex = pos; - fPacketReader.setCurrentPacket(getPacket()); - if (fPacketReader.hasMoreEvents()) { - break; - } - } - - /* - * Go until the end of that packet - */ - EventDefinition prevEvent = null; - while (fCurrentEvent != null) { - prevEvent = fCurrentEvent; - this.readNextEvent(); - } - /* - * Go back to the previous event - */ - this.setCurrentEvent(prevEvent); - } - - /** - * @return the parent - */ - public CTFTraceReader getParent() { - return fParent; - } - - /** - * @param parent - * the parent to set - */ - public void setParent(CTFTraceReader parent) { - fParent = parent; - } - - /** - * Sets the current event in a stream input reader - * - * @param currentEvent - * the event to set - */ - public void setCurrentEvent(EventDefinition currentEvent) { - fCurrentEvent = currentEvent; - } - - /** - * @return the packetIndexIt - */ - private int getPacketIndex() { - return fPacketIndex; - } - - private StreamInputPacketIndexEntry getPacket() { - return fStreamInput.getIndex().getEntries().get(getPacketIndex()); - } - - /** - * Get the file channel wrapped by this reader - * - * @return the file channel - */ - FileChannel getFc() { - return fFileChannel; - } - - /** - * @return the packetReader - */ - public CTFStreamInputPacketReader getPacketReader() { - return fPacketReader; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + fId; - result = (prime * result) - + fFile.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof CTFStreamInputReader)) { - return false; - } - CTFStreamInputReader other = (CTFStreamInputReader) obj; - if (fId != other.fId) { - return false; - } - return fFile.equals(other.fFile); - } - - @Override - public String toString() { - // this helps debugging - return fId + ' ' + fCurrentEvent.toString(); - } - -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java deleted file mode 100644 index b383e93a9e..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java +++ /dev/null @@ -1,1007 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - * Alexandre Montplaisir - Initial API and implementation - * Simon Delisle - Replace LinkedList by TreeSet in callsitesByName attribute - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.io.Serializable; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.FileChannel; -import java.nio.channels.FileChannel.MapMode; -import java.nio.file.StandardOpenOption; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; - -import org.eclipse.linuxtools.ctf.core.event.CTFCallsite; -import org.eclipse.linuxtools.ctf.core.event.CTFClock; -import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; -import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope; -import org.eclipse.linuxtools.ctf.core.event.types.Definition; -import org.eclipse.linuxtools.ctf.core.event.types.IDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.internal.ctf.core.SafeMappedByteBuffer; -import org.eclipse.linuxtools.internal.ctf.core.event.CTFCallsiteComparator; -import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; -import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition; - -/** - * A CTF trace on the file system. - * - * Represents a trace on the filesystem. It is responsible of parsing the - * metadata, creating declarations data structures, indexing the event packets - * (in other words, all the work that can be shared between readers), but the - * actual reading of events is left to TraceReader. - * - * @author Matthew Khouzam - * @version $Revision: 1.0 $ - */ -public class CTFTrace implements IDefinitionScope, AutoCloseable { - - @Override - public String toString() { - /* Only for debugging, shouldn't be externalized */ - return "CTFTrace [path=" + fPath + ", major=" + fMajor + ", minor=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + fMinor + ", uuid=" + fUuid + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * The trace directory on the filesystem. - */ - private final File fPath; - - /** - * Major CTF version number - */ - private Long fMajor; - - /** - * Minor CTF version number - */ - private Long fMinor; - - /** - * Trace UUID - */ - private UUID fUuid; - - /** - * Trace byte order - */ - private ByteOrder fByteOrder; - - /** - * Packet header structure declaration - */ - private StructDeclaration fPacketHeaderDecl = null; - - /** - * The clock of the trace - */ - private CTFClock fSingleClock = null; - - /** - * Packet header structure definition - * - * This is only used when opening the trace files, to read the first packet - * header and see if they are valid trace files. - */ - private StructDefinition fPacketHeaderDef; - - /** - * Collection of streams contained in the trace. - */ - private final Map<Long, CTFStream> fStreams = new HashMap<>(); - - /** - * Collection of environment variables set by the tracer - */ - private final Map<String, String> fEnvironment = new HashMap<>(); - - /** - * Collection of all the clocks in a system. - */ - private final Map<String, CTFClock> fClocks = new HashMap<>(); - - /** Handlers for the metadata files */ - private static final FileFilter METADATA_FILE_FILTER = new MetadataFileFilter(); - private static final Comparator<File> METADATA_COMPARATOR = new MetadataComparator(); - - /** Callsite helpers */ - private CTFCallsiteComparator fCtfCallsiteComparator = new CTFCallsiteComparator(); - - private Map<String, TreeSet<CTFCallsite>> fCallsitesByName = new HashMap<>(); - - /** Callsite helpers */ - private TreeSet<CTFCallsite> fCallsitesByIP = new TreeSet<>(); - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Trace constructor. - * - * @param path - * Filesystem path of the trace directory - * @throws CTFReaderException - * If no CTF trace was found at the path - */ - public CTFTrace(String path) throws CTFReaderException { - this(new File(path)); - - } - - /** - * Trace constructor. - * - * @param path - * Filesystem path of the trace directory. - * @throws CTFReaderException - * If no CTF trace was found at the path - */ - public CTFTrace(File path) throws CTFReaderException { - fPath = path; - final Metadata metadata = new Metadata(this); - - /* Set up the internal containers for this trace */ - if (!fPath.exists()) { - throw new CTFReaderException("Trace (" + path.getPath() + ") doesn't exist. Deleted or moved?"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - if (!fPath.isDirectory()) { - throw new CTFReaderException("Path must be a valid directory"); //$NON-NLS-1$ - } - - /* Open and parse the metadata file */ - metadata.parseFile(); - - init(path); - } - - /** - * Streamed constructor - * - * @since 3.0 - */ - public CTFTrace() { - fPath = null; - } - - private void init(File path) throws CTFReaderException { - - /* Open all the trace files */ - - /* List files not called metadata and not hidden. */ - File[] files = path.listFiles(METADATA_FILE_FILTER); - Arrays.sort(files, METADATA_COMPARATOR); - - /* Try to open each file */ - for (File streamFile : files) { - openStreamInput(streamFile); - } - - /* Create their index */ - for (CTFStream stream : getStreams()) { - Set<CTFStreamInput> inputs = stream.getStreamInputs(); - for (CTFStreamInput s : inputs) { - addStream(s); - } - } - } - - /** - * Dispose the trace - * - * FIXME Not needed anymore, class doesn't need to be AutoCloseable. - * - * @since 3.0 - */ - @Override - public void close() { - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Gets an event declaration hash map for a given streamID - * - * @param streamId - * The ID of the stream from which to read - * @return The Hash map with the event declarations - * @since 2.0 - * @deprecated use {@link CTFTrace#getEventDeclarations(Long)} - */ - @Deprecated - public Map<Long, IEventDeclaration> getEvents(Long streamId) { - return fStreams.get(streamId).getEvents(); - } - - /** - * Gets an event declaration list for a given streamID - * - * @param streamId - * The ID of the stream from which to read - * @return The list of event declarations - * @since 3.2 - */ - public Collection<IEventDeclaration> getEventDeclarations(Long streamId) { - return fStreams.get(streamId).getEventDeclarations(); - } - - /** - * Get an event by it's ID - * - * @param streamId - * The ID of the stream from which to read - * @param id - * the ID of the event - * @return the event declaration - * @since 2.0 - * @deprecated use {@link CTFTrace#getEventType(long, int)} instead - */ - @Deprecated - public IEventDeclaration getEventType(long streamId, long id) { - return getStream(streamId).getEventDeclaration((int) id); - } - - /** - * Get an event by it's ID - * - * @param streamId - * The ID of the stream from which to read - * @param id - * the ID of the event - * @return the event declaration - * @since 3.2 - */ - public IEventDeclaration getEventType(long streamId, int id) { - return getEvents(streamId).get(id); - } - - /** - * Method getStream gets the stream for a given id - * - * @param id - * Long the id of the stream - * @return Stream the stream that we need - * @since 3.0 - */ - public CTFStream getStream(Long id) { - return fStreams.get(id); - } - - /** - * Method nbStreams gets the number of available streams - * - * @return int the number of streams - */ - public int nbStreams() { - return fStreams.size(); - } - - /** - * Method setMajor sets the major version of the trace (DO NOT USE) - * - * @param major - * long the major version - */ - public void setMajor(long major) { - fMajor = major; - } - - /** - * Method setMinor sets the minor version of the trace (DO NOT USE) - * - * @param minor - * long the minor version - */ - public void setMinor(long minor) { - fMinor = minor; - } - - /** - * Method setUUID sets the UUID of a trace - * - * @param uuid - * UUID - */ - public void setUUID(UUID uuid) { - fUuid = uuid; - } - - /** - * Method setByteOrder sets the byte order - * - * @param byteOrder - * ByteOrder of the trace, can be little-endian or big-endian - */ - public void setByteOrder(ByteOrder byteOrder) { - fByteOrder = byteOrder; - } - - /** - * Method setPacketHeader sets the packet header of a trace (DO NOT USE) - * - * @param packetHeader - * StructDeclaration the header in structdeclaration form - */ - public void setPacketHeader(StructDeclaration packetHeader) { - fPacketHeaderDecl = packetHeader; - } - - /** - * Method majorIsSet is the major version number set? - * - * @return boolean is the major set? - * @since 3.0 - */ - public boolean majorIsSet() { - return fMajor != null; - } - - /** - * Method minorIsSet. is the minor version number set? - * - * @return boolean is the minor set? - */ - public boolean minorIsSet() { - return fMinor != null; - } - - /** - * Method UUIDIsSet is the UUID set? - * - * @return boolean is the UUID set? - * @since 2.0 - */ - public boolean uuidIsSet() { - return fUuid != null; - } - - /** - * Method byteOrderIsSet is the byteorder set? - * - * @return boolean is the byteorder set? - */ - public boolean byteOrderIsSet() { - return fByteOrder != null; - } - - /** - * Method packetHeaderIsSet is the packet header set? - * - * @return boolean is the packet header set? - */ - public boolean packetHeaderIsSet() { - return fPacketHeaderDecl != null; - } - - /** - * Method getUUID gets the trace UUID - * - * @return UUID gets the trace UUID - */ - public UUID getUUID() { - return fUuid; - } - - /** - * Method getMajor gets the trace major version - * - * @return long gets the trace major version - */ - public long getMajor() { - return fMajor; - } - - /** - * Method getMinor gets the trace minor version - * - * @return long gets the trace minor version - */ - public long getMinor() { - return fMinor; - } - - /** - * Method getByteOrder gets the trace byte order - * - * @return ByteOrder gets the trace byte order - */ - public final ByteOrder getByteOrder() { - return fByteOrder; - } - - /** - * Method getPacketHeader gets the trace packet header - * - * @return StructDeclaration gets the trace packet header - */ - public StructDeclaration getPacketHeader() { - return fPacketHeaderDecl; - } - - /** - * Method getTraceDirectory gets the trace directory - * - * @return File the path in "File" format. - */ - public File getTraceDirectory() { - return fPath; - } - - /** - * Get all the streams as an iterable. - * - * @return Iterable<Stream> an iterable over streams. - * @since 3.0 - */ - public Iterable<CTFStream> getStreams() { - return fStreams.values(); - } - - /** - * Method getPath gets the path of the trace directory - * - * @return String the path of the trace directory, in string format. - * @see java.io.File#getPath() - */ - public String getPath() { - return (fPath != null) ? fPath.getPath() : ""; //$NON-NLS-1$ - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - private void addStream(CTFStreamInput s) { - - /* - * add the stream - */ - CTFStream stream = s.getStream(); - fStreams.put(stream.getId(), stream); - - /* - * index the trace - */ - s.setupIndex(); - } - - /** - * Tries to open the given file, reads the first packet header of the file - * and check its validity. This will add a file to a stream as a streaminput - * - * @param streamFile - * A trace file in the trace directory. - * @param index - * Which index in the class' streamFileChannel array this file - * must use - * @throws CTFReaderException - * if there is a file error - */ - private CTFStream openStreamInput(File streamFile) throws CTFReaderException { - ByteBuffer byteBuffer; - BitBuffer streamBitBuffer; - CTFStream stream; - - if (!streamFile.canRead()) { - throw new CTFReaderException("Unreadable file : " //$NON-NLS-1$ - + streamFile.getPath()); - } - - try (FileChannel fc = FileChannel.open(streamFile.toPath(), StandardOpenOption.READ)) { - /* Map one memory page of 4 kiB */ - byteBuffer = SafeMappedByteBuffer.map(fc, MapMode.READ_ONLY, 0, (int) Math.min(fc.size(), 4096L)); - if (byteBuffer == null) { - throw new IllegalStateException("Failed to allocate memory"); //$NON-NLS-1$ - } - /* Create a BitBuffer with this mapping and the trace byte order */ - streamBitBuffer = new BitBuffer(byteBuffer, this.getByteOrder()); - - if (fPacketHeaderDecl != null) { - /* Read the packet header */ - fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, LexicalScope.PACKET_HEADER, streamBitBuffer); - } - } catch (IOException e) { - /* Shouldn't happen at this stage if every other check passed */ - throw new CTFReaderException(e); - } - if (fPacketHeaderDef != null) { - validateMagicNumber(fPacketHeaderDef); - - validateUUID(fPacketHeaderDef); - - /* Read the stream ID */ - IDefinition streamIDDef = fPacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$ - - if (streamIDDef instanceof IntegerDefinition) { - /* This doubles as a null check */ - long streamID = ((IntegerDefinition) streamIDDef).getValue(); - stream = fStreams.get(streamID); - } else { - /* No stream_id in the packet header */ - stream = fStreams.get(null); - } - - } else { - /* No packet header, we suppose there is only one stream */ - stream = fStreams.get(null); - } - - if (stream == null) { - throw new CTFReaderException("Unexpected end of stream"); //$NON-NLS-1$ - } - - /* - * Create the stream input and add a reference to the streamInput in the - * stream. - */ - stream.addInput(new CTFStreamInput(stream, streamFile)); - return stream; - } - - private void validateUUID(StructDefinition packetHeaderDef) throws CTFReaderException { - IDefinition lookupDefinition = packetHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$ - ArrayDefinition uuidDef = (ArrayDefinition) lookupDefinition; - if (uuidDef != null) { - UUID otheruuid = Utils.getUUIDfromDefinition(uuidDef); - if (!fUuid.equals(otheruuid)) { - throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ - } - } - } - - private static void validateMagicNumber(StructDefinition packetHeaderDef) throws CTFReaderException { - IntegerDefinition magicDef = (IntegerDefinition) packetHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$ - int magic = (int) magicDef.getValue(); - if (magic != Utils.CTF_MAGIC) { - throw new CTFReaderException("CTF magic mismatch"); //$NON-NLS-1$ - } - } - - // ------------------------------------------------------------------------ - // IDefinitionScope - // ------------------------------------------------------------------------ - - /** - * @since 3.0 - */ - @Override - public LexicalScope getScopePath() { - return LexicalScope.TRACE; - } - - /** - * Looks up a definition from packet - * - * @param lookupPath - * String - * @return Definition - * @see org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope#lookupDefinition(String) - */ - @Override - public Definition lookupDefinition(String lookupPath) { - if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER.toString())) { - return fPacketHeaderDef; - } - return null; - } - - // ------------------------------------------------------------------------ - // Live trace reading - // ------------------------------------------------------------------------ - - /** - * Add a new stream file to support new streams while the trace is being - * read. - * - * @param streamFile - * the file of the stream - * @throws CTFReaderException - * A stream had an issue being read - * @since 3.0 - */ - public void addStreamFile(File streamFile) throws CTFReaderException { - openStreamInput(streamFile); - } - - /** - * Registers a new stream to the trace. - * - * @param stream - * A stream object. - * @throws ParseException - * If there was some problem reading the metadata - * @since 3.0 - */ - public void addStream(CTFStream stream) throws ParseException { - /* - * If there is already a stream without id (the null key), it must be - * the only one - */ - if (fStreams.get(null) != null) { - throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$ - } - - /* - * If the stream we try to add has the null key, it must be the only - * one. Thus, if the streams container is not empty, it is not valid. - */ - if ((stream.getId() == null) && (fStreams.size() != 0)) { - throw new ParseException("Stream without id with multiple streams"); //$NON-NLS-1$ - } - - /* - * If a stream with the same ID already exists, it is not valid. - */ - CTFStream existingStream = fStreams.get(stream.getId()); - if (existingStream != null) { - throw new ParseException("Stream id already exists"); //$NON-NLS-1$ - } - - /* This stream is valid and has a unique id. */ - fStreams.put(stream.getId(), stream); - } - - /** - * Gets the Environment variables from the trace metadata (See CTF spec) - * - * @return The environment variables in the form of an unmodifiable map - * (key, value) - * @since 2.0 - */ - public Map<String, String> getEnvironment() { - return Collections.unmodifiableMap(fEnvironment); - } - - /** - * Add a variable to the environment variables - * - * @param varName - * the name of the variable - * @param varValue - * the value of the variable - */ - public void addEnvironmentVar(String varName, String varValue) { - fEnvironment.put(varName, varValue); - } - - /** - * Add a clock to the clock list - * - * @param nameValue - * the name of the clock (full name with scope) - * @param ctfClock - * the clock - */ - public void addClock(String nameValue, CTFClock ctfClock) { - fClocks.put(nameValue, ctfClock); - } - - /** - * gets the clock with a specific name - * - * @param name - * the name of the clock. - * @return the clock - */ - public CTFClock getClock(String name) { - return fClocks.get(name); - } - - /** - * gets the clock if there is only one. (this is 100% of the use cases as of - * June 2012) - * - * @return the clock - */ - public final CTFClock getClock() { - if (fSingleClock != null && fClocks.size() == 1) { - return fSingleClock; - } - if (fClocks.size() == 1) { - fSingleClock = fClocks.get(fClocks.keySet().iterator().next()); - return fSingleClock; - } - return null; - } - - /** - * gets the time offset of a clock with respect to UTC in nanoseconds - * - * @return the time offset of a clock with respect to UTC in nanoseconds - */ - public final long getOffset() { - if (getClock() == null) { - return 0; - } - return fSingleClock.getClockOffset(); - } - - /** - * gets the time offset of a clock with respect to UTC in nanoseconds - * - * @return the time offset of a clock with respect to UTC in nanoseconds - */ - private double getTimeScale() { - if (getClock() == null) { - return 1.0; - } - return fSingleClock.getClockScale(); - } - - /** - * Gets the current first packet start time - * - * @return the current start time - * @since 3.0 - */ - public long getCurrentStartTime() { - long currentStart = Long.MAX_VALUE; - for (CTFStream stream : fStreams.values()) { - for (CTFStreamInput si : stream.getStreamInputs()) { - currentStart = Math.min(currentStart, si.getIndex().getEntries().get(0).getTimestampBegin()); - } - } - return timestampCyclesToNanos(currentStart); - } - - /** - * Gets the current last packet end time - * - * @return the current end time - * @since 3.0 - */ - public long getCurrentEndTime() { - long currentEnd = Long.MIN_VALUE; - for (CTFStream stream : fStreams.values()) { - for (CTFStreamInput si : stream.getStreamInputs()) { - currentEnd = Math.max(currentEnd, si.getTimestampEnd()); - } - } - return timestampCyclesToNanos(currentEnd); - } - - /** - * Does the trace need to time scale? - * - * @return if the trace is in ns or cycles. - */ - private boolean clockNeedsScale() { - if (getClock() == null) { - return false; - } - return fSingleClock.isClockScaled(); - } - - /** - * the inverse clock for returning to a scale. - * - * @return 1.0 / scale - */ - private double getInverseTimeScale() { - if (getClock() == null) { - return 1.0; - } - return fSingleClock.getClockAntiScale(); - } - - /** - * @param cycles - * clock cycles since boot - * @return time in nanoseconds UTC offset - * @since 2.0 - */ - public long timestampCyclesToNanos(long cycles) { - long retVal = cycles + getOffset(); - /* - * this fix is since quite often the offset will be > than 53 bits and - * therefore the conversion will be lossy - */ - if (clockNeedsScale()) { - retVal = (long) (retVal * getTimeScale()); - } - return retVal; - } - - /** - * @param nanos - * time in nanoseconds UTC offset - * @return clock cycles since boot. - * @since 2.0 - */ - public long timestampNanoToCycles(long nanos) { - long retVal; - /* - * this fix is since quite often the offset will be > than 53 bits and - * therefore the conversion will be lossy - */ - if (clockNeedsScale()) { - retVal = (long) (nanos * getInverseTimeScale()); - } else { - retVal = nanos; - } - return retVal - getOffset(); - } - - /** - * Adds a callsite - * - * @param eventName - * the event name of the callsite - * @param funcName - * the name of the callsite function - * @param ip - * the ip of the callsite - * @param fileName - * the filename of the callsite - * @param lineNumber - * the line number of the callsite - */ - public void addCallsite(String eventName, String funcName, long ip, - String fileName, long lineNumber) { - final CTFCallsite cs = new CTFCallsite(eventName, funcName, ip, - fileName, lineNumber); - TreeSet<CTFCallsite> csl = fCallsitesByName.get(eventName); - if (csl == null) { - csl = new TreeSet<>(fCtfCallsiteComparator); - fCallsitesByName.put(eventName, csl); - } - - csl.add(cs); - - fCallsitesByIP.add(cs); - } - - /** - * Gets the set of callsites associated to an event name. O(1) - * - * @param eventName - * the event name - * @return the callsite set can be empty - * @since 3.0 - */ - public TreeSet<CTFCallsite> getCallsiteCandidates(String eventName) { - TreeSet<CTFCallsite> retVal = fCallsitesByName.get(eventName); - if (retVal == null) { - retVal = new TreeSet<>(fCtfCallsiteComparator); - } - return retVal; - } - - /** - * The I'm feeling lucky of getCallsiteCandidates O(1) - * - * @param eventName - * the event name - * @return the first callsite that has that event name, can be null - * @since 1.2 - */ - public CTFCallsite getCallsite(String eventName) { - TreeSet<CTFCallsite> callsites = fCallsitesByName.get(eventName); - if (callsites != null) { - return callsites.first(); - } - return null; - } - - /** - * Gets a callsite from the instruction pointer O(log(n)) - * - * @param ip - * the instruction pointer to lookup - * @return the callsite just before that IP in the list remember the IP is - * backwards on X86, can be null if no callsite is before the IP. - * @since 1.2 - */ - public CTFCallsite getCallsite(long ip) { - CTFCallsite cs = new CTFCallsite(null, null, ip, null, 0L); - return fCallsitesByIP.ceiling(cs); - } - - /** - * Gets a callsite using the event name and instruction pointer O(log(n)) - * - * @param eventName - * the name of the event - * @param ip - * the instruction pointer - * @return the closest matching callsite, can be null - */ - public CTFCallsite getCallsite(String eventName, long ip) { - final TreeSet<CTFCallsite> candidates = fCallsitesByName.get(eventName); - if (candidates == null) { - return null; - } - final CTFCallsite dummyCs = new CTFCallsite(null, null, ip, null, -1); - final CTFCallsite callsite = candidates.ceiling(dummyCs); - if (callsite == null) { - return candidates.floor(dummyCs); - } - return callsite; - } - - /** - * Add a new stream - * - * @param id - * the ID of the stream - * @param streamFile - * new file in the stream - * @throws CTFReaderException - * The file must exist - * @since 3.0 - */ - // TODO: remove suppress warning - @SuppressWarnings("resource") - public void addStream(long id, File streamFile) throws CTFReaderException { - CTFStream stream = null; - final File file = streamFile; - if (file == null) { - throw new CTFReaderException("cannot create a stream with no file"); //$NON-NLS-1$ - } - if (fStreams.containsKey(id)) { - stream = fStreams.get(id); - } else { - stream = new CTFStream(this); - fStreams.put(id, stream); - } - stream.addInput(new CTFStreamInput(stream, file)); - } -} - -class MetadataFileFilter implements FileFilter { - - @Override - public boolean accept(File pathname) { - if (pathname.isDirectory()) { - return false; - } - if (pathname.isHidden()) { - return false; - } - if (pathname.getName().equals("metadata")) { //$NON-NLS-1$ - return false; - } - return true; - } - -} - -class MetadataComparator implements Comparator<File>, Serializable { - - private static final long serialVersionUID = 1L; - - @Override - public int compare(File o1, File o2) { - return o1.getName().compareTo(o2.getName()); - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java deleted file mode 100644 index 0590798ed0..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java +++ /dev/null @@ -1,573 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - * Alexandre Montplaisir - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.PriorityQueue; -import java.util.Set; - -import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; -import org.eclipse.linuxtools.internal.ctf.core.Activator; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; - -/** - * A CTF trace reader. Reads the events of a trace. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Alexandre Montplaisir - */ -public class CTFTraceReader implements AutoCloseable { - - private static final int MIN_PRIO_SIZE = 16; - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * The trace to read from. - */ - private final CTFTrace fTrace; - - /** - * Vector of all the trace file readers. - */ - private final List<CTFStreamInputReader> fStreamInputReaders = new ArrayList<>(); - - /** - * Priority queue to order the trace file readers by timestamp. - */ - private PriorityQueue<CTFStreamInputReader> fPrio; - - /** - * Array to count the number of event per trace file. - */ - private long[] fEventCountPerTraceFile; - - /** - * Timestamp of the first event in the trace - */ - private long fStartTime; - - /** - * Timestamp of the last event read so far - */ - private long fEndTime; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs a TraceReader to read a trace. - * - * @param trace - * The trace to read from. - * @throws CTFReaderException - * if an error occurs - */ - public CTFTraceReader(CTFTrace trace) throws CTFReaderException { - fTrace = trace; - fStreamInputReaders.clear(); - - /** - * Create the trace file readers. - */ - createStreamInputReaders(); - - /** - * Populate the timestamp-based priority queue. - */ - populateStreamInputReaderHeap(); - - /** - * Get the start Time of this trace bear in mind that the trace could be - * empty. - */ - fStartTime = 0; - if (hasMoreEvents()) { - fStartTime = getTopStream().getCurrentEvent().getTimestamp(); - setEndTime(fStartTime); - } - } - - /** - * Copy constructor - * - * @return The new CTFTraceReader - * @throws CTFReaderException - * if an error occurs - */ - public CTFTraceReader copyFrom() throws CTFReaderException { - CTFTraceReader newReader = null; - - newReader = new CTFTraceReader(fTrace); - newReader.fStartTime = fStartTime; - newReader.setEndTime(fEndTime); - return newReader; - } - - /** - * Dispose the CTFTraceReader - * - * @since 3.0 - */ - @Override - public void close() { - for (CTFStreamInputReader reader : fStreamInputReaders) { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - Activator.logError(e.getMessage(), e); - } - } - } - fStreamInputReaders.clear(); - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Return the start time of this trace (== timestamp of the first event) - * - * @return the trace start time - */ - public long getStartTime() { - return fStartTime; - } - - /** - * Set the trace's end time - * - * @param endTime - * The end time to use - */ - protected final void setEndTime(long endTime) { - fEndTime = endTime; - } - - /** - * Get the priority queue of this trace reader. - * - * @return The priority queue of input readers - * @since 2.0 - */ - protected PriorityQueue<CTFStreamInputReader> getPrio() { - return fPrio; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * Creates one trace file reader per trace file contained in the trace. - * - * @throws CTFReaderException - * if an error occurs - */ - private void createStreamInputReaders() throws CTFReaderException { - /* - * For each stream. - */ - for (CTFStream stream : fTrace.getStreams()) { - Set<CTFStreamInput> streamInputs = stream.getStreamInputs(); - - /* - * For each trace file of the stream. - */ - for (CTFStreamInput streamInput : streamInputs) { - - /* - * Create a reader and add it to the group. - */ - fStreamInputReaders.add(new CTFStreamInputReader(streamInput)); - } - } - - /* - * Create the array to count the number of event per trace file. - */ - fEventCountPerTraceFile = new long[fStreamInputReaders.size()]; - } - - /** - * Update the priority queue to make it match the parent trace - * - * @throws CTFReaderException - * An error occured - * - * @since 3.0 - */ - public void update() throws CTFReaderException { - Set<CTFStreamInputReader> readers = new HashSet<>(); - for (CTFStream stream : fTrace.getStreams()) { - Set<CTFStreamInput> streamInputs = stream.getStreamInputs(); - for (CTFStreamInput streamInput : streamInputs) { - /* - * Create a reader. - */ - CTFStreamInputReader streamInputReader = new CTFStreamInputReader( - streamInput); - - /* - * Add it to the group. - */ - if (!fStreamInputReaders.contains(streamInputReader)) { - streamInputReader.readNextEvent(); - fStreamInputReaders.add(streamInputReader); - readers.add(streamInputReader); - } - } - } - long[] temp = fEventCountPerTraceFile; - fEventCountPerTraceFile = new long[readers.size() + temp.length]; - for (CTFStreamInputReader reader : readers) { - fPrio.add(reader); - } - for (int i = 0; i < temp.length; i++) { - fEventCountPerTraceFile[i] = temp[i]; - } - } - - /** - * Gets an iterable of the stream input readers, useful for foreaches - * - * @return the iterable of the stream input readers - * @since 3.0 - */ - public Iterable<IEventDeclaration> getEventDeclarations() { - ImmutableSet.Builder<IEventDeclaration> builder = new Builder<>(); - for (CTFStreamInputReader sir : fStreamInputReaders) { - builder.addAll(sir.getEventDeclarations()); - } - return builder.build(); - } - - /** - * Initializes the priority queue used to choose the trace file with the - * lower next event timestamp. - * - * @throws CTFReaderException - * if an error occurs - */ - private void populateStreamInputReaderHeap() throws CTFReaderException { - if (fStreamInputReaders.isEmpty()) { - fPrio = new PriorityQueue<>(MIN_PRIO_SIZE, - new StreamInputReaderTimestampComparator()); - return; - } - - /* - * Create the priority queue with a size twice as bigger as the number - * of reader in order to avoid constant resizing. - */ - fPrio = new PriorityQueue<>( - Math.max(fStreamInputReaders.size() * 2, MIN_PRIO_SIZE), - new StreamInputReaderTimestampComparator()); - - int pos = 0; - - for (CTFStreamInputReader reader : fStreamInputReaders) { - /* - * Add each trace file reader in the priority queue, if we are able - * to read an event from it. - */ - reader.setParent(this); - CTFResponse readNextEvent = reader.readNextEvent(); - if (readNextEvent == CTFResponse.OK || readNextEvent == CTFResponse.WAIT) { - fPrio.add(reader); - - fEventCountPerTraceFile[pos] = 0; - reader.setName(pos); - - pos++; - } - } - } - - /** - * Get the current event, which is the current event of the trace file - * reader with the lowest timestamp. - * - * @return An event definition, or null of the trace reader reached the end - * of the trace. - */ - public EventDefinition getCurrentEventDef() { - CTFStreamInputReader top = getTopStream(); - return (top != null) ? top.getCurrentEvent() : null; - } - - /** - * Go to the next event. - * - * @return True if an event was read. - * @throws CTFReaderException - * if an error occurs - */ - public boolean advance() throws CTFReaderException { - /* - * Remove the reader from the top of the priority queue. - */ - CTFStreamInputReader top = fPrio.poll(); - - /* - * If the queue was empty. - */ - if (top == null) { - return false; - } - /* - * Read the next event of this reader. - */ - switch (top.readNextEvent()) { - case OK: { - /* - * Add it back in the queue. - */ - fPrio.add(top); - final long topEnd = fTrace.timestampCyclesToNanos(top.getCurrentEvent().getTimestamp()); - setEndTime(Math.max(topEnd, getEndTime())); - fEventCountPerTraceFile[top.getName()]++; - - if (top.getCurrentEvent() != null) { - fEndTime = Math.max(top.getCurrentEvent().getTimestamp(), - fEndTime); - } - break; - } - case WAIT: { - fPrio.add(top); - break; - } - case FINISH: - break; - case ERROR: - default: - // something bad happend - } - /* - * If there is no reader in the queue, it means the trace reader reached - * the end of the trace. - */ - return hasMoreEvents(); - } - - /** - * Go to the last event in the trace. - * - * @throws CTFReaderException - * if an error occurs - */ - public void goToLastEvent() throws CTFReaderException { - seek(getEndTime()); - while (fPrio.size() > 1) { - advance(); - } - } - - /** - * Seeks to a given timestamp. It will seek to the nearest event greater or - * equal to timestamp. If a trace is [10 20 30 40] and you are looking for - * 19, it will give you 20. If you want 20, you will get 20, if you want 21, - * you will get 30. The value -inf will seek to the first element and the - * value +inf will seek to the end of the file (past the last event). - * - * @param timestamp - * the timestamp to seek to - * @return true if there are events above or equal the seek timestamp, false - * if seek at the end of the trace (no valid event). - * @throws CTFReaderException - * if an error occurs - */ - public boolean seek(long timestamp) throws CTFReaderException { - /* - * Remove all the trace readers from the priority queue - */ - fPrio.clear(); - for (CTFStreamInputReader streamInputReader : fStreamInputReaders) { - /* - * Seek the trace reader. - */ - streamInputReader.seek(timestamp); - - /* - * Add it to the priority queue if there is a current event. - */ - if (streamInputReader.getCurrentEvent() != null) { - fPrio.add(streamInputReader); - } - } - return hasMoreEvents(); - } - - /** - * Gets the stream with the oldest event - * - * @return the stream with the oldest event - * @since 3.0 - */ - public CTFStreamInputReader getTopStream() { - return fPrio.peek(); - } - - /** - * Does the trace have more events? - * - * @return true if yes. - */ - public final boolean hasMoreEvents() { - return fPrio.size() > 0; - } - - /** - * Prints the event count stats. - */ - public void printStats() { - printStats(60); - } - - /** - * Prints the event count stats. - * - * @param width - * Width of the display. - */ - public void printStats(int width) { - int numEvents = 0; - if (width == 0) { - return; - } - - for (long i : fEventCountPerTraceFile) { - numEvents += i; - } - - for (int j = 0; j < fEventCountPerTraceFile.length; j++) { - CTFStreamInputReader se = fStreamInputReaders.get(j); - - long len = (width * fEventCountPerTraceFile[se.getName()]) - / numEvents; - - StringBuilder sb = new StringBuilder(se.getFilename()); - sb.append("\t["); //$NON-NLS-1$ - - for (int i = 0; i < len; i++) { - sb.append('+'); - } - - for (long i = len; i < width; i++) { - sb.append(' '); - } - - sb.append("]\t" + fEventCountPerTraceFile[se.getName()] + " Events"); //$NON-NLS-1$//$NON-NLS-2$ - Activator.log(sb.toString()); - } - } - - /** - * Gets the last event timestamp that was read. This is NOT necessarily the - * last event in a trace, just the last one read so far. - * - * @return the last event - */ - public long getEndTime() { - return fEndTime; - } - - /** - * Sets a trace to be live or not - * - * @param live - * whether the trace is live - * @since 3.0 - */ - public void setLive(boolean live) { - for (CTFStreamInputReader s : fPrio) { - s.setLive(live); - } - } - - /** - * Get if the trace is to read live or not - * - * @return whether the trace is live or not - * @since 3.0 - * - */ - public boolean isLive() { - return getTopStream().isLive(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + (int) (fStartTime ^ (fStartTime >>> 32)); - result = (prime * result) + fStreamInputReaders.hashCode(); - result = (prime * result) + ((fTrace == null) ? 0 : fTrace.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof CTFTraceReader)) { - return false; - } - CTFTraceReader other = (CTFTraceReader) obj; - if (!fStreamInputReaders.equals(other.fStreamInputReaders)) { - return false; - } - if (fTrace == null) { - if (other.fTrace != null) { - return false; - } - } else if (!fTrace.equals(other.fTrace)) { - return false; - } - return true; - } - - @Override - public String toString() { - /* Only for debugging, shouldn't be externalized */ - return "CTFTraceReader [trace=" + fTrace + ']'; //$NON-NLS-1$ - } - - /** - * Gets the parent trace - * - * @return the parent trace - */ - public CTFTrace getTrace() { - return fTrace; - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java deleted file mode 100644 index 41edcdb5b6..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java +++ /dev/null @@ -1,457 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Khouzam - Initial API and implementation - * Simon Marchi - Initial API and implementation - * Matthew Khouzam - Update for live trace reading support - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.channels.FileChannel; -import java.util.UUID; - -import org.antlr.runtime.ANTLRReaderStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.RewriteCardinalityException; -import org.eclipse.linuxtools.ctf.parser.CTFLexer; -import org.eclipse.linuxtools.ctf.parser.CTFParser; -import org.eclipse.linuxtools.ctf.parser.CTFParser.parse_return; -import org.eclipse.linuxtools.internal.ctf.core.event.metadata.IOStructGen; -import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.CtfAntlrException; -import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; - -/** - * The CTF trace metadata TSDL file - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public class Metadata { - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - /** - * Name of the metadata file in the trace directory - */ - private static final String METADATA_FILENAME = "metadata"; //$NON-NLS-1$ - - /** - * Size of the metadata packet header, in bytes, computed by hand. - */ - private static final int METADATA_PACKET_HEADER_SIZE = 37; - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - /** - * Byte order as detected when reading the TSDL magic number. - */ - private ByteOrder detectedByteOrder = null; - - /** - * The trace file to which belongs this metadata file. - */ - private final CTFTrace trace; - - private IOStructGen fTreeParser; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Constructs a Metadata object. - * - * @param trace - * The trace to which belongs this metadata file. - */ - public Metadata(CTFTrace trace) { - this.trace = trace; - } - - /** - * For network streaming - * - * @since 3.0 - */ - public Metadata() { - trace = new CTFTrace(); - } - - // ------------------------------------------------------------------------ - // Getters/Setters/Predicates - // ------------------------------------------------------------------------ - - /** - * Returns the ByteOrder that was detected while parsing the metadata. - * - * @return The byte order. - */ - public ByteOrder getDetectedByteOrder() { - return detectedByteOrder; - } - - /** - * Gets the parent trace - * - * @return the parent trace - * @since 3.0 - */ - public CTFTrace getTrace() { - return trace; - } - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * Parse the metadata file. - * - * @throws CTFReaderException - * If there was a problem parsing the metadata - * @since 3.0 - */ - public void parseFile() throws CTFReaderException { - - /* - * Reader. It will contain a StringReader if we are using packet-based - * metadata and it will contain a FileReader if we have text-based - * metadata. - */ - - try (FileInputStream fis = new FileInputStream(getMetadataPath()); - FileChannel metadataFileChannel = fis.getChannel(); - /* Check if metadata is packet-based, if not it is text based */ - Reader metadataTextInput = - (isPacketBased(metadataFileChannel) ? - readBinaryMetaData(metadataFileChannel) : - new FileReader(getMetadataPath()));) { - - readMetaDataText(metadataTextInput); - - } catch (FileNotFoundException e) { - throw new CTFReaderException("Cannot find metadata file!"); //$NON-NLS-1$ - } catch (IOException | ParseException e) { - throw new CTFReaderException(e); - } catch (RecognitionException | RewriteCardinalityException e) { - throw new CtfAntlrException(e); - } - } - - private Reader readBinaryMetaData(FileChannel metadataFileChannel) throws CTFReaderException { - /* Create StringBuffer to receive metadata text */ - StringBuffer metadataText = new StringBuffer(); - - /* - * Read metadata packet one by one, appending the text to the - * StringBuffer - */ - MetadataPacketHeader packetHeader = readMetadataPacket( - metadataFileChannel, metadataText); - while (packetHeader != null) { - packetHeader = readMetadataPacket(metadataFileChannel, - metadataText); - } - - /* Wrap the metadata string with a StringReader */ - return new StringReader(metadataText.toString()); - } - - /** - * Read the metadata from a formatted TSDL string - * - * @param data - * the data to read - * @throws CTFReaderException - * this exception wraps a ParseException, IOException or - * CtfAntlrException, three exceptions that can be obtained from - * parsing a TSDL file - * @since 3.0 - */ - public void parseText(String data) throws CTFReaderException { - Reader metadataTextInput = new StringReader(data); - try { - readMetaDataText(metadataTextInput); - } catch (IOException | ParseException e) { - throw new CTFReaderException(e); - } catch (RecognitionException | RewriteCardinalityException e) { - throw new CtfAntlrException(e); - } - - } - - private void readMetaDataText(Reader metadataTextInput) throws IOException, RecognitionException, ParseException { - CommonTree tree = createAST(metadataTextInput); - - /* Generate IO structures (declarations) */ - fTreeParser = new IOStructGen(tree, trace); - fTreeParser.generate(); - } - - /** - * Read a metadata fragment from a formatted TSDL string - * - * @param dataFragment - * the data to read - * @throws CTFReaderException - * this exception wraps a ParseException, IOException or - * CtfAntlrException, three exceptions that can be obtained from - * parsing a TSDL file - * @since 3.0 - */ - public void parseTextFragment(String dataFragment) throws CTFReaderException { - Reader metadataTextInput = new StringReader(dataFragment); - try { - readMetaDataTextFragment(metadataTextInput); - } catch (IOException | ParseException e) { - throw new CTFReaderException(e); - } catch (RecognitionException | RewriteCardinalityException e) { - throw new CtfAntlrException(e); - } - } - - private void readMetaDataTextFragment(Reader metadataTextInput) throws IOException, RecognitionException, ParseException { - CommonTree tree = createAST(metadataTextInput); - fTreeParser.setTree(tree); - fTreeParser.generateFragment(); - } - - private static CommonTree createAST(Reader metadataTextInput) throws IOException, - RecognitionException { - /* Create an ANTLR reader */ - ANTLRReaderStream antlrStream; - antlrStream = new ANTLRReaderStream(metadataTextInput); - - /* Parse the metadata text and get the AST */ - CTFLexer ctfLexer = new CTFLexer(antlrStream); - CommonTokenStream tokens = new CommonTokenStream(ctfLexer); - CTFParser ctfParser = new CTFParser(tokens, false); - - parse_return pr = ctfParser.parse(); - return pr.getTree(); - } - - /** - * Determines whether the metadata file is packet-based by looking at the - * TSDL magic number. If it is packet-based, it also gives information about - * the endianness of the trace using the detectedByteOrder attribute. - * - * @param metadataFileChannel - * FileChannel of the metadata file. - * @return True if the metadata is packet-based. - * @throws CTFReaderException - */ - private boolean isPacketBased(FileChannel metadataFileChannel) - throws CTFReaderException { - /* - * Create a ByteBuffer to read the TSDL magic number (default is - * big-endian) - */ - ByteBuffer magicByteBuffer = ByteBuffer.allocate(Utils.TSDL_MAGIC_LEN); - - /* Read without changing file position */ - try { - metadataFileChannel.read(magicByteBuffer, 0); - } catch (IOException e) { - throw new CTFReaderException("Unable to read metadata file channel.", e); //$NON-NLS-1$ - } - - /* Get the first int from the file */ - int magic = magicByteBuffer.getInt(0); - - /* Check if it matches */ - if (Utils.TSDL_MAGIC == magic) { - detectedByteOrder = ByteOrder.BIG_ENDIAN; - return true; - } - - /* Try the same thing, but with little-endian */ - magicByteBuffer.order(ByteOrder.LITTLE_ENDIAN); - magic = magicByteBuffer.getInt(0); - - if (Utils.TSDL_MAGIC == magic) { - detectedByteOrder = ByteOrder.LITTLE_ENDIAN; - return true; - } - - return false; - } - - private String getMetadataPath() { - /* Path of metadata file = trace directory path + metadata filename */ - if (trace.getTraceDirectory() == null) { - return new String(); - } - return trace.getTraceDirectory().getPath() - + Utils.SEPARATOR + METADATA_FILENAME; - } - - /** - * Reads a metadata packet from the given metadata FileChannel, do some - * basic validation and append the text to the StringBuffer. - * - * @param metadataFileChannel - * Metadata FileChannel - * @param metadataText - * StringBuffer to which the metadata text will be appended. - * @return A structure describing the header of the metadata packet, or null - * if the end of the file is reached. - * @throws CTFReaderException - */ - private MetadataPacketHeader readMetadataPacket( - FileChannel metadataFileChannel, StringBuffer metadataText) - throws CTFReaderException { - /* Allocate a ByteBuffer for the header */ - ByteBuffer headerByteBuffer = ByteBuffer.allocate(METADATA_PACKET_HEADER_SIZE); - - /* Read the header */ - try { - int nbBytesRead = metadataFileChannel.read(headerByteBuffer); - - /* Return null if EOF */ - if (nbBytesRead < 0) { - return null; - } - - if (nbBytesRead != METADATA_PACKET_HEADER_SIZE) { - throw new CTFReaderException("Error reading the metadata header."); //$NON-NLS-1$ - } - - } catch (IOException e) { - throw new CTFReaderException("Error reading the metadata header.", e); //$NON-NLS-1$ - } - - /* Set ByteBuffer's position to 0 */ - headerByteBuffer.position(0); - - /* Use byte order that was detected with the magic number */ - headerByteBuffer.order(detectedByteOrder); - - MetadataPacketHeader header = new MetadataPacketHeader(headerByteBuffer); - - /* Check TSDL magic number */ - if (!header.isMagicValid()) { - throw new CTFReaderException("TSDL magic number does not match"); //$NON-NLS-1$ - } - - /* Check UUID */ - if (!trace.uuidIsSet()) { - trace.setUUID(header.getUuid()); - } else if (!trace.getUUID().equals(header.getUuid())) { - throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ - } - - /* Extract the text from the packet */ - int payloadSize = ((header.getContentSize() / 8) - METADATA_PACKET_HEADER_SIZE); - if (payloadSize < 0) { - throw new CTFReaderException("Invalid metadata packet payload size."); //$NON-NLS-1$ - } - int skipSize = (header.getPacketSize() - header.getContentSize()) / 8; - - /* Read the payload + the padding in a ByteBuffer */ - ByteBuffer payloadByteBuffer = ByteBuffer.allocateDirect(payloadSize - + skipSize); - try { - metadataFileChannel.read(payloadByteBuffer); - } catch (IOException e) { - throw new CTFReaderException("Error reading metadata packet payload.", e); //$NON-NLS-1$ - } - payloadByteBuffer.rewind(); - - /* Read only the payload from the ByteBuffer into a byte array */ - byte payloadByteArray[] = new byte[payloadByteBuffer.remaining()]; - payloadByteBuffer.get(payloadByteArray, 0, payloadSize); - - /* Convert the byte array to a String */ - String str = new String(payloadByteArray, 0, payloadSize); - - /* Append it to the existing metadata */ - metadataText.append(str); - - return header; - } - - private static class MetadataPacketHeader { - - private final int fMagic; - private final UUID fUuid; - private final int fChecksum; - private final int fContentSize; - private final int fPacketSize; - private final byte fCompressionScheme; - private final byte fEncryptionScheme; - private final byte fChecksumScheme; - private final byte fCtfMajorVersion; - private final byte fCtfMinorVersion; - - public MetadataPacketHeader(ByteBuffer headerByteBuffer) { - /* Read from the ByteBuffer */ - fMagic = headerByteBuffer.getInt(); - byte[] uuidBytes = new byte[16]; - headerByteBuffer.get(uuidBytes); - fUuid = Utils.makeUUID(uuidBytes); - fChecksum = headerByteBuffer.getInt(); - fContentSize = headerByteBuffer.getInt(); - fPacketSize = headerByteBuffer.getInt(); - fCompressionScheme = headerByteBuffer.get(); - fEncryptionScheme = headerByteBuffer.get(); - fChecksumScheme = headerByteBuffer.get(); - fCtfMajorVersion = headerByteBuffer.get(); - fCtfMinorVersion = headerByteBuffer.get(); - } - - public boolean isMagicValid() { - return fMagic == Utils.TSDL_MAGIC; - } - - public UUID getUuid() { - return fUuid; - } - - public int getContentSize() { - return fContentSize; - } - - public int getPacketSize() { - return fPacketSize; - } - - @Override - public String toString() { - /* Only for debugging, shouldn't be externalized */ - /* Therefore it cannot be covered by test cases */ - return "MetadataPacketHeader [magic=0x" //$NON-NLS-1$ - + Integer.toHexString(fMagic) + ", uuid=" //$NON-NLS-1$ - + fUuid.toString() + ", checksum=" + fChecksum //$NON-NLS-1$ - + ", contentSize=" + fContentSize + ", packetSize=" //$NON-NLS-1$ //$NON-NLS-2$ - + fPacketSize + ", compressionScheme=" + fCompressionScheme //$NON-NLS-1$ - + ", encryptionScheme=" + fEncryptionScheme //$NON-NLS-1$ - + ", checksumScheme=" + fChecksumScheme //$NON-NLS-1$ - + ", ctfMajorVersion=" + fCtfMajorVersion //$NON-NLS-1$ - + ", ctfMinorVersion=" + fCtfMinorVersion + ']'; //$NON-NLS-1$ - } - - } -} diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java deleted file mode 100644 index 72c1124124..0000000000 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Utils.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial API and implementation - * Contributors: Simon Marchi - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.ctf.core.trace; - -import java.util.UUID; - -import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; - -/** - * Various utilities. - * - * @version 1.0 - * @author Matthew Khouzam - * @author Simon Marchi - */ -public final class Utils { - - private Utils() { - } - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - /** - * CTF magic number. (sort of looks like CTF CTF CT) - */ - public static final int CTF_MAGIC = 0xC1FC1FC1; - - /** - * TSDL magic number. (sort of looks like TSDL LSDT) - */ - public static final int TSDL_MAGIC = 0x75D11D57; - - /** - * TSDL magic number length in bytes. - */ - public static final int TSDL_MAGIC_LEN = 4; - - /** - * Directory separator on the current platform. - */ - public static final String SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ - - /** - * Length in bytes of a UUID value. - */ - public static final int UUID_LEN = 16; - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /** - * Performs an unsigned long comparison on two unsigned long numbers. - * - * <strong> As Java does not support unsigned types and arithmetic, - * parameters are received encoded as a signed long (two-complement) but the - * operation is an unsigned comparator.</strong> - * - * @param left - * Left operand of the comparator. - * @param right - * Right operand of the comparator. - * @return -1 if left < right, 1 if left > right, 0 if left == right. - */ - public static int unsignedCompare(long left, long right) { - /* - * This method assumes that the arithmetic overflow on signed integer - * wrap on a circular domain (modulo arithmetic in two-complement), - * which is the defined behavior in Java. - * - * This idea is to rotate the domain by the length of the negative - * space, and then use the signed operator. - */ - final long a = left + Long.MIN_VALUE; - final long b = right + Long.MIN_VALUE; - if (a < b) { - return -1; - } else if (a > b) { - return 1; - } - return 0; - } - - /** - * Gets a UUID from an array defintion - * - * @param uuidDef - * the array defintions, must contain integer bytes - * @return the UUID - * @throws CTFReaderException - * if the definition contains less than 16 elements - * @since 3.1 - */ - public static UUID getUUIDfromDefinition(AbstractArrayDefinition uuidDef) throws CTFReaderException { - byte[] uuidArray = new byte[16]; - IDeclaration declaration = uuidDef.getDeclaration(); - if (!(declaration instanceof CompoundDeclaration)) { - throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$ - } - CompoundDeclaration uuidDec = (CompoundDeclaration) declaration; - - IDeclaration uuidElem = uuidDec.getElementType(); - if (!(uuidElem instanceof IntegerDeclaration)) { - throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$ - } - IntegerDeclaration intUuidElem = (IntegerDeclaration) uuidElem; - if (!intUuidElem.isUnsignedByte()) { - throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$ - } - return getUUID(uuidDef, uuidArray); - } - - private static UUID getUUID(AbstractArrayDefinition uuidDef, byte[] uuidArray) throws CTFReaderException { - for (int i = 0; i < uuidArray.length; i++) { - IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getDefinitions().get(i); - if (uuidByteDef == null) { - throw new CTFReaderException("UUID incomplete, only " + i + " bytes available"); //$NON-NLS-1$ //$NON-NLS-2$ - } - uuidArray[i] = (byte) uuidByteDef.getValue(); - } - - UUID uuid = Utils.makeUUID(uuidArray); - return uuid; - } - - /** - * Gets a UUID from an array defintion - * - * @param uuidDef - * the array defintions, must contain integer bytes - * @return the UUID - * @throws CTFReaderException - * if the definition contains less than 16 elements - * @since 3.1 - * @deprecated use - * {@link Utils#getUUIDfromDefinition(AbstractArrayDefinition uuidDef)} - */ - @Deprecated - public static UUID getUUIDfromDefinition(org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition uuidDef) throws CTFReaderException { - byte[] uuidArray = new byte[16]; - return getUUID(uuidDef, uuidArray); - } - - /** - * Creates a UUID object from an array of 16 bytes. - * - * @param bytes - * Array of 16 bytes. - * @return A UUID object. - */ - public static UUID makeUUID(byte bytes[]) { - long high = 0; - long low = 0; - - assert (bytes.length == Utils.UUID_LEN); - - for (int i = 0; i < 8; i++) { - low = (low << 8) | (bytes[i + 8] & 0xFF); - high = (high << 8) | (bytes[i] & 0xFF); - } - - UUID uuid = new UUID(high, low); - - return uuid; - } - -} |