From: Matthew Khouzam Date: Wed, 2 Dec 2015 20:41:59 +0000 (-0500) Subject: ctf: make SIPIE enums store both key and value X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=23ba30ce1a4ede4e2b10b3d50e2cf4b7b485f170;p=deliverable%2Ftracecompass.git ctf: make SIPIE enums store both key and value By adding the getStringValue and getIntegerValue, instead of getValue, we have more information available. This is useful for enums so we can look up the string name but also sort it easier. Change-Id: Icfa095a0a8c2b8924809c389dbfe53055c3b63be Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/61814 Reviewed-by: Hudson CI Reviewed-by: Francis Giraldeau Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse --- diff --git a/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java b/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java index fd33e77c60..f1677c7268 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java +++ b/ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java @@ -84,7 +84,9 @@ public class CTFStreamInputPacketIndexEntryTest { sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); sd.addField("load_factor", new FloatDeclaration(24, 8, ByteOrder.nativeOrder(), 8)); sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); - sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); + final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + declaration.add(-100, 100, ""); + sd.addField("Enum", declaration); BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); bb.getByteBuffer().putInt(100); bb.getByteBuffer().putInt(200); @@ -112,7 +114,9 @@ public class CTFStreamInputPacketIndexEntryTest { sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); - sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); + final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + declaration.add(-100, 100, ""); + sd.addField("Enum", declaration); BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); bb.getByteBuffer().putInt(100); bb.getByteBuffer().putInt(200); @@ -140,7 +144,9 @@ public class CTFStreamInputPacketIndexEntryTest { sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); sd.addField("packet_size", IntegerDeclaration.INT_32B_DECL); sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); - sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); + final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + declaration.add(-100, 100, ""); + sd.addField("Enum", declaration); sd.addField("intruder", new StructDeclaration(8)); BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); bb.getByteBuffer().putInt(100); @@ -170,7 +176,9 @@ public class CTFStreamInputPacketIndexEntryTest { StructDeclaration sd = new StructDeclaration(8); sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); - sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); + final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + declaration.add(-100, 100, ""); + sd.addField("Enum", declaration); BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); bb.getByteBuffer().putInt(0); bb.getByteBuffer().put(("Test").getBytes()); @@ -195,7 +203,9 @@ public class CTFStreamInputPacketIndexEntryTest { sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); sd.addField("device", StringDeclaration.getStringDeclaration(Encoding.ASCII)); - sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); + final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + declaration.add(-100, 100, ""); + sd.addField("Enum", declaration); BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); bb.getByteBuffer().putInt(-1); bb.getByteBuffer().putInt(0); diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndexEntry.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndexEntry.java index ade605afe5..64bb804615 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndexEntry.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndexEntry.java @@ -12,11 +12,13 @@ package org.eclipse.tracecompass.internal.ctf.core.trace; +import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.tracecompass.common.core.NonNullUtils; import org.eclipse.tracecompass.ctf.core.CTFStrings; import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition; import org.eclipse.tracecompass.ctf.core.event.types.FloatDefinition; @@ -101,7 +103,7 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor { * @param fileSizeBytes * number of bytes in a file * - * TODO: Remove + * TODO: Remove */ public StreamInputPacketIndexEntry(long dataOffsetBits, long fileSizeBytes) { @@ -129,7 +131,7 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor { * @param lostSoFar * number of lost events so far * - * TODO: Remove + * TODO: Remove */ public StreamInputPacketIndexEntry(long dataOffsetBits, StructDefinition streamPacketContextDef, long fileSizeBytes, long lostSoFar) { this(dataOffsetBits, streamPacketContextDef, fileSizeBytes, lostSoFar, dataOffsetBits); @@ -158,7 +160,10 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor { } else if (id instanceof FloatDefinition) { fAttributes.put(field, ((FloatDefinition) id).getValue()); } else if (id instanceof EnumDefinition) { - fAttributes.put(field, ((EnumDefinition) id).getValue()); + final EnumDefinition enumDec = (EnumDefinition) id; + fAttributes.put(field, new AbstractMap.SimpleImmutableEntry<>( + NonNullUtils.checkNotNull(enumDec.getStringValue()), + NonNullUtils.checkNotNull(enumDec.getIntegerValue()))); } else if (id instanceof StringDefinition) { fAttributes.put(field, ((StringDefinition) id).getValue()); }