Skip to content

Commit

Permalink
scripting: Remove AnalysisScriptingModule deprecations
Browse files Browse the repository at this point in the history
Add use of the existing getActiveTrace API to replace the hereby removed
(deprecated) getAnalysis. This is to be able to continue testing with a
default active (test) trace, through HeadlessScriptExecutionTest. Hence
slightly adapt testAnalysis.{js,py}, accordingly. Do the same in the
documentation code samples and files.

Adapt the related files also for the getFieldValue replacement, namely
getEventFieldValue in the reused Trace module.

Long deprecated; since commits 346e798, 632d834 and 8b2cb50.

Slightly reformat, based on Eclipse, while being there. Do the same for
HeadlessScriptExecutionTest since used to test this change, even if not
touched per se. Slightly fix related javadoc in AnalysisScriptingModule.

[Removed] AnalysisScriptingModule#getAnalysis
[Removed] AnalysisScriptingModule#getFieldValue

Change-Id: I99288575c54ef3096e8c3fcc005c07b367834a4c
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/193694
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
marco-miller committed May 30, 2022
1 parent a7ab6bc commit 79ff90d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 84 deletions.
Expand Up @@ -155,10 +155,14 @@ Here's an example javascript script for Trace Compass. It is the equivalent of '
// load Trace Compass modules
loadModule('/TraceCompass/Analysis');
loadModule('/TraceCompass/DataProvider');
loadModule('/TraceCompass/Trace');
loadModule('/TraceCompass/View');

// Create an analysis named activetid.js.
var analysis = getAnalysis("activetid.js");
// Get the active trace
var trace = getActiveTrace();

// Create an analysis named activetid.js
var analysis = createScriptedAnalysis(trace, "activetid.js");

