From 45261b3b99f00c382fe194fc9da3d74dab61263a Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Wed, 15 Jul 2015 21:31:57 -0400 Subject: [PATCH] tmf.ctf: Accelerate ByteArrayDefintion parsing Make BADs no longer need to generate definitions uselessly. This patch yields a 15-50% acceleration in Synchronization benchmarks, a 5% acceleration in the Kernel Analysis benchmark, and an average event size reduction of 33%. Change-Id: Ie581abaecf1d8b188de9f1acc3010fe3f7a65d7a Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/52024 Reviewed-by: Hudson CI Reviewed-by: Patrick Tasse --- .../core/event/types/ByteArrayDefinition.java | 10 ++++++++++ .../tmf/ctf/core/event/CtfTmfEventField.java | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ByteArrayDefinition.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ByteArrayDefinition.java index abc0f334df..4964bfed45 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ByteArrayDefinition.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ByteArrayDefinition.java @@ -109,4 +109,14 @@ public final class ByteArrayDefinition extends AbstractArrayDefinition { b.append(']'); return checkNotNull(b.toString()); } + + /** + * Get a byte of the byte array + * @param index the index of the byte + * + * @return the byte + */ + public byte getByte(int index) { + return fContent[index]; + } } \ No newline at end of file diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java index b891bc1da2..d6a0bdd2d0 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/event/CtfTmfEventField.java @@ -21,7 +21,6 @@ import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; import org.eclipse.jdt.annotation.NonNull; @@ -37,6 +36,7 @@ import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition; import org.eclipse.tracecompass.ctf.core.event.types.StringDefinition; import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition; +import org.eclipse.tracecompass.internal.ctf.core.event.types.ByteArrayDefinition; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.event.TmfEventField; import org.eclipse.tracecompass.tmf.ctf.core.CtfEnumPair; @@ -130,8 +130,20 @@ public abstract class CtfTmfEventField extends TmfEventField { } CompoundDeclaration arrDecl = (CompoundDeclaration) decl; IDeclaration elemType = null; - Collection definitions = arrayDef.getDefinitions(); elemType = arrDecl.getElementType(); + if (arrayDef instanceof ByteArrayDefinition) { + ByteArrayDefinition byteArrayDefinition = (ByteArrayDefinition) arrayDef; + /* it's a CTFIntegerArrayField */ + int size = arrayDef.getLength(); + long[] values = new long[size]; + for (int i = 0; i < size; i++) { + values[i] = Byte.toUnsignedLong(byteArrayDefinition.getByte(i)); + } + field = new CTFIntegerArrayField(fieldName, values, + 16, + false); + + } if (elemType instanceof IntegerDeclaration) { /* * Array of integers => CTFIntegerArrayField, unless it's a @@ -144,7 +156,7 @@ public abstract class CtfTmfEventField extends TmfEventField { field = new CTFStringField(fieldName, arrayDef.toString()); } else { /* it's a CTFIntegerArrayField */ - int size = arrayDef.getDefinitions().size(); + int size = arrayDef.getLength(); long[] values = new long[size]; for (int i = 0; i < size; i++) { IDefinition elem = arrayDef.getDefinitions().get(i); @@ -162,6 +174,7 @@ public abstract class CtfTmfEventField extends TmfEventField { CtfTmfEventField[] elements = new CtfTmfEventField[arrayDef.getLength()]; /* Parse the elements of the array. */ int i = 0; + List definitions = arrayDef.getDefinitions(); for (IDefinition definition : definitions) { CtfTmfEventField curField = CtfTmfEventField.parseField( definition, fieldName + '[' + i + ']'); -- 2.34.1