9b3ace00cf8be80bb40bb4f1a56b59ed202f648d
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / memory / UstMemoryAnalysisModule.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others
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
11 * Guilliano Molaire - Provide the requirements of the analysis
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.lttng2.ust.core.analysis.memory;
15
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17 import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
18
19 import java.util.Set;
20
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStateProvider;
24 import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings;
25 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
26 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
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;
33
34 import com.google.common.collect.ImmutableSet;
35
36 /**
37 * This analysis build a state system from the libc memory instrumentation on a
38 * UST trace
39 *
40 * @author Geneviève Bastien
41 */
42 public class UstMemoryAnalysisModule extends TmfStateSystemAnalysisModule {
43
44 /**
45 * Analysis ID, it should match that in the plugin.xml file
46 */
47 public static final @NonNull String ID = "org.eclipse.linuxtools.lttng2.ust.analysis.memory"; //$NON-NLS-1$
48
49 /** The analysis's requirements. Only set after the trace is set. */
50 private @Nullable Set<TmfAnalysisRequirement> fAnalysisRequirements;
51
52 @Override
53 protected ITmfStateProvider createStateProvider() {
54 return new UstMemoryStateProvider(checkNotNull(getTrace()));
55 }
56
57 /**
58 * @since 1.0
59 */
60 @Override
61 public boolean setTrace(ITmfTrace trace) throws TmfAnalysisException {
62 if (!(trace instanceof LttngUstTrace)) {
63 return false;
64 }
65 return super.setTrace(trace);
66 }
67
68 @Override
69 protected LttngUstTrace getTrace() {
70 return (LttngUstTrace) super.getTrace();
71 }
72
73 @Override
74 public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
75 Set<TmfAnalysisRequirement> requirements = fAnalysisRequirements;
76 if (requirements == null) {
77 LttngUstTrace trace = getTrace();
78 ILttngUstEventLayout layout;
79 if (trace == null) {
80 layout = ILttngUstEventLayout.DEFAULT_LAYOUT;
81 } else {
82 layout = trace.getEventLayout();
83 }
84
85 @NonNull Set<@NonNull String> requiredEvents = ImmutableSet.of(
86 layout.eventLibcMalloc(),
87 layout.eventLibcFree(),
88 layout.eventLibcCalloc(),
89 layout.eventLibcRealloc(),
90 layout.eventLibcMemalign(),
91 layout.eventLibcPosixMemalign()
92 );
93
94 /* Initialize the requirements for the analysis: domain and events */
95 TmfAnalysisRequirement eventsReq = new TmfAnalysisRequirement(
96 nullToEmptyString(SessionConfigStrings.CONFIG_ELEMENT_EVENT), requiredEvents, ValuePriorityLevel.MANDATORY);
97 /*
98 * In order to have these events, the libc wrapper with probes should be
99 * loaded
100 */
101 eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingInformation));
102 eventsReq.addInformation(nullToEmptyString(Messages.UstMemoryAnalysisModule_EventsLoadingExampleInformation));
103
104 /* The domain type of the analysis */
105 TmfAnalysisRequirement domainReq = new TmfAnalysisRequirement(nullToEmptyString(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN));
106 domainReq.addValue(nullToEmptyString(SessionConfigStrings.CONFIG_DOMAIN_TYPE_UST), ValuePriorityLevel.MANDATORY);
107
108 requirements = ImmutableSet.of(domainReq, eventsReq);
109 fAnalysisRequirements = requirements;
110 }
111 return requirements;
112 }
113 }
This page took 0.037389 seconds and 4 git commands to generate.