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