From: Bernd Hufmann Date: Tue, 29 Nov 2016 22:36:11 +0000 (+0100) Subject: xml: support any aspects to be used in XML analysis X-Git-Url: http://git.efficios.com/?p=deliverable%2Ftracecompass.git;a=commitdiff_plain;h=c3f865bf35e28827a15601355e5814f076305c2c xml: support any aspects to be used in XML analysis Some traces have aspects to show special data in a column. With this commit it is possible to use any aspect in the XML anlysis. Change-Id: I9dedc910e9465ac94f82912dc9095e9d315b0882 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/86002 Reviewed-by: Hudson CI Tested-by: Jean-Christian Kouame Reviewed-by: Jean-Christian Kouame --- diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java index aa31e945d6..94ae688090 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java @@ -12,13 +12,13 @@ package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model; +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; +import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString; + import java.util.LinkedList; import java.util.List; import org.eclipse.jdt.annotation.Nullable; -import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString; -import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; - import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator; import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer; import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils; @@ -31,6 +31,7 @@ import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; import org.w3c.dom.Element; @@ -223,6 +224,8 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute { if (name == null) { throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$ } + + Object fieldValue = null; /* First, look for a field with the given name */ ITmfEventField field = event.getContent().getField(name); /* Field not found, see if it is a special case field */ @@ -234,10 +237,18 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute { if (cpu != null) { return getQuarkRelativeAndAdd(startQuark, cpu.toString()); } + return IXmlStateSystemContainer.ERROR_QUARK; + } + /* Search between the trace event aspects */ + for (ITmfEventAspect aspect : event.getTrace().getEventAspects()) { + if (aspect.getName().equals(fName)) { + fieldValue = aspect.resolve(event); + break; + } } - return IXmlStateSystemContainer.ERROR_QUARK; + } else { + fieldValue = field.getValue(); } - Object fieldValue = field.getValue(); if (fieldValue instanceof String) { String fieldString = (String) fieldValue; @@ -249,6 +260,7 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute { Integer fieldInterger = (Integer) fieldValue; quark = getQuarkRelativeAndAdd(startQuark, fieldInterger.toString()); } + return quark; } case QUERY: { diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java index 2f0360a7bb..c4ea951b96 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java @@ -30,6 +30,7 @@ import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; import org.w3c.dom.Element; @@ -297,9 +298,10 @@ public abstract class TmfXmlStateValue implements ITmfXmlStateValue { final ITmfEventField field = event.getContent().getField(fieldName); + Object fieldValue = null; + /* If the field does not exist, see if it's a special case */ if (field == null) { - if (fieldName.equalsIgnoreCase(TmfXmlStrings.CPU)) { /* A "CPU" field will return the CPU aspect if available */ Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), TmfCpuAspect.class, event); @@ -313,11 +315,20 @@ public abstract class TmfXmlStateValue implements ITmfXmlStateValue { */ return TmfStateValue.newValueLong(event.getTimestamp().getValue()); } - return value; + // This will allow to use any column as input + for (ITmfEventAspect aspect : event.getTrace().getEventAspects()) { + if (aspect.getName().equals(fieldName)) { + fieldValue = aspect.resolve(event); + break; + } + } + if (fieldValue == null) { + return value; + } + } else { + fieldValue = field.getValue(); } - Object fieldValue = field.getValue(); - /* * Try to find the right type. The type can be forced by * "forcedType" argument.