From c91f009609349f5dbe16bcc971a736159f12b07b Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Fri, 11 Mar 2016 13:42:42 -0500 Subject: [PATCH] lttng: Fix ust memory analysis help text display 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 Reviewed-on: https://git.eclipse.org/r/68236 Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann --- .../memory/UstMemoryAnalysisModule.java | 85 +++++++++---------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java index c5df05d2ff..9b3ace00cf 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java @@ -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 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 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 getAnalysisRequirements() { - Set reqs = fAnalysisRequirements; - if (reqs == null) { - throw new IllegalStateException("Cannot get the analysis requirements without an assigned trace."); //$NON-NLS-1$ + Set 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; } } -- 2.34.1