aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2012-04-23 17:55:39 (EDT)
committerMatthew Khouzam2012-05-01 09:47:44 (EDT)
commitb9634371e98806aaa4576c967ae23622bdae3d07 (patch)
tree252cc7a76a48ba958963fbdc56feb28ba0bd9102
parentf4ecc41d065ccdd894bf815d854836313cb3f0a5 (diff)
downloadorg.eclipse.linuxtools-b9634371e98806aaa4576c967ae23622bdae3d07.zip
org.eclipse.linuxtools-b9634371e98806aaa4576c967ae23622bdae3d07.tar.gz
org.eclipse.linuxtools-b9634371e98806aaa4576c967ae23622bdae3d07.tar.bz2
Fix alignment issue. Now traces using more than one alignment can be
read. Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java3
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java3
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java23
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java8
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java4
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java43
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java24
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java7
8 files changed, 69 insertions, 46 deletions
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
index e782419..308b05a 100644
--- 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
@@ -67,6 +67,9 @@ public class EnumDefinition extends Definition {
@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();
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
index 6ac0d93..499c7fd 100644
--- 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
@@ -61,6 +61,9 @@ public class IntegerDefinition extends Definition {
@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;
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
index 2f0ef53..271a3fb 100644
--- 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
@@ -27,26 +27,22 @@ public class StructDeclaration implements IDeclaration {
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) {
@@ -63,7 +59,7 @@ public class StructDeclaration implements IDeclaration {
@Override
public long getAlignment() {
- return getMinAlign();
+ return this.maxAlign;
}
// ------------------------------------------------------------------------
// Operations
@@ -76,10 +72,13 @@ public class StructDeclaration implements IDeclaration {
}
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
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
index e29a6d0..b5d8210 100644
--- 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
@@ -13,6 +13,7 @@
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;
@@ -71,10 +72,13 @@ public class StructDefinition extends Definition implements IDefinitionScope {
@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);
}
}
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
index c0338cf..6592edd 100644
--- 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
@@ -24,7 +24,7 @@ public class VariantDeclaration implements IDeclaration {
// ------------------------------------------------------------------------
private String tag = null;
- private long alignment;
+ final private long alignment = 1;
private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>();
// ------------------------------------------------------------------------
@@ -32,6 +32,7 @@ public class VariantDeclaration implements IDeclaration {
// ------------------------------------------------------------------------
public VariantDeclaration() {
+
}
// ------------------------------------------------------------------------
@@ -74,7 +75,6 @@ public class VariantDeclaration implements IDeclaration {
public void addField(String fieldTag, IDeclaration declaration) {
fields.put(fieldTag, declaration);
- alignment = Math.max(alignment, declaration.getAlignment());
}
@Override
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
index 104bc6e..59d80c7 100644
--- 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
@@ -353,8 +353,23 @@ public class CTFTraceReader {
*/
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) {
@@ -362,13 +377,7 @@ public class CTFTraceReader {
* 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) {
/*
@@ -400,6 +409,22 @@ public class CTFTraceReader {
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();
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
index 9b4b2cb..debc335 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
@@ -289,20 +289,22 @@ class StreamInputPacketReader implements IDefinitionScope {
*/
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();
@@ -310,7 +312,7 @@ class StreamInputPacketReader implements IDefinitionScope {
/*
* 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);
/*
@@ -326,7 +328,6 @@ class StreamInputPacketReader implements IDefinitionScope {
IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
if (idIntegerDef != null) {
eventID = idIntegerDef.getValue();
-
}
/*
@@ -345,7 +346,7 @@ class StreamInputPacketReader implements IDefinitionScope {
* Read the stream event context.
*/
if (getStreamEventContextDef() != null) {
- getStreamEventContextDef().read(getBitBuffer());
+ getStreamEventContextDef().read(currentBitBuffer);
}
/*
@@ -360,19 +361,14 @@ class StreamInputPacketReader implements IDefinitionScope {
* 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);
}
/*
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
index 7e30719..1380de4 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
@@ -1545,18 +1545,11 @@ public class IOStructGen {
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) {