1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Geneviève Bastien - Initial API and implementation
11 * Guilliano Molaire - Provide the requirements of the analysis
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.memory
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.eclipse
.tracecompass
.internal
.lttng2
.ust
.core
.analysis
.memory
.UstMemoryStateProvider
;
23 import org
.eclipse
.tracecompass
.lttng2
.control
.core
.session
.SessionConfigStrings
;
24 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
25 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.layout
.ILttngUstEventLayout
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisRequirement
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisRequirement
.ValuePriorityLevel
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
33 import com
.google
.common
.collect
.ImmutableSet
;
36 * This analysis build a state system from the libc memory instrumentation on a
39 * @author Geneviève Bastien
41 public class UstMemoryAnalysisModule
extends TmfStateSystemAnalysisModule
{
44 * Analysis ID, it should match that in the plugin.xml file
46 public static final @NonNull String ID
= "org.eclipse.linuxtools.lttng2.ust.analysis.memory"; //$NON-NLS-1$
48 /** The analysis's requirements. Only set after the trace is set. */
49 private @Nullable Set
<TmfAnalysisRequirement
> fAnalysisRequirements
;
52 protected ITmfStateProvider
createStateProvider() {
53 return new UstMemoryStateProvider(checkNotNull(getTrace()));
60 public boolean setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
61 if (!(trace
instanceof LttngUstTrace
)) {
65 * setTrace() calls getAnalysisRequirements, so we need the field set
66 * for the check to work.
68 fAnalysisRequirements
= requirementsForTrace((LttngUstTrace
) trace
);
69 boolean traceIsSet
= super.setTrace(trace
);
71 /* Unset the requirements, the trace was not good after all. */
72 fAnalysisRequirements
= null;
78 protected LttngUstTrace
getTrace() {
79 return (LttngUstTrace
) super.getTrace();
82 private static Set
<TmfAnalysisRequirement
> requirementsForTrace(LttngUstTrace trace
) {
84 * Compute the list of required events, whose exact names can change
85 * depending on the tracer's version.
87 ILttngUstEventLayout layout
= trace
.getEventLayout();
88 Set
<String
> requiredEvents
= ImmutableSet
.of(
89 layout
.eventLibcMalloc(),
90 layout
.eventLibcFree(),
91 layout
.eventLibcCalloc(),
92 layout
.eventLibcRealloc(),
93 layout
.eventLibcMemalign(),
94 layout
.eventLibcPosixMemalign()
97 /* Initialize the requirements for the analysis: domain and events */
98 TmfAnalysisRequirement eventsReq
= new TmfAnalysisRequirement(SessionConfigStrings
.CONFIG_ELEMENT_EVENT
, requiredEvents
, ValuePriorityLevel
.MANDATORY
);
100 * In order to have these events, the libc wrapper with probes should be
103 eventsReq
.addInformation(Messages
.UstMemoryAnalysisModule_EventsLoadingInformation
);
104 eventsReq
.addInformation(Messages
.UstMemoryAnalysisModule_EventsLoadingExampleInformation
);
106 /* The domain type of the analysis */
107 TmfAnalysisRequirement domainReq
= new TmfAnalysisRequirement(SessionConfigStrings
.CONFIG_ELEMENT_DOMAIN
);
108 domainReq
.addValue(SessionConfigStrings
.CONFIG_DOMAIN_TYPE_UST
, ValuePriorityLevel
.MANDATORY
);
110 return checkNotNull(ImmutableSet
.of(domainReq
, eventsReq
));
114 public Iterable
<TmfAnalysisRequirement
> getAnalysisRequirements() {
115 Set
<TmfAnalysisRequirement
> reqs
= fAnalysisRequirements
;
117 throw new IllegalStateException("Cannot get the analysis requirements without an assigned trace."); //$NON-NLS-1$