Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeneviève Bastien2014-05-08 22:04:53 -0400
committerAlexandre Montplaisir2014-05-24 01:53:13 -0400
commit5d55376fe1a49a415bb27a510459455bffb2509b (patch)
tree237a7d754bf254c5b0e17d882b1005358c07cb9a
parenta5ac941bb768a872879310e8bef82a5eb2ec0346 (diff)
downloadorg.eclipse.linuxtools-5d55376fe1a49a415bb27a510459455bffb2509b.tar.gz
org.eclipse.linuxtools-5d55376fe1a49a415bb27a510459455bffb2509b.tar.xz
org.eclipse.linuxtools-5d55376fe1a49a415bb27a510459455bffb2509b.zip
TMF: Validate if an analysis can be executed using the requirements
Change-Id: If4b51af84c4fc3dc7541629b69e950b0cc54cb00 Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/26294 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/analysis/LttngKernelAnalysisTest.java16
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/analysis/LttngKernelAnalysisModule.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/Messages.java3
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java19
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java60
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/messages.properties1
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java2
8 files changed, 105 insertions, 10 deletions
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/analysis/LttngKernelAnalysisTest.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/analysis/LttngKernelAnalysisTest.java
index 4e6e5919cd..d49c8e8da1 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/analysis/LttngKernelAnalysisTest.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/analysis/LttngKernelAnalysisTest.java
@@ -31,6 +31,7 @@ import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestHelper;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
import org.junit.After;
import org.junit.Before;
@@ -92,6 +93,21 @@ public class LttngKernelAnalysisTest {
}
/**
+ * Test the canExecute method on valid and invalid traces
+ */
+ @Test
+ public void testCanExecute() {
+ /* Test with a valid kernel trace */
+ assertTrue(fKernelAnalysisModule.canExecute(fTrace));
+
+ /* Test with a CTF trace that does not have required events */
+ assumeTrue(CtfTmfTestTrace.CYG_PROFILE.exists());
+ try (CtfTmfTrace trace = CtfTmfTestTrace.CYG_PROFILE.getTrace();) {
+ assertFalse(fKernelAnalysisModule.canExecute(trace));
+ }
+ }
+
+ /**
* Test for {@link LttngKernelAnalysisModule#getAnalysisRequirements()}
*/
@Test
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/analysis/LttngKernelAnalysisModule.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/analysis/LttngKernelAnalysisModule.java
index 0e2beaf01f..e3e0bfb6fb 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/analysis/LttngKernelAnalysisModule.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/analysis/LttngKernelAnalysisModule.java
@@ -41,6 +41,7 @@ public class LttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
/** The ID of this analysis module */
public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.analysis"; //$NON-NLS-1$
+ /* TODO: Are all those mandatory events really mandatory or should some of them be optional? */
private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of(
LttngStrings.EXIT_SYSCALL,
LttngStrings.IRQ_HANDLER_ENTRY,
@@ -54,11 +55,15 @@ public class LttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
LttngStrings.SCHED_PROCESS_FREE,
LttngStrings.STATEDUMP_PROCESS_STATE,
LttngStrings.SCHED_WAKEUP,
- LttngStrings.SCHED_WAKEUP_NEW,
+ LttngStrings.SCHED_WAKEUP_NEW
+ );
+
+ private static final ImmutableSet<String> OPTIONAL_EVENTS = ImmutableSet.of(
/* Add the prefix for syscalls */
LttngStrings.SYSCALL_PREFIX
);
+
/** The requirements as an immutable set */
private static final ImmutableSet<TmfAnalysisRequirement> REQUIREMENTS;
@@ -67,7 +72,10 @@ public class LttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
TmfAnalysisRequirement domainReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN);
domainReq.addValue(SessionConfigStrings.CONFIG_DOMAIN_TYPE_KERNEL, ValuePriorityLevel.MANDATORY);
- REQUIREMENTS = ImmutableSet.of(domainReq, new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_EVENT, REQUIRED_EVENTS, ValuePriorityLevel.MANDATORY));
+ TmfAnalysisRequirement eventReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_EVENT, REQUIRED_EVENTS, ValuePriorityLevel.MANDATORY);
+ eventReq.addValues(OPTIONAL_EVENTS, ValuePriorityLevel.OPTIONAL);
+
+ REQUIREMENTS = ImmutableSet.of(domainReq, eventReq);
}
@Override
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java
index a2c1377b16..3e30dc9f71 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java
@@ -142,7 +142,7 @@ public interface IAnalysisModule extends ITmfComponent, IAnalysisRequirementProv
* The trace to analyze
* @return Whether the analysis can be executed
*/
- boolean canExecute(ITmfTrace trace);
+ boolean canExecute(@NonNull ITmfTrace trace);
/**
* Schedule the execution of the analysis. If the trace has been set and is
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/Messages.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/Messages.java
index 5b57833aec..fb8e1eebb2 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/Messages.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/Messages.java
@@ -40,6 +40,9 @@ public class Messages extends NLS {
/** Parameter is invalid */
public static String TmfAbstractAnalysisModule_InvalidParameter;
+ /** The trace to set was null */
+ public static String TmfAbstractAnalysisModule_NullTrace;
+
/** Running analysis */
public static String TmfAbstractAnalysisModule_RunningAnalysis;
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java
index f0403d7c9a..6ac0f8153f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java
@@ -100,6 +100,9 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
@Override
public void setTrace(ITmfTrace trace) throws TmfAnalysisException {
+ if (trace == null) {
+ throw new TmfAnalysisException(Messages.TmfAbstractAnalysisModule_NullTrace);
+ }
if (fTrace != null) {
throw new TmfAnalysisException(NLS.bind(Messages.TmfAbstractAnalysisModule_TraceSetMoreThanOnce, getName()));
}
@@ -108,6 +111,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
if (!canExecute(trace)) {
throw new TmfAnalysisException(NLS.bind(Messages.TmfAbstractAnalysisModule_AnalysisCannotExecute, getName()));
}
+
fTrace = trace;
/* Get the parameter providers for this trace */
fParameterProviders = TmfAnalysisManager.getParameterProviders(this, fTrace);
@@ -182,7 +186,12 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
}
@Override
- public boolean canExecute(ITmfTrace trace) {
+ public boolean canExecute(@NonNull ITmfTrace trace) {
+ for (TmfAnalysisRequirement requirement : getAnalysisRequirements()) {
+ if (!requirement.isFulfilled(trace)) {
+ return false;
+ }
+ }
return true;
}
@@ -251,7 +260,7 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
cancel();
}
- private void execute() {
+ private void execute(@NonNull final ITmfTrace trace) {
/*
* TODO: The analysis in a job should be done at the analysis manager
@@ -272,7 +281,6 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
fStarted = true;
}
- final ITmfTrace trace = fTrace;
/*
* Actual analysis will be run on a separate thread
*/
@@ -311,10 +319,11 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
@Override
public IStatus schedule() {
- if (fTrace == null) {
+ final ITmfTrace trace = fTrace;
+ if (trace == null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, String.format("No trace specified for analysis %s", getName())); //$NON-NLS-1$
}
- execute();
+ execute(trace);
return Status.OK_STATUS;
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java
index 0809b51922..9397b2469d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java
@@ -13,11 +13,17 @@
package org.eclipse.linuxtools.tmf.core.analysis;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.HashMap;
+import java.util.Map.Entry;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
+import org.eclipse.linuxtools.tmf.core.trace.TmfEventTypeCollectionHelper;
+
/**
* Class that contains all the values associated with a type needed by an
* analysis in order to execute. Each value is peered with a level that
@@ -41,6 +47,11 @@ import java.util.Set;
*/
public class TmfAnalysisRequirement {
+ /**
+ * String for requirement type 'event', that can be used by analysis
+ */
+ public static final String TYPE_EVENT = "event"; //$NON-NLS-1$
+
private final String fType;
private final Map<String, ValuePriorityLevel> fValues = new HashMap<>();
private final Set<String> fInformation = new HashSet<>();
@@ -210,6 +221,26 @@ public class TmfAnalysisRequirement {
}
/**
+ * Gets all the values associated with the requirement with a given priority
+ * level.
+ *
+ * @param level
+ * The desired level
+ * @return Set containing the values with the given priority level
+ */
+ public Set<String> getValues(ValuePriorityLevel level) {
+ synchronized (fValues) {
+ Set<String> values = new HashSet<>();
+ for (Entry<String, ValuePriorityLevel> entry : fValues.entrySet()) {
+ if (entry.getValue() == level) {
+ values.add(entry.getKey());
+ }
+ }
+ return values;
+ }
+ }
+
+ /**
* Gets information about the requirement.
*
* @return The set of all the information
@@ -230,4 +261,31 @@ public class TmfAnalysisRequirement {
return fValues.get(value);
}
}
+
+ /**
+ * Verifies whether a trace fulfills this requirement
+ *
+ * @param trace
+ * The trace on which to check for this requirement
+ * @return True if the trace has all mandatory values of this requirement
+ */
+ public boolean isFulfilled(@NonNull ITmfTrace trace) {
+ switch (fType) {
+ case TYPE_EVENT:
+ if (trace instanceof ITmfTraceWithPreDefinedEvents) {
+ Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(((ITmfTraceWithPreDefinedEvents) trace).getContainedEventTypes());
+ Set<String> mandatoryValues = getValues(ValuePriorityLevel.MANDATORY);
+ return traceEvents.containsAll(mandatoryValues);
+ }
+ break;
+ default:
+ return true;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return fType + ": " + fValues; //$NON-NLS-1$
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/messages.properties b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/messages.properties
index 46e2597399..9744dea254 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/messages.properties
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/messages.properties
@@ -15,6 +15,7 @@ TmfAnalysisModuleHelper_AnalysisDoesNotApply=Cannot perform analysis "{0}" on th
TmfAbstractAnalysisModule_AnalysisForTrace=Analysis module: {0} for trace {1}
TmfAbstractAnalysisModule_AnalysisModule=Analysis module: {0}
TmfAbstractAnalysisModule_InvalidParameter=Parameter {0} is not valid for analysis module {1}
+TmfAbstractAnalysisModule_NullTrace=Setting a null trace to analysis module
TmfAbstractAnalysisModule_RunningAnalysis=Running analysis {0}
TmfAnalysisManager_ErrorParameterProvider=Error instantiating parameter provider
TmfAnalysisModuleHelper_ImpossibleToCreateModule=Could not instantiate module "{0}"
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java
index 1190cb0382..e220ccf66f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java
@@ -290,7 +290,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
status.add(module.schedule());
}
} catch (TmfAnalysisException e) {
- status.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+ status.add(new Status(IStatus.WARNING, Activator.PLUGIN_ID, e.getMessage()));
}
}
return status;

Back to the top