lttng: Fix ust memory analysis help text display
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Fri, 11 Mar 2016 18:42:42 +0000 (13:42 -0500)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 16 Mar 2016 14:08:45 +0000 (10:08 -0400)
When the analysis cannot be executed due to missing requirements, the
user can request the help text to get the reason why. However, this
was not working and caused an exception because the requirements are
only instantiated when the trace is open.

Change-Id: I43ca26b964467711bea10bf7ed52eba2988e3fd9
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/68236
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java

index c5df05d2ff9952baf93b976bf20e43bb974a3a6c..9b3ace00cf8be80bb40bb4f1a56b59ed202f648d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -62,17 +62,7 @@ public class UstMemoryAnalysisModule extends TmfStateSystemAnalysisModule {
         if (!(trace instanceof LttngUstTrace)) {
             return false;
         }
-        /*
-         * setTrace() calls getAnalysisRequirements, so we need the field set
-         * for the check to work.
-         */
-        fAnalysisRequirements = requirementsForTrace((LttngUstTrace) trace);
-        boolean traceIsSet = super.setTrace(trace);
-        if (!traceIsSet) {
-            /* Unset the requirements, the trace was not good after all. */
-            fAnalysisRequirements = null;
-        }
-        return traceIsSet;
+        return super.setTrace(trace);
     }
 
     @Override
@@ -80,43 +70,44 @@ public class UstMemoryAnalysisModule extends TmfStateSystemAnalysisModule {
         return (LttngUstTrace) super.getTrace();
     }
 
-    private static Set<TmfAnalysisRequirement> requirementsForTrace(LttngUstTrace trace) {
-        /*
-         * Compute the list of required events, whose exact names can change
-         * depending on the tracer's version.
-         */
-        ILttngUstEventLayout layout = trace.getEventLayout();
-        Set<String> requiredEvents = ImmutableSet.of(
-                layout.eventLibcMalloc(),
-                layout.eventLibcFree(),
-                layout.eventLibcCalloc(),
-                layout.eventLibcRealloc(),
-                layout.eventLibcMemalign(),
-                layout.eventLibcPosixMemalign()
-              );
-
-        /* Initialize the requirements for the analysis: domain and events */
-        TmfAnalysisRequirement eventsReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_EVENT, requiredEvents, ValuePriorityLevel.MANDATORY);
-        /*
-         * In order to have these events, the libc wrapper with probes should be
-         * loaded
-         */
-        eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingInformation));
-        eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingExampleInformation));
-
-        /* The domain type of the analysis */
-        TmfAnalysisRequirement domainReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN);
-        domainReq.addValue(SessionConfigStrings.CONFIG_DOMAIN_TYPE_UST, ValuePriorityLevel.MANDATORY);
-
-        return ImmutableSet.of(domainReq, eventsReq);
-    }
-
     @Override
     public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
-        Set<TmfAnalysisRequirement> reqs = fAnalysisRequirements;
-        if (reqs == null) {
-            throw new IllegalStateException("Cannot get the analysis requirements without an assigned trace."); //$NON-NLS-1$
+        Set<TmfAnalysisRequirement> requirements = fAnalysisRequirements;
+        if (requirements == null) {
+            LttngUstTrace trace = getTrace();
+            ILttngUstEventLayout layout;
+            if (trace == null) {
+                layout = ILttngUstEventLayout.DEFAULT_LAYOUT;
+            } else {
+                layout = trace.getEventLayout();
+            }
+
+            @NonNull Set<@NonNull String> requiredEvents = ImmutableSet.of(
+                    layout.eventLibcMalloc(),
+                    layout.eventLibcFree(),
+                    layout.eventLibcCalloc(),
+                    layout.eventLibcRealloc(),
+                    layout.eventLibcMemalign(),
+                    layout.eventLibcPosixMemalign()
+                  );
+
+            /* Initialize the requirements for the analysis: domain and events */
+            TmfAnalysisRequirement eventsReq = new TmfAnalysisRequirement(
+                    nullToEmptyString(SessionConfigStrings.CONFIG_ELEMENT_EVENT), requiredEvents, ValuePriorityLevel.MANDATORY);
+            /*
+             * In order to have these events, the libc wrapper with probes should be
+             * loaded
+             */
+            eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingInformation));
+            eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingExampleInformation));
+
+            /* The domain type of the analysis */
+            TmfAnalysisRequirement domainReq = new TmfAnalysisRequirement(nullToEmptyString(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN));
+            domainReq.addValue(nullToEmptyString(SessionConfigStrings.CONFIG_DOMAIN_TYPE_UST), ValuePriorityLevel.MANDATORY);
+
+            requirements = ImmutableSet.of(domainReq, eventsReq);
+            fAnalysisRequirements = requirements;
         }
-        return reqs;
+        return requirements;
     }
 }
This page took 0.026037 seconds and 5 git commands to generate.