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