Commit | Line | Data |
---|---|---|
2237fe8a | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2014, 2015 École Polytechnique de Montréal |
2237fe8a GB |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
53e5d2d3 | 11 | * Guilliano Molaire - Provide the requirements of the analysis |
2237fe8a GB |
12 | *******************************************************************************/ |
13 | ||
9bc60be7 | 14 | package org.eclipse.tracecompass.lttng2.ust.core.analysis.memory; |
2237fe8a | 15 | |
5db5a3a4 | 16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
aa353506 | 17 | import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString; |
5db5a3a4 AM |
18 | |
19 | import java.util.Set; | |
20 | ||
ba27dd38 | 21 | import org.eclipse.jdt.annotation.NonNull; |
7e452c97 | 22 | import org.eclipse.jdt.annotation.Nullable; |
116738ad | 23 | import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStateProvider; |
9bc60be7 AM |
24 | import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings; |
25 | import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace; | |
7e452c97 | 26 | import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; |
2bdf0193 AM |
27 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement; |
28 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel; | |
29 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; | |
30 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; | |
31 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; | |
32 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2237fe8a | 33 | |
53e5d2d3 GM |
34 | import com.google.common.collect.ImmutableSet; |
35 | ||
2237fe8a GB |
36 | /** |
37 | * This analysis build a state system from the libc memory instrumentation on a | |
1996f571 | 38 | * UST trace |
2237fe8a GB |
39 | * |
40 | * @author Geneviève Bastien | |
2237fe8a GB |
41 | */ |
42 | public class UstMemoryAnalysisModule extends TmfStateSystemAnalysisModule { | |
43 | ||
44 | /** | |
45 | * Analysis ID, it should match that in the plugin.xml file | |
46 | */ | |
1d83ed07 | 47 | public static final @NonNull String ID = "org.eclipse.linuxtools.lttng2.ust.analysis.memory"; //$NON-NLS-1$ |
2237fe8a | 48 | |
7e452c97 AM |
49 | /** The analysis's requirements. Only set after the trace is set. */ |
50 | private @Nullable Set<TmfAnalysisRequirement> fAnalysisRequirements; | |
53e5d2d3 | 51 | |
2237fe8a | 52 | @Override |
53e5d2d3 | 53 | protected ITmfStateProvider createStateProvider() { |
116738ad | 54 | return new UstMemoryStateProvider(checkNotNull(getTrace())); |
2237fe8a GB |
55 | } |
56 | ||
f479550c GB |
57 | /** |
58 | * @since 1.0 | |
59 | */ | |
2237fe8a | 60 | @Override |
f479550c | 61 | public boolean setTrace(ITmfTrace trace) throws TmfAnalysisException { |
2237fe8a | 62 | if (!(trace instanceof LttngUstTrace)) { |
f479550c | 63 | return false; |
2237fe8a | 64 | } |
7e452c97 AM |
65 | /* |
66 | * setTrace() calls getAnalysisRequirements, so we need the field set | |
67 | * for the check to work. | |
68 | */ | |
69 | fAnalysisRequirements = requirementsForTrace((LttngUstTrace) trace); | |
70 | boolean traceIsSet = super.setTrace(trace); | |
71 | if (!traceIsSet) { | |
72 | /* Unset the requirements, the trace was not good after all. */ | |
73 | fAnalysisRequirements = null; | |
74 | } | |
75 | return traceIsSet; | |
2237fe8a GB |
76 | } |
77 | ||
78 | @Override | |
79 | protected LttngUstTrace getTrace() { | |
80 | return (LttngUstTrace) super.getTrace(); | |
81 | } | |
82 | ||
7e452c97 AM |
83 | private static Set<TmfAnalysisRequirement> requirementsForTrace(LttngUstTrace trace) { |
84 | /* | |
85 | * Compute the list of required events, whose exact names can change | |
86 | * depending on the tracer's version. | |
87 | */ | |
88 | ILttngUstEventLayout layout = trace.getEventLayout(); | |
89 | Set<String> requiredEvents = ImmutableSet.of( | |
90 | layout.eventLibcMalloc(), | |
91 | layout.eventLibcFree(), | |
92 | layout.eventLibcCalloc(), | |
93 | layout.eventLibcRealloc(), | |
94 | layout.eventLibcMemalign(), | |
95 | layout.eventLibcPosixMemalign() | |
96 | ); | |
97 | ||
98 | /* Initialize the requirements for the analysis: domain and events */ | |
99 | TmfAnalysisRequirement eventsReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_EVENT, requiredEvents, ValuePriorityLevel.MANDATORY); | |
100 | /* | |
101 | * In order to have these events, the libc wrapper with probes should be | |
102 | * loaded | |
103 | */ | |
aa353506 AM |
104 | eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingInformation)); |
105 | eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingExampleInformation)); | |
7e452c97 AM |
106 | |
107 | /* The domain type of the analysis */ | |
108 | TmfAnalysisRequirement domainReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN); | |
109 | domainReq.addValue(SessionConfigStrings.CONFIG_DOMAIN_TYPE_UST, ValuePriorityLevel.MANDATORY); | |
110 | ||
0e4f957e | 111 | return ImmutableSet.of(domainReq, eventsReq); |
7e452c97 AM |
112 | } |
113 | ||
53e5d2d3 GM |
114 | @Override |
115 | public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() { | |
7e452c97 AM |
116 | Set<TmfAnalysisRequirement> reqs = fAnalysisRequirements; |
117 | if (reqs == null) { | |
118 | throw new IllegalStateException("Cannot get the analysis requirements without an assigned trace."); //$NON-NLS-1$ | |
119 | } | |
120 | return reqs; | |
53e5d2d3 | 121 | } |
2237fe8a | 122 | } |