diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/analysis/AnalysisScriptingModule.java b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/analysis/AnalysisScriptingModule.java index 3db87d904..3fbfe46fc 100644 --- a/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/analysis/AnalysisScriptingModule.java +++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/analysis/AnalysisScriptingModule.java @@ -13,6 +13,7 @@ import org.eclipse.ease.modules.WrapToScript; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.incubator.scripting.core.trace.TraceScriptingModule; import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; @@ -35,8 +36,9 @@ * provider with script-defined entries and arrows (javascript) *
  • A basic analysis building an * state system and showing its data in a time graph (javascript)
  • - *
  • Same basic analysis as before, - * building an state system and showing its data in a time graph, in python
  • + *
  • Same basic analysis as + * before, building a state system and showing its data in a time graph, in + * python
  • * * * @author Geneviève Bastien @@ -76,7 +78,11 @@ public class AnalysisScriptingModule { * The name of the field to fetch * @return The field value object, or null if the field is not * found + * @deprecated This method has been moved to the + * {@link TraceScriptingModule#getEventFieldValue(ITmfEvent, + * String)} class. */ + @Deprecated @WrapToScript public @Nullable Object getFieldValue(ITmfEvent event, String fieldName) { diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/TraceScriptingModule.java b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/TraceScriptingModule.java index b24b47928..e7816b0c9 100644 --- a/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/TraceScriptingModule.java +++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/TraceScriptingModule.java @@ -25,12 +25,14 @@ import org.eclipse.tracecompass.incubator.internal.scripting.core.trace.Messages; import org.eclipse.tracecompass.incubator.internal.scripting.core.trace.ScriptEventRequest; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; /** * Scripting modules to open and manipulate traces @@ -176,4 +178,30 @@ public Iterator getEventIterator(@Nullable ITmfTrace trace) { trace.sendRequest(scriptEventRequest); return scriptEventRequest.getEventIterator(); } + + /** + * A wrapper method to get the value of an event field. If the field itself + * does not exist, it will try to resolve an aspect from the trace the event + * is from. + * + * @param event + * The event for which to get the field + * @param fieldName + * The name of the field to fetch + * @return The field value object, or null if the field is not + * found + */ + @WrapToScript + public @Nullable Object getEventFieldValue(ITmfEvent event, String fieldName) { + + final ITmfEventField field = event.getContent().getField(fieldName); + + /* If the field does not exist, see if it's a special case */ + if (field == null) { + // This will allow to use any column as input + return TmfTraceUtils.resolveAspectOfNameForEvent(event.getTrace(), fieldName, event); + } + return field.getValue(); + + } }