if (analysis == null) {
print("Trace is null");
Expand All @@ -182,8 +186,8 @@ function runAnalysis() {
// Do something when the event is a sched_switch
if (event.getName() == "sched_switch") {
// This function is a wrapper to get the value of field CPU in the event, or return null if the field is not present
cpu = getFieldValue(event, "CPU");
tid = getFieldValue(event, "next_tid");
cpu = getEventFieldValue(event, "CPU");
tid = getEventFieldValue(event, "next_tid");
if ((cpu != null) && (tid != null)) {
// Write the tid to the state system, for the attribute corresponding to the cpu
quark = ss.getQuarkAbsoluteAndAdd(cpu);
Expand Down
Expand Up @@ -22,8 +22,8 @@
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

/**
* Test the {@link ScriptExecutionHelper} class
Expand Down Expand Up @@ -96,5 +96,4 @@ public void testPython() {
Object result = ScriptExecutionHelper.executeScript(String.valueOf(path.toOSString()));
assertEquals(36, result);
}

}
Expand Up @@ -10,9 +10,13 @@

// load Trace Compass modules
loadModule('/TraceCompass/Analysis')
loadModule('/TraceCompass/Trace')

// Create an analysis named activetid.js.
var analysis = getAnalysis("activetid.js")
// Get the active trace
var trace = getActiveTrace()

// Create an analysis named activetid.js
var analysis = createScriptedAnalysis(trace, "activetid.js")

if (analysis == null) {
print("Trace is null")
Expand Down
Expand Up @@ -10,9 +10,13 @@

# load Trace Compass modules
loadModule('/TraceCompass/Analysis')
loadModule('/TraceCompass/Trace')

# Get the active trace
trace = getActiveTrace()

# Create an analysis for this script
analysis = getAnalysis("activetid_python.js")
analysis = createScriptedAnalysis(trace, "activetid_python.js")

if analysis is None:
print("Trace is null")
Expand Down
Expand Up @@ -15,13 +15,9 @@

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;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;

/**
* Provide an API to create an analysis. Using an analysis links the outputs of
Expand All @@ -48,58 +44,6 @@
*/
public class AnalysisScriptingModule {

/**
* Create an analysis with the given name. It will be associated with the
* currently active trace. If there is no active trace, it will return
* <code>null</code>.
*
* @param name
* The name of the analysis
* @return The new analysis, for the active trace, or <code>null</code> if
* there is no active trace.
* @deprecated Use {@link #createScriptedAnalysis(ITmfTrace, String)}
* instead
*/
@WrapToScript
@Deprecated
public @Nullable ScriptedAnalysis getAnalysis(String name) {
ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
if (activeTrace == null) {
return null;
}
return new ScriptedAnalysis(activeTrace, name);
}

/**
* 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 <code>null</code> 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) {

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();

}

/**
* A wrapper method to get a specified analysis of a trace. It returns an
* existing analysis, whether builtin or data-driven, for the trace. These
Expand All @@ -109,6 +53,7 @@ public class AnalysisScriptingModule {
* The analyses can be queried by ID, or by name, ie the text that is
* displayed in the Trace Compass UI.
* </p>
*
* @param trace
* The trace being analyzed.
* @param analysisName
Expand Down Expand Up @@ -137,11 +82,10 @@ public class AnalysisScriptingModule {
* The name of the analysis to create. If backends like state
* systems are saved by this analysis, this name will be used to
* retrieve the previous data.
* @return The module
* @return The new analysis for this trace.
*/
@WrapToScript
public ScriptedAnalysis createScriptedAnalysis(@Nullable ITmfTrace trace, String analysisName) {
return new ScriptedAnalysis(Objects.requireNonNull(trace, "Trace should not be null"), analysisName); //$NON-NLS-1$
}

}
Expand Up @@ -13,10 +13,14 @@
// load Trace Compass modules
loadModule('/TraceCompass/Analysis');
loadModule('/TraceCompass/DataProvider');
loadModule('/TraceCompass/Trace');
loadModule('/TraceCompass/View');

// Create an analysis named activetid.js.
var analysis = getAnalysis("activetid.js");
// Get the active trace
var trace = getActiveTrace();

// Create an analysis named activetid.js
var analysis = createScriptedAnalysis(trace, "activetid.js");

if (analysis == null) {
print("Trace is null");
Expand All @@ -40,8 +44,8 @@ function runAnalysis() {
// Do something when the event is a sched_switch
if (event.getName() == "sched_switch") {
// This function is a wrapper to get the value of field CPU in the event, or return null if the field is not present
cpu = getFieldValue(event, "CPU");
tid = getFieldValue(event, "next_tid");
cpu = getEventFieldValue(event, "CPU");
tid = getEventFieldValue(event, "next_tid");
if ((cpu != null) && (tid != null)) {
// Write the tid to the state system, for the attribute corresponding to the cpu
quark = ss.getQuarkAbsoluteAndAdd(cpu);
Expand Down
Expand Up @@ -12,13 +12,17 @@

# load proper Trace Compass modules
loadModule('/TraceCompass/Analysis');
loadModule('/TraceCompass/Trace');
loadModule('/TraceCompass/View');
loadModule('/TraceCompass/DataProvider');

from py4j.java_gateway import JavaClass

# Get the active trace
trace = getActiveTrace()

# Create an analysis for this script
analysis = getAnalysis("activetid_python.js")
analysis = createScriptedAnalysis(trace, "activetid_python.js")

if analysis is None:
print("Trace is null")
Expand Down Expand Up @@ -51,8 +55,8 @@ def runAnalysis():
# Do something when the event is a sched_switch
if event.getName() == "sched_switch":
# This function is a wrapper to get the value of field CPU in the event, or return null if the field is not present
cpu = getFieldValue(event, "CPU")
tid = getFieldValue(event, "next_tid")
cpu = getEventFieldValue(event, "CPU")
tid = getEventFieldValue(event, "next_tid")
if (not(cpu is None) and not(tid is None)):
# Write the tid to the state system, for the attribute corresponding to the cpu
quark = ss.getQuarkAbsoluteAndAdd(strToVarargs(str(cpu)))
Expand Down
Expand Up @@ -13,11 +13,15 @@
// load Trace Compass modules
loadModule('/TraceCompass/Analysis');
loadModule('/TraceCompass/DataProvider');
loadModule('/TraceCompass/Trace');
loadModule('/TraceCompass/View');
loadModule('/TraceCompass/Utils');

// Create an analysis named mpiring.js.
var analysis = getAnalysis("mpiring.js");
// Get the active trace
var trace = getActiveTrace();

// Create an analysis named activetid.js
var analysis = createScriptedAnalysis(trace, "activetid.js");

if (analysis == null) {
print("Trace is null");
Expand Down Expand Up @@ -48,15 +52,15 @@ function runAnalysis() {
name = event.getName();
if (name == "mpi:mpi_init_exit") {
// This function is a wrapper to get the value of field CPU in the event, or return null if the field is not present
resourceId = getFieldValue(event, "res");
tid = getFieldValue(event, "tid");
resourceId = getEventFieldValue(event, "res");
tid = getEventFieldValue(event, "tid");
if ((resourceId != null) && (tid != null)) {
// Save the association between tid and resource
tidToResMap[tid] = resourceId;
}
} else if (name == "mpi:mpi_recv_entry") {
// First get the current resource from its tid
tid = getFieldValue(event, "tid");
tid = getEventFieldValue(event, "tid");
if (tid != null) {
resourceId = tidToResMap[tid];
if (resourceId != null) {
Expand All @@ -66,7 +70,7 @@ function runAnalysis() {
}
}
} else if (name == "mpi:mpi_recv_exit") {
tid = getFieldValue(event, "tid");
tid = getEventFieldValue(event, "tid");
if (tid != null) {
resourceId = tidToResMap[tid];
if (resourceId != null) {
Expand All @@ -75,7 +79,7 @@ function runAnalysis() {
ss.removeAttribute(event.getTimestamp().toNanos(), quark);
}
// We received a message, see if we can close a pending arrow
source = getFieldValue(event, "source");
source = getEventFieldValue(event, "source");

if (source != null) {
pending = pendingArrows[resourceId];
Expand All @@ -89,7 +93,7 @@ function runAnalysis() {
}

} else if (name == "mpi:mpi_send_entry") {
tid = getFieldValue(event, "tid");
tid = getEventFieldValue(event, "tid");
if (tid != null) {
resourceId = tidToResMap[tid];
if (resourceId != null) {
Expand All @@ -98,13 +102,13 @@ function runAnalysis() {
ss.modifyAttribute(event.getTimestamp().toNanos(), "Sending message", quark);
}
// Prepare the start of an arrow
dest = getFieldValue(event, "dest");
dest = getEventFieldValue(event, "dest");
if (dest != null) {
pendingArrows[dest] = {"time" : event.getTimestamp().toNanos(), "source" : resourceId, "dest" : dest};
}
}
} else if (name == "mpi:mpi_send_exit") {
tid = getFieldValue(event, "tid");
tid = getEventFieldValue(event, "tid");
if (tid != null) {
resourceId = tidToResMap[tid];
if (resourceId != null) {
Expand Down

0 comments on commit 79ff90d

Please sign in to comment.