Commit | Line | Data |
---|---|---|
91fc3690 | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
91fc3690 AM |
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 | * Matthew Khouzam - Initial API and implementation | |
1c6660ca | 11 | * Alexandre Montplaisir - Add UST callstack state system |
af015d44 | 12 | * Marc-Andre Laperle - Handle BufferOverflowException (Bug 420203) |
91fc3690 AM |
13 | **********************************************************************/ |
14 | ||
9bc60be7 | 15 | package org.eclipse.tracecompass.lttng2.ust.core.trace; |
91fc3690 | 16 | |
ef7f180d | 17 | import java.util.Collection; |
d6e6f5d5 | 18 | import java.util.HashSet; |
747fd87b | 19 | import java.util.Map; |
1c6660ca | 20 | |
91fc3690 | 21 | import org.eclipse.core.resources.IProject; |
7443de72 | 22 | import org.eclipse.core.resources.IResource; |
91fc3690 AM |
23 | import org.eclipse.core.runtime.IStatus; |
24 | import org.eclipse.core.runtime.Status; | |
7443de72 AM |
25 | import org.eclipse.jdt.annotation.NonNull; |
26 | import org.eclipse.jdt.annotation.Nullable; | |
9bc60be7 | 27 | import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator; |
d6e6f5d5 | 28 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.ContextVtidAspect; |
4f3ea7da | 29 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.DefaultUstEventLayout; |
7443de72 AM |
30 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout; |
31 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout; | |
ef7f180d | 32 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst28EventLayout; |
59c014d7 | 33 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst29EventLayout; |
df993132 | 34 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryAspect; |
3335f36e | 35 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoFunctionAspect; |
a103fe67 | 36 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoSourceAspect; |
7443de72 AM |
37 | import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; |
38 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
ef7f180d | 39 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
7443de72 | 40 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; |
2bdf0193 | 41 | import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; |
d755ffcc | 42 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory; |
9722e5d7 | 43 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
747fd87b | 44 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; |
542ddfb3 | 45 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils; |
91fc3690 | 46 | |
ef7f180d AM |
47 | import com.google.common.collect.ImmutableSet; |
48 | ||
91fc3690 AM |
49 | /** |
50 | * Class to contain LTTng-UST traces | |
51 | * | |
52 | * @author Matthew Khouzam | |
91fc3690 AM |
53 | */ |
54 | public class LttngUstTrace extends CtfTmfTrace { | |
55 | ||
ef7f180d AM |
56 | /** |
57 | * Name of the tracer that generates this trace type, as found in the CTF | |
58 | * metadata. | |
59 | * | |
60 | * @since 2.0 | |
61 | */ | |
62 | public static final String TRACER_NAME = "lttng-ust"; //$NON-NLS-1$ | |
63 | ||
cd43d683 PT |
64 | private static final int CONFIDENCE = 100; |
65 | ||
ec48d248 | 66 | private static final @NonNull Collection<ITmfEventAspect<?>> LTTNG_UST_ASPECTS; |
ef7f180d AM |
67 | |
68 | static { | |
ec48d248 | 69 | ImmutableSet.Builder<ITmfEventAspect<?>> builder = ImmutableSet.builder(); |
ef7f180d | 70 | builder.addAll(CtfTmfTrace.CTF_ASPECTS); |
df993132 | 71 | builder.add(UstDebugInfoBinaryAspect.INSTANCE); |
3335f36e | 72 | builder.add(UstDebugInfoFunctionAspect.INSTANCE); |
a103fe67 | 73 | builder.add(UstDebugInfoSourceAspect.INSTANCE); |
0e4f957e | 74 | LTTNG_UST_ASPECTS = builder.build(); |
ef7f180d AM |
75 | } |
76 | ||
d6e6f5d5 GB |
77 | private @NonNull Collection<ITmfEventAspect<?>> fUstTraceAspects = new HashSet<>(LTTNG_UST_ASPECTS); |
78 | ||
7443de72 AM |
79 | private @Nullable ILttngUstEventLayout fLayout = null; |
80 | ||
91fc3690 AM |
81 | /** |
82 | * Default constructor | |
83 | */ | |
84 | public LttngUstTrace() { | |
5c82e602 | 85 | super(LttngUstEventFactory.instance()); |
91fc3690 AM |
86 | } |
87 | ||
d755ffcc GB |
88 | /** |
89 | * Protected constructor for child classes. Classes extending this one may | |
90 | * have extra fields coming from the event itself and may pass their own | |
91 | * event factory. | |
92 | * | |
93 | * @param factory | |
94 | * The event factory for this specific trace | |
f0c26e1d | 95 | * @since 3.0 |
d755ffcc GB |
96 | */ |
97 | protected LttngUstTrace(@NonNull CtfTmfEventFactory factory) { | |
98 | super(factory); | |
99 | } | |
100 | ||
7443de72 AM |
101 | /** |
102 | * Get the event layout to use with this trace. This normally depends on the | |
103 | * tracer's version. | |
104 | * | |
105 | * @return The event layout | |
106 | * @since 2.0 | |
107 | */ | |
108 | public @NonNull ILttngUstEventLayout getEventLayout() { | |
109 | ILttngUstEventLayout layout = fLayout; | |
110 | if (layout == null) { | |
111 | throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$ | |
112 | } | |
113 | return layout; | |
114 | } | |
115 | ||
116 | @Override | |
117 | public void initTrace(IResource resource, String path, | |
118 | Class<? extends ITmfEvent> eventType) throws TmfTraceException { | |
119 | super.initTrace(resource, path, eventType); | |
120 | ||
121 | /* Determine the event layout to use from the tracer's version */ | |
542ddfb3 | 122 | fLayout = getLayoutFromEnv(); |
d6e6f5d5 GB |
123 | |
124 | ImmutableSet.Builder<ITmfEventAspect<?>> builder = ImmutableSet.builder(); | |
125 | builder.addAll(LTTNG_UST_ASPECTS); | |
126 | builder.add(new ContextVtidAspect(fLayout)); | |
127 | fUstTraceAspects = builder.build(); | |
7443de72 AM |
128 | } |
129 | ||
542ddfb3 AM |
130 | private @NonNull ILttngUstEventLayout getLayoutFromEnv() { |
131 | String tracerName = CtfUtils.getTracerName(this); | |
132 | int tracerMajor = CtfUtils.getTracerMajorVersion(this); | |
133 | int tracerMinor = CtfUtils.getTracerMinorVersion(this); | |
7443de72 | 134 | |
ef7f180d | 135 | if (TRACER_NAME.equals(tracerName)) { |
542ddfb3 | 136 | if (tracerMajor >= 2) { |
59c014d7 AM |
137 | if (tracerMinor >= 9) { |
138 | return LttngUst29EventLayout.getInstance(); | |
139 | } else if (tracerMinor >= 8) { | |
ef7f180d AM |
140 | return LttngUst28EventLayout.getInstance(); |
141 | } else if (tracerMinor >= 7) { | |
7443de72 AM |
142 | return LttngUst27EventLayout.getInstance(); |
143 | } | |
144 | return LttngUst20EventLayout.getInstance(); | |
145 | } | |
146 | } | |
147 | ||
4f3ea7da AB |
148 | /* Fallback to the Default layout and hope for the best */ |
149 | return DefaultUstEventLayout.getInstance(); | |
7443de72 AM |
150 | } |
151 | ||
ef7f180d | 152 | @Override |
ec48d248 | 153 | public Iterable<ITmfEventAspect<?>> getEventAspects() { |
d6e6f5d5 | 154 | return fUstTraceAspects; |
ef7f180d AM |
155 | } |
156 | ||
cd43d683 PT |
157 | /** |
158 | * {@inheritDoc} | |
159 | * <p> | |
160 | * This implementation sets the confidence to 100 if the trace is a valid | |
161 | * CTF trace in the "ust" domain. | |
162 | */ | |
91fc3690 | 163 | @Override |
b562a24f | 164 | public IStatus validate(final IProject project, final String path) { |
747fd87b PT |
165 | IStatus status = super.validate(project, path); |
166 | if (status instanceof CtfTraceValidationStatus) { | |
167 | Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment(); | |
dd9752d5 | 168 | /* Make sure the domain is "ust" in the trace's env vars */ |
747fd87b PT |
169 | String domain = environment.get("domain"); //$NON-NLS-1$ |
170 | if (domain == null || !domain.equals("\"ust\"")) { //$NON-NLS-1$ | |
171 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngUstTrace_DomainError); | |
dd9752d5 | 172 | } |
747fd87b | 173 | return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); |
91fc3690 | 174 | } |
747fd87b | 175 | return status; |
91fc3690 | 176 | } |
cb2b5e56 AM |
177 | |
178 | // ------------------------------------------------------------------------ | |
179 | // Fields/methods bridging the Debug-info symbol provider | |
180 | // ------------------------------------------------------------------------ | |
181 | ||
182 | /* | |
183 | * FIXME Once the symbol provider is split in core/ui components, the | |
184 | * UstDebugInfoSymbolProvider should be moved to the core plugin, and this | |
185 | * here can be removed. | |
186 | */ | |
187 | ||
188 | /** | |
189 | * Configuration of the symbol provider. | |
190 | * | |
191 | * @since 2.0 | |
192 | */ | |
193 | public static class SymbolProviderConfig { | |
194 | ||
195 | private final boolean fUseCustomRootDir; | |
196 | private final @NonNull String fCustomRootDirPath; | |
197 | ||
198 | /** | |
199 | * Constructor | |
200 | * | |
201 | * Note that a path can be specified even if 'useCustomRootDir' is | |
202 | * false. This will keep the setting in the text field even when it is | |
203 | * grayed out. | |
204 | * | |
205 | * @param useCustomRootDir | |
206 | * Should a custom directory be used | |
207 | * @param rootDirPath | |
208 | * Custom directory path | |
209 | */ | |
210 | public SymbolProviderConfig(boolean useCustomRootDir, @NonNull String rootDirPath) { | |
211 | fUseCustomRootDir = useCustomRootDir; | |
212 | fCustomRootDirPath = rootDirPath; | |
213 | } | |
214 | ||
215 | /** | |
216 | * @return Should a custom directory be used | |
217 | */ | |
218 | public boolean useCustomRootDir() { | |
219 | return fUseCustomRootDir; | |
220 | } | |
221 | ||
222 | /** | |
223 | * @return The configured root directory | |
224 | */ | |
225 | public String getCustomRootDirPath() { | |
226 | return fCustomRootDirPath; | |
227 | } | |
228 | ||
229 | /** | |
230 | * Return the "real" path to use for symbol resolution. This is a | |
231 | * convenience method that avoids having to check the state of | |
232 | * {@link #useCustomRootDir()} separately. | |
233 | * | |
234 | * @return The actual root directory to use | |
235 | */ | |
236 | public String getActualRootDirPath() { | |
237 | if (fUseCustomRootDir) { | |
238 | return fCustomRootDirPath; | |
239 | } | |
240 | return ""; //$NON-NLS-1$ | |
241 | } | |
242 | } | |
243 | ||
244 | private @NonNull SymbolProviderConfig fCurrentProviderConfig = | |
245 | /* Default settings for new traces */ | |
246 | new SymbolProviderConfig(false, ""); //$NON-NLS-1$ | |
247 | ||
248 | ||
249 | /** | |
250 | * Get the current symbol provider configuration for this trace. | |
251 | * | |
252 | * @return The current symbol provider configuration | |
253 | * @since 2.0 | |
254 | */ | |
255 | public @NonNull SymbolProviderConfig getSymbolProviderConfig() { | |
256 | return fCurrentProviderConfig; | |
257 | } | |
258 | ||
259 | /** | |
260 | * Set the symbol provider configuration for this trace. | |
261 | * | |
262 | * @param config | |
263 | * The new symbol provider configuration to use | |
264 | * @since 2.0 | |
265 | */ | |
266 | public void setSymbolProviderConfig(@NonNull SymbolProviderConfig config) { | |
267 | fCurrentProviderConfig = config; | |
268 | } | |
91fc3690 | 269 | } |