Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Saint-Cyr2019-07-29 15:15:19 -0400
committerGenevieve Bastien2019-07-31 10:03:32 -0400
commit308dd254befc1a772c1d7d20682e30700016ca6d (patch)
tree212ac0c44f6de23199783832ca8525527675eb43
parentd47b7c25eff71880d6ab7d98953c5937f35c11f6 (diff)
downloadorg.eclipse.tracecompass.incubator-308dd254befc1a772c1d7d20682e30700016ca6d.tar.gz
org.eclipse.tracecompass.incubator-308dd254befc1a772c1d7d20682e30700016ca6d.tar.xz
org.eclipse.tracecompass.incubator-308dd254befc1a772c1d7d20682e30700016ca6d.zip
scripting: Add a Trace module
The module has a method to get the currently active trace. This patch also adds a function to get an analysis module from a trace [Added] Scripting methods to get the active trace and trace analyses Change-Id: I690831816100e01c70ca19df5f25f532de2c825d Signed-off-by: Benjamin Saint-Cyr <benjamin.saint-cyr@polymtl.ca> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/146755 Tested-by: CI Bot Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org> Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/analysis/AnalysisModuleTest.java84
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.core/META-INF/MANIFEST.MF2
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.core/plugin.xml7
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/analysis/AnalysisScriptingModule.java28
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/TraceScriptingModule.java33
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/package-info.java19
6 files changed, 172 insertions, 1 deletions
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/analysis/AnalysisModuleTest.java b/analyses/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/analysis/AnalysisModuleTest.java
index d62ecc06..846ab89c 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/analysis/AnalysisModuleTest.java
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/analysis/AnalysisModuleTest.java
@@ -11,21 +11,29 @@ package org.eclipse.tracecompass.incubator.scripting.core.tests.analysis;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.incubator.scripting.core.analysis.AnalysisScriptingModule;
import org.eclipse.tracecompass.incubator.scripting.core.analysis.ScriptedAnalysis;
import org.eclipse.tracecompass.incubator.scripting.core.tests.stubs.ScriptingTestUtils;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
+import com.google.common.collect.Iterables;
+
/**
* Test the {@link AnalysisScriptingModule}'s specific objects and methods
*
@@ -67,4 +75,80 @@ public class AnalysisModuleTest {
}
}
+ /**
+ * Test the
+ * {@link AnalysisScriptingModule#getTraceAnalysis(ITmfTrace, String)}
+ * method
+ */
+ @Test
+ public void testGetAnalysis() {
+ AnalysisScriptingModule scriptModule = new AnalysisScriptingModule();
+
+ ITmfTrace trace = ScriptingTestUtils.getTrace();
+ TmfExperiment exp = null;
+ try {
+ Iterable<@NonNull IAnalysisModule> analysisModules = trace.getAnalysisModules();
+ assertTrue(Iterables.size(analysisModules) > 0);
+ // Map to save trace modules
+ Map<String, IAnalysisModule> traceModules = new HashMap<>();
+ for (IAnalysisModule module : analysisModules) {
+ // Get the module by ID
+ IAnalysisModule analysis = scriptModule.getTraceAnalysis(trace, module.getId());
+ assertEquals("Analysis by ID " + module.getId(), module, analysis);
+
+ // Get the module by name, don't assert equality, as some
+ // analysis may have the same name as others
+ analysis = scriptModule.getTraceAnalysis(trace, module.getName());
+ assertNotNull("Analysis by name " + module.getName(), analysis);
+
+ // Add the module to the map
+ traceModules.put(module.getId(), module);
+ }
+
+ // Add the trace to an experiment and make sure all those analyses
+ // are found
+ ITmfTrace[] traces = new ITmfTrace[] { trace };
+ exp = new TmfExperiment(ITmfEvent.class, "test-exp", traces,
+ TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
+ exp.traceOpened(new TmfTraceOpenedSignal(this, exp, null));
+
+ Iterable<@NonNull IAnalysisModule> experimentModules = exp.getAnalysisModules();
+ assertTrue(Iterables.size(experimentModules) > 0);
+ for (IAnalysisModule module : experimentModules) {
+ // Get the module by ID
+ IAnalysisModule analysis = scriptModule.getTraceAnalysis(exp, module.getId());
+ assertEquals("Experiment analysis by ID " + module.getId(), module, analysis);
+
+ // Get the module by name, don't assert equality, as some
+ // analysis may have the same name as others
+ analysis = scriptModule.getTraceAnalysis(exp, module.getName());
+ assertNotNull("Experiment analysis by name " + module.getName(), analysis);
+
+ // Remove this analysis from the trace's, as the experiment also
+ // has an analysis with this name, and it's the one that will be
+ // returned by the method
+ traceModules.remove(module.getId());
+ }
+
+ // Get the trace-only modules from the experiment
+ assertTrue(!traceModules.isEmpty());
+ for (IAnalysisModule module : traceModules.values()) {
+ // Get the module by ID
+ IAnalysisModule analysis = scriptModule.getTraceAnalysis(exp, module.getId());
+ assertEquals("Trace-only analysis by ID " + module.getId(), module, analysis);
+
+ // Get the module by name, don't assert equality, as some
+ // analysis may have the same name as others
+ analysis = scriptModule.getTraceAnalysis(exp, module.getName());
+ assertNotNull("Trace-only analysis by name " + module.getName(), analysis);
+ }
+
+ } finally {
+ trace.dispose();
+ if (exp != null) {
+ exp.dispose();
+ }
+ }
+ }
+
}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.core/META-INF/MANIFEST.MF b/analyses/org.eclipse.tracecompass.incubator.scripting.core/META-INF/MANIFEST.MF
index c043ebbb..4e214173 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.core/META-INF/MANIFEST.MF
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core/META-INF/MANIFEST.MF
@@ -15,7 +15,6 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ease,
org.eclipse.tracecompass.tmf.core,
org.eclipse.core.commands,
- org.eclipse.ui.workbench,
org.eclipse.jface,
org.eclipse.tracecompass.statesystem.core,
org.eclipse.tracecompass.analysis.os.linux.core,
@@ -27,6 +26,7 @@ Export-Package: org.eclipse.tracecompass.incubator.internal.scripting.core;x-fri
org.eclipse.tracecompass.incubator.scripting.core.analysis,
org.eclipse.tracecompass.incubator.scripting.core.data.provider,
org.eclipse.tracecompass.incubator.scripting.core.filters,
+ org.eclipse.tracecompass.incubator.scripting.core.trace,
org.eclipse.tracecompass.incubator.scripting.core.utils
Automatic-Module-Name: org.eclipse.tracecompass.incubator.scripting.core
Import-Package: com.google.common.collect,
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.core/plugin.xml b/analyses/org.eclipse.tracecompass.incubator.scripting.core/plugin.xml
index 80326b29..fdb29259 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.core/plugin.xml
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core/plugin.xml
@@ -31,6 +31,13 @@
name="Filters"
visible="true">
</module>
+ <module
+ category="org.eclipse.tracecompass.incubator.scripting.core.category"
+ class="org.eclipse.tracecompass.incubator.scripting.core.trace.TraceScriptingModule"
+ id="org.eclipse.tracecompass.incubator.scripting.core.trace"
+ name="Trace"
+ visible="true">
+ </module>
<category
id="org.eclipse.tracecompass.incubator.scripting.core.category"
name="TraceCompass">
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 f5555193..07d5bdcb 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
@@ -11,6 +11,7 @@ package org.eclipse.tracecompass.incubator.scripting.core.analysis;
import org.eclipse.ease.modules.WrapToScript;
import org.eclipse.jdt.annotation.Nullable;
+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;
@@ -85,4 +86,31 @@ public class AnalysisScriptingModule {
}
+ /**
+ * 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
+ * analyses cannot create state systems or anything else, but their results
+ * can be queried and visualized in a script.
+ * <p>
+ * The analyses can be queried by ID, or by name, ie the text that is
+ * displayed in the Trace Compass UI.
+ *
+ * @param trace
+ * The trace being analyzed.
+ * @param analysisName
+ * The analysis module name or ID to get.
+ * @return The module
+ */
+ @WrapToScript
+ public @Nullable IAnalysisModule getTraceAnalysis(ITmfTrace trace, String analysisName) {
+ for (ITmfTrace childTrace : TmfTraceManager.getTraceSetWithExperiment(trace)) {
+ for (IAnalysisModule module : childTrace.getAnalysisModules()) {
+ if (module.getName().equals(analysisName) || module.getId().equals(analysisName)) {
+ return module;
+ }
+ }
+ }
+ return null;
+ }
+
}
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
new file mode 100644
index 00000000..1b428c7a
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/TraceScriptingModule.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2019 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.incubator.scripting.core.trace;
+
+import org.eclipse.ease.modules.WrapToScript;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+
+/**
+ * Scripting modules to open and manipulate traces
+ *
+ * @author Benjamin Saint-Cyr
+ */
+public class TraceScriptingModule {
+
+ /**
+ * Get the currently active trace, ie the last trace opened in the UI
+ *
+ * @return The current trace or <code>null</code> if no trace is opened
+ */
+ @WrapToScript
+ public @Nullable ITmfTrace getActiveTrace() {
+ return TmfTraceManager.getInstance().getActiveTrace();
+ }
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/package-info.java b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/package-info.java
new file mode 100644
index 00000000..2512cad5
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/trace/package-info.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2019 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+/**
+ * <code>/TraceCompass/trace</code>: EASE scripting module and classes to open
+ * or import traces
+ *
+ * <pre>
+ * Load: <code>/TraceCompass/trace</code>
+ * Type: core
+ * </pre>
+ */
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.incubator.scripting.core.trace; \ No newline at end of file

Back to the top