1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Add UST callstack state system
12 * Marc-Andre Laperle - Handle BufferOverflowException (Bug 420203)
13 **********************************************************************/
15 package org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
;
17 import java
.util
.Collection
;
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
;
45 import com
.google
.common
.collect
.ImmutableSet
;
48 * Class to contain LTTng-UST traces
50 * @author Matthew Khouzam
52 public class LttngUstTrace
extends CtfTmfTrace
{
55 * Name of the tracer that generates this trace type, as found in the CTF
60 public static final String TRACER_NAME
= "lttng-ust"; //$NON-NLS-1$
62 private static final int CONFIDENCE
= 100;
64 private static final @NonNull Collection
<ITmfEventAspect
<?
>> LTTNG_UST_ASPECTS
;
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();
75 private @Nullable ILttngUstEventLayout fLayout
= null;
80 public LttngUstTrace() {
81 super(LttngUstEventFactory
.instance());
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
90 * The event factory for this specific trace
93 protected LttngUstTrace(@NonNull CtfTmfEventFactory factory
) {
98 * Get the event layout to use with this trace. This normally depends on the
101 * @return The event layout
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$
113 public void initTrace(IResource resource
, String path
,
114 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
115 super.initTrace(resource
, path
, eventType
);
117 /* Determine the event layout to use from the tracer's version */
118 fLayout
= getLayoutFromEnv();
121 private @NonNull ILttngUstEventLayout
getLayoutFromEnv() {
122 String tracerName
= CtfUtils
.getTracerName(this);
123 int tracerMajor
= CtfUtils
.getTracerMajorVersion(this);
124 int tracerMinor
= CtfUtils
.getTracerMinorVersion(this);
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();
135 return LttngUst20EventLayout
.getInstance();
139 /* Fallback to the Default layout and hope for the best */
140 return DefaultUstEventLayout
.getInstance();
144 public Iterable
<ITmfEventAspect
<?
>> getEventAspects() {
145 return LTTNG_UST_ASPECTS
;
151 * This implementation sets the confidence to 100 if the trace is a valid
152 * CTF trace in the "ust" domain.
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
);
164 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
169 // ------------------------------------------------------------------------
170 // Fields/methods bridging the Debug-info symbol provider
171 // ------------------------------------------------------------------------
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.
180 * Configuration of the symbol provider.
184 public static class SymbolProviderConfig
{
186 private final boolean fUseCustomRootDir
;
187 private final @NonNull String fCustomRootDirPath
;
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
196 * @param useCustomRootDir
197 * Should a custom directory be used
199 * Custom directory path
201 public SymbolProviderConfig(boolean useCustomRootDir
, @NonNull String rootDirPath
) {
202 fUseCustomRootDir
= useCustomRootDir
;
203 fCustomRootDirPath
= rootDirPath
;
207 * @return Should a custom directory be used
209 public boolean useCustomRootDir() {
210 return fUseCustomRootDir
;
214 * @return The configured root directory
216 public String
getCustomRootDirPath() {
217 return fCustomRootDirPath
;
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.
225 * @return The actual root directory to use
227 public String
getActualRootDirPath() {
228 if (fUseCustomRootDir
) {
229 return fCustomRootDirPath
;
231 return ""; //$NON-NLS-1$
235 private @NonNull SymbolProviderConfig fCurrentProviderConfig
=
236 /* Default settings for new traces */
237 new SymbolProviderConfig(false, ""); //$NON-NLS-1$
241 * Get the current symbol provider configuration for this trace.
243 * @return The current symbol provider configuration
246 public @NonNull SymbolProviderConfig
getSymbolProviderConfig() {
247 return fCurrentProviderConfig
;
251 * Set the symbol provider configuration for this trace.
254 * The new symbol provider configuration to use
257 public void setSymbolProviderConfig(@NonNull SymbolProviderConfig config
) {
258 fCurrentProviderConfig
= config
;