Add support for enums in trace fields.
Add support for broken end timestamped traces. (experimental)
Add support for variant free id/timestamp pairings (non-lttng)
Add support for non-CPU based traces (dsp/gpu/fpga...)
Change-Id: I2e49f798ae5e2fefda0316631dbbb74609ba36aa
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/6951
/**
* 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.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class EnumDefinition extends Definition {
+public class EnumDefinition extends SimpleDatatypeDefinition {
// ------------------------------------------------------------------------
// Attributes
return value;
}
+ @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.
*/
- public long getIntegerValue() {
+ @Override
+ public Long getIntegerValue() {
return integerValue.getValue();
}
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class IntegerDefinition extends Definition {
+public class IntegerDefinition extends SimpleDatatypeDefinition {
// ------------------------------------------------------------------------
// Attributes
return declaration;
}
+
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.ctf.core.event.types.SimpleDatatypeDefinition#getLongValue()
+ */
+ @Override
+ public Long getIntegerValue() {
+ return getValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.ctf.core.event.types.SimpleDatatypeDefinition#getStringValue()
+ */
+ @Override
+ public String getStringValue() {
+ return this.toString();
+ }
+
@Override
public void read(BitBuffer input) {
final long longNegBit = 0x0000000080000000L;
--- /dev/null
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+/**
+ * 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 {
+
+ public SimpleDatatypeDefinition(IDefinitionScope definitionScope,
+ String fieldName) {
+ super(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;
+ }
+
+}
import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
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.IDefinitionScope;
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;
* Read CPU ID
*/
- Definition cpuiddef = getStreamPacketContextDef()
- .lookupDefinition("cpu_id"); //$NON-NLS-1$
- if (cpuiddef instanceof IntegerDefinition) {
- currentCpu = (int) ((IntegerDefinition) cpuiddef)
- .getValue();
+ if (this.getCurrentPacket().getTarget() != null) {
+ this.currentCpu = (int) this.getCurrentPacket()
+ .getTargetId();
}
/*
* Read number of lost events
*/
- Definition lostEventsdef = getStreamPacketContextDef()
- .lookupDefinition("events_discarded"); //$NON-NLS-1$
- if (cpuiddef instanceof IntegerDefinition) {
- int totalLostEvents = (int) ((IntegerDefinition) lostEventsdef)
- .getValue();
- lostEventsInThisPacket = totalLostEvents - lostEvents;
- lostEvents = totalLostEvents;
- currentPacket.setLostEvents(lostEventsInThisPacket);
- lostSoFar = 0;
- }
+
+ int totalLostEvents = (int) this.getCurrentPacket()
+ .getLostEvents();
+ lostEventsInThisPacket = totalLostEvents - lostEvents;
+ lostEvents = totalLostEvents;
+ currentPacket.setLostEvents(lostEventsInThisPacket);
+ lostSoFar = 0;
+
}
/*
* If there was a problem reading the trace
*/
public EventDefinition readNextEvent() throws CTFReaderException {
- /* WARNING: This is very LTTng-specific. */
+ /* WARNING: This is still LTTng-specific. */
Long eventID = null;
long timestamp = 0;
/*
* Check for an event id.
*/
- EnumDefinition idEnumDef = (EnumDefinition) sehd
+ SimpleDatatypeDefinition idDef = (SimpleDatatypeDefinition) sehd
.lookupDefinition("id"); //$NON-NLS-1$
- assert (idEnumDef != null);
-
- eventID = idEnumDef.getIntegerValue();
+ IntegerDefinition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$
+ eventID = idDef.getIntegerValue();
/*
* Check for the variant v.
*/
VariantDefinition variantDef = (VariantDefinition) sehd
.lookupDefinition("v"); //$NON-NLS-1$
- assert (variantDef != null);
+ if (variantDef != null) {
- /*
- * Get the variant current field
- */
- StructDefinition variantCurrentField = (StructDefinition) variantDef
- .getCurrentField();
- assert (variantCurrentField != null);
+ /*
+ * Get the variant current field
+ */
+ StructDefinition variantCurrentField = (StructDefinition) 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.
- */
- IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField
- .lookupDefinition("id"); //$NON-NLS-1$
- if (idIntegerDef != null) {
- eventID = idIntegerDef.getValue();
- }
+ /*
+ * Try to get the id field in the current field of the variant.
+ * If it is present, it overrides the previously read event id.
+ */
+ IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField
+ .lookupDefinition("id"); //$NON-NLS-1$
+ if (idIntegerDef != null) {
+ eventID = idIntegerDef.getValue();
+ }
+ /*
+ * Get the timestamp.
+ */
+ timestampDef = (IntegerDefinition) variantCurrentField
+ .lookupDefinition("timestamp"); //$NON-NLS-1$
- /*
- * Get the timestamp.
- */
- IntegerDefinition timestampDef = (IntegerDefinition) variantCurrentField
- .lookupDefinition("timestamp"); //$NON-NLS-1$
- assert (timestampDef != null);
+ }
/*
* Calculate the event timestamp.
private CTFTraceReader parent;
- @SuppressWarnings("unused")
- private final long prevIndex;
// ------------------------------------------------------------------------
// Constructors
* Get the iterator on the packet index.
*/
this.packetIndex = 0;
-
- this.prevIndex = 0;
/*
* Make first packet the current one.
*/
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
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.IDefinitionScope;
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.StructDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.Utils;
/**
* Gets the stream the streamInput wrapper is wrapping
+ *
* @return the stream the streamInput wrapper is wrapping
*/
public Stream getStream() {
/**
* the common streamInput Index
+ *
* @return the stream input Index
*/
public StreamInputPacketIndex getIndex() {
}
/**
- * Gets the filechannel of the streamInput. This is a limited Java ressource.
+ * Gets the filechannel of the streamInput. This is a limited Java
+ * ressource.
+ *
* @return the filechannel
*/
public FileChannel getFileChannel() {
/**
* Gets the filename of the streamInput file.
+ *
* @return the filename of the streaminput file.
*/
public String getFilename() {
}
/**
- * gets the last read timestamp of a stream. (this is not necessarily the last time in the stream.)
+ * 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() {
}
/**
- * Sets the last read timestamp of a stream. (this is not necessarily the last time in the stream.)
- * @param timestampEnd the last read timestamp
+ * 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) {
this.timestampEnd = timestampEnd;
*/
public void setupIndex() {
-
/*
* The BitBuffer to extract data from the StreamInput
*/
StructDefinition tracePacketHeaderDef,
StructDefinition streamPacketContextDef, BitBuffer bitBuffer)
throws CTFReaderException {
- @SuppressWarnings("unused")
- MappedByteBuffer bb = createPacketBitBuffer(fileSizeBytes,
+ @SuppressWarnings("unused")
+ MappedByteBuffer bb = createPacketBitBuffer(fileSizeBytes,
packetOffsetBytes, packetIndex, bitBuffer);
/*
/*
* Update the counting packet offset
*/
- packetOffsetBytes = computeNextOffset(packetIndex);
- return packetOffsetBytes;
+ return computeNextOffset(packetIndex);
}
/**
StreamInputPacketIndexEntry packetIndex) {
streamPacketContextDef.read(bitBuffer);
+ for (String field : streamPacketContextDef.getDeclaration()
+ .getFieldsList()) {
+ Definition 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 timestampBegin = (Long) packetIndex
+ .lookupAttribute("timestamp_begin"); //$NON-NLS-1$
+ Long timestampEnd = (Long) packetIndex.lookupAttribute("timestamp_end"); //$NON-NLS-1$
+ String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$
+ // LTTng Specific
+ Long CPU_ID = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$
/*
* Read the content size in bits
*/
- IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("content_size"); //$NON-NLS-1$
- if (contentSizeDef != null) {
- packetIndex.setContentSizeBits((int) contentSizeDef.getValue());
+ if (contentSize != null) {
+ packetIndex.setContentSizeBits(contentSize.intValue());
} else {
packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
}
/*
* Read the packet size in bits
*/
- IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("packet_size"); //$NON-NLS-1$
- if (packetSizeDef != null) {
- packetIndex.setPacketSizeBits((int) packetSizeDef.getValue());
+
+ if (packetSize != null) {
+ packetIndex.setPacketSizeBits(packetSize.intValue());
} else {
if (packetIndex.getContentSizeBits() != 0) {
packetIndex.setPacketSizeBits(packetIndex.getContentSizeBits());
/*
* Read the begin timestamp
*/
- IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
- if (timestampBeginDef != null) {
- packetIndex.setTimestampBegin(timestampBeginDef.getValue());
+
+ if (timestampBegin != null) {
+ packetIndex.setTimestampBegin(timestampBegin.longValue());
}
/*
* Read the end timestamp
*/
- IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("timestamp_end"); //$NON-NLS-1$
- if (timestampEndDef != null) {
- packetIndex.setTimestampEnd(timestampEndDef.getValue());
+ if (timestampEnd != null) {
+ if( timestampEnd == -1 ) {
+ timestampEnd = Long.MAX_VALUE;
+ }
+ packetIndex.setTimestampEnd(timestampEnd.longValue());
setTimestampEnd(packetIndex.getTimestampEnd());
}
+
+ if (device != null) {
+ packetIndex.setTarget(device);
+ }
+
+ if (CPU_ID != null) {
+ packetIndex.setTarget("CPU" + CPU_ID.toString()); //$NON-NLS-1$
+ }
}
/*
package org.eclipse.linuxtools.internal.ctf.core.trace;
+import java.util.HashMap;
+
/**
* <b><u>StreamInputPacketIndexEntry</u></b>
* <p>
*/
private long lostEvents = 0;
+ /**
+ * Which target is being traced
+ */
+ private String target ;
+ private long targetID;
+
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public void setLostEvents(long lostEvents) {
this.lostEvents = lostEvents;
}
+
+ private final HashMap<String, Object> attributes = new HashMap<String, Object>();
+ public void addAttribute(String field, Object value) {
+ attributes.put(field, value);
+ }
+ public Object lookupAttribute(String field){
+ return attributes.get(field);
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ this.targetID = Integer.parseInt(target.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
+ }
+
+ public long getTargetId(){
+ return targetID;
+ }
}
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
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.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
*/
protected CtfTmfEventField(String name) {
/* Strip the underscore */
- if ( name.startsWith("_") ) { //$NON-NLS-1$
+ if (name.startsWith("_")) { //$NON-NLS-1$
this.name = name.substring(1);
} else {
this.name = name;
int base = intDef.getDeclaration().getBase();
field = new CTFIntegerField(intDef.getValue(), fieldName, base);
+ } else if (fieldDef instanceof EnumDefinition) {
+ EnumDefinition enumDef = (EnumDefinition) fieldDef;
+ field = new CTFStringField(enumDef.getValue(), fieldName);
+
} else if (fieldDef instanceof StringDefinition) {
field = new CTFStringField(
((StringDefinition) fieldDef).getValue(), fieldName);
/* This is a an array of CTF Integers */
long[] values = new long[arrayDecl.getLength()];
for (int i = 0; i < arrayDecl.getLength(); i++) {
- values[i] = ((IntegerDefinition) arrayDef.getElem(i)).getValue();
+ values[i] = ((IntegerDefinition) arrayDef.getElem(i))
+ .getValue();
}
field = new CTFIntegerArrayField(values, fieldName);
}
/* Sequence of integers => CTFIntegerArrayField */
long[] values = new long[seqDef.getLength()];
for (int i = 0; i < seqDef.getLength(); i++) {
- values[i] = ((IntegerDefinition) seqDef.getElem(i)).getValue();
+ values[i] = ((IntegerDefinition) seqDef.getElem(i))
+ .getValue();
}
field = new CTFIntegerArrayField(values, fieldName);
}
/* Add other Sequence types here */
- } else if (fieldDef instanceof FloatDefinition){
+ } else if (fieldDef instanceof FloatDefinition) {
FloatDefinition floatDef = (FloatDefinition) fieldDef;
- field = new CTFFloatField( floatDef.getValue(), fieldName);
+ field = new CTFFloatField(floatDef.getValue(), fieldName);
}
return field;
switch (other.getFieldType()) {
case FIELDTYPE_INTEGER:
CTFIntegerField intOther = (CTFIntegerField) other;
- return new CTFIntegerField(intOther.getValue(), intOther.name, intOther.getBase());
+ return new CTFIntegerField(intOther.getValue(), intOther.name,
+ intOther.getBase());
case FIELDTYPE_STRING:
- return new CTFStringField(((CTFStringField) other).getValue(), other.name);
+ return new CTFStringField(((CTFStringField) other).getValue(),
+ other.name);
case FIELDTYPE_INTEGER_ARRAY:
- return new CTFIntegerArrayField(((CTFIntegerArrayField) other).getValue(), other.name);
+ return new CTFIntegerArrayField(
+ ((CTFIntegerArrayField) other).getValue(), other.name);
case FIELDTYPE_FLOAT:
- return new CTFFloatField(((CTFFloatField) other).getValue(), other.name);
+ return new CTFFloatField(((CTFFloatField) other).getValue(),
+ other.name);
default:
return null;
}
}
}
-
/**
* The CTF field implementation for integer fields.
*
}
}
-
/**
* The CTF field implementation for string fields
*
}
}
-
/**
* CTF field implementation for arrays of integers.
*
}
}
-
/**
* CTF field implementation for floats.
*
* @param name
* The name of this field
*/
- protected CTFFloatField(double value ,String name) {
+ protected CTFFloatField(double value, String name) {
super(name);
this.value = value;
}
}
@Override
- public String toString(){
+ public String toString() {
return name + '=' + value;
}
}
/* Handle the case where the trace is empty */
this.setStartTime(TmfTimestamp.BIG_BANG);
} else {
- this.setStartTime(ctx.getCurrentEvent().getTimestamp());
- this.setEndTime(ctx.getCurrentEvent().getTimestamp());
+ final ITmfTimestamp curTime = ctx.getCurrentEvent().getTimestamp();
+ this.setStartTime(curTime);
+ this.setEndTime(curTime);
}
} catch (final CTFReaderException e) {