read.
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
@Override
public void read(BitBuffer input) {
+ int align = (int) declaration.getAlignment();
+ int pos = input.position() + ((align-(input.position() % align))%align);
+ input.position(pos);
integerValue.read(input);
long val = integerValue.getValue();
@Override
public void read(BitBuffer input) {
+ int align = (int) declaration.getAlignment();
+ int pos = input.position() + ((align-(input.position() % align))%align);
+ input.position(pos);
boolean signed = declaration.isSigned();
int length = declaration.getLength();
long bits = 0;
private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>();
private final List<String> fieldsList = new LinkedList<String>();
- private long minAlign;
+ private long maxAlign;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- public StructDeclaration(long minAlign) {
- this.minAlign = minAlign;
+ public StructDeclaration(long align) {
+ this.maxAlign = Math.max(align, 1);
}
// ------------------------------------------------------------------------
// Getters/Setters/Predicates
// ------------------------------------------------------------------------
- public long getMinAlign() {
- return this.minAlign;
- }
-
- public void setMinAlign(long minAlign) {
- this.minAlign = minAlign;
+ public long getMaxAlign() {
+ return maxAlign;
}
public boolean hasField(String name) {
@Override
public long getAlignment() {
- return getMinAlign();
+ return this.maxAlign;
}
// ------------------------------------------------------------------------
// Operations
}
public void addField(String name, IDeclaration declaration) {
- // TODO: update the minAlign to be the max of minAlign and the align
- // value of the new field.
this.fields.put(name, declaration);
this.fieldsList.add(name);
+ maxAlign = Math.max(maxAlign, declaration.getAlignment());
+ if( maxAlign == 1 )
+ {
+ maxAlign =1;
+ }
}
@Override
package org.eclipse.linuxtools.ctf.core.event.types;
import java.util.HashMap;
+import java.util.List;
import java.util.ListIterator;
import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
@Override
public void read(BitBuffer input) {
- for (String fName : declaration.getFieldsList()) {
+ final int align = (int) declaration.getAlignment();
+ int pos = input.position() + ((align-(input.position() % align))%align);
+ input.position(pos);
+ final List<String> fieldList = declaration.getFieldsList();
+ for (String fName : fieldList) {
Definition def = definitions.get(fName);
assert (def != null);
-
def.read(input);
}
}
// ------------------------------------------------------------------------
private String tag = null;
- private long alignment;
+ final private long alignment = 1;
private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>();
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
public VariantDeclaration() {
+
}
// ------------------------------------------------------------------------
public void addField(String fieldTag, IDeclaration declaration) {
fields.put(fieldTag, declaration);
- alignment = Math.max(alignment, declaration.getAlignment());
}
@Override
*/
final long streamIndex = streamInputReader.seekIndex(index);
tempIndex = Math.max(tempIndex, streamIndex);
- tempTimestamp = Math.max(tempTimestamp,
- streamInputReader.getCurrentEvent().timestamp);
+ EventDefinition currentEvent = streamInputReader.getCurrentEvent();
+ /*
+ * Maybe we're at the beginning of a trace.
+ */
+ if( currentEvent == null ){
+ streamInputReader.readNextEvent();
+ currentEvent = streamInputReader.getCurrentEvent();
+ }
+ if( currentEvent != null ) {
+ tempTimestamp = Math.max(tempTimestamp,
+ currentEvent.timestamp);
+ } else {
+ /*
+ * probably beyond the last event
+ */
+ tempIndex = goToZero();
+ }
}
} catch (CTFReaderException e) {
* Important, if it failed, it's because it's not yet indexed, so we
* have to manually advance to the right value.
*/
- for (StreamInputReader streamInputReader : this.streamInputReaders) {
- /*
- * Seek the trace reader.
- */
- streamInputReader.seek(0);
- }
- tempIndex = 0;
+ tempIndex = goToZero();
}
for (StreamInputReader streamInputReader : this.streamInputReaders) {
/*
return hasMoreEvents();
}
+ /**
+ * Go to the first entry of a trace
+ * @return 0, the first index.
+ */
+ private long goToZero() {
+ long tempIndex;
+ for (StreamInputReader streamInputReader : this.streamInputReaders) {
+ /*
+ * Seek the trace reader.
+ */
+ streamInputReader.seek(0);
+ }
+ tempIndex = 0;
+ return tempIndex;
+ }
+
public StreamInputReader getTopStream() {
return this.prio.peek();
}
*/
public EventDefinition readNextEvent() throws CTFReaderException {
/* WARNING: This is very LTTng-specific. */
-
Long eventID = null;
long timestamp = 0;
+ StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long variable name
+ BitBuffer currentBitBuffer = getBitBuffer();
/*
* Read the stream event header.
*/
- if (getStreamEventHeaderDef() != null) {
- getStreamEventHeaderDef().read(getBitBuffer());
+
+ if (sehd != null) {
+ sehd.read(currentBitBuffer);
/*
* Check for an event id.
*/
- EnumDefinition idEnumDef = (EnumDefinition) getStreamEventHeaderDef().lookupDefinition("id"); //$NON-NLS-1$
+ EnumDefinition idEnumDef = (EnumDefinition) sehd.lookupDefinition("id"); //$NON-NLS-1$
assert (idEnumDef != null);
eventID = idEnumDef.getIntegerValue();
/*
* Check for the variant v.
*/
- VariantDefinition variantDef = (VariantDefinition) getStreamEventHeaderDef().lookupDefinition("v"); //$NON-NLS-1$
+ VariantDefinition variantDef = (VariantDefinition) sehd.lookupDefinition("v"); //$NON-NLS-1$
assert (variantDef != null);
/*
IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
if (idIntegerDef != null) {
eventID = idIntegerDef.getValue();
-
}
/*
* Read the stream event context.
*/
if (getStreamEventContextDef() != null) {
- getStreamEventContextDef().read(getBitBuffer());
+ getStreamEventContextDef().read(currentBitBuffer);
}
/*
* Read the event context.
*/
if (eventDef.context != null) {
- eventDef.context.read(getBitBuffer());
+ eventDef.context.read(currentBitBuffer);
}
/*
* Read the event fields.
*/
if (eventDef.fields != null) {
- int pos = getBitBuffer().position();
- int minAlign = (int) eventDef.fields.getDeclaration().getMinAlign();
- int offset = pos % minAlign;
- pos += (minAlign - offset)%minAlign;
- getBitBuffer().position(pos);
- eventDef.fields.read(getBitBuffer());
+ eventDef.fields.read(currentBitBuffer);
}
/*
throw new ParseException("struct " + structName //$NON-NLS-1$
+ " already defined."); //$NON-NLS-1$
}
-
/* Create the declaration */
structDeclaration = new StructDeclaration(structAlign);
/* Parse the body */
parseStructBody(structBody, structDeclaration);
- long maxFieldAlign = -1;
- for( IDeclaration field : structDeclaration.getFields().values())
- {
- maxFieldAlign = Math.max(maxFieldAlign, field.getAlignment());
- }
- structDeclaration.setMinAlign(maxFieldAlign);
/* If struct has name, add it to the current scope. */
if (hasName) {