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
.LttngUst20EventLayout
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.ust
.core
.trace
.layout
.LttngUst27EventLayout
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.ust
.core
.trace
.layout
.LttngUst28EventLayout
;
30 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoBinaryAspect
;
31 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoFunctionAspect
;
32 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoSourceAspect
;
33 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.layout
.ILttngUstEventLayout
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
38 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
39 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTraceValidationStatus
;
40 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfUtils
;
42 import com
.google
.common
.collect
.ImmutableSet
;
45 * Class to contain LTTng-UST traces
47 * @author Matthew Khouzam
49 public class LttngUstTrace
extends CtfTmfTrace
{
52 * Name of the tracer that generates this trace type, as found in the CTF
57 public static final String TRACER_NAME
= "lttng-ust"; //$NON-NLS-1$
59 private static final int CONFIDENCE
= 100;
61 private static final @NonNull Collection
<ITmfEventAspect
<?
>> LTTNG_UST_ASPECTS
;
64 ImmutableSet
.Builder
<ITmfEventAspect
<?
>> builder
= ImmutableSet
.builder();
65 builder
.addAll(CtfTmfTrace
.CTF_ASPECTS
);
66 builder
.add(UstDebugInfoBinaryAspect
.INSTANCE
);
67 builder
.add(UstDebugInfoFunctionAspect
.INSTANCE
);
68 builder
.add(UstDebugInfoSourceAspect
.INSTANCE
);
69 LTTNG_UST_ASPECTS
= builder
.build();
72 private @Nullable ILttngUstEventLayout fLayout
= null;
77 public LttngUstTrace() {
78 super(LttngUstEventFactory
.instance());
82 * Get the event layout to use with this trace. This normally depends on the
85 * @return The event layout
88 public @NonNull ILttngUstEventLayout
getEventLayout() {
89 ILttngUstEventLayout layout
= fLayout
;
91 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
97 public void initTrace(IResource resource
, String path
,
98 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
99 super.initTrace(resource
, path
, eventType
);
101 /* Determine the event layout to use from the tracer's version */
102 fLayout
= getLayoutFromEnv();
105 private @NonNull ILttngUstEventLayout
getLayoutFromEnv() {
106 String tracerName
= CtfUtils
.getTracerName(this);
107 int tracerMajor
= CtfUtils
.getTracerMajorVersion(this);
108 int tracerMinor
= CtfUtils
.getTracerMinorVersion(this);
110 if (TRACER_NAME
.equals(tracerName
)) {
111 if (tracerMajor
>= 2) {
112 if (tracerMinor
>= 8) {
113 return LttngUst28EventLayout
.getInstance();
114 } else if (tracerMinor
>= 7) {
115 return LttngUst27EventLayout
.getInstance();
117 return LttngUst20EventLayout
.getInstance();
121 /* Fallback to the UST 2.0 layout and hope for the best */
122 return LttngUst20EventLayout
.getInstance();
126 public Iterable
<ITmfEventAspect
<?
>> getEventAspects() {
127 return LTTNG_UST_ASPECTS
;
133 * This implementation sets the confidence to 100 if the trace is a valid
134 * CTF trace in the "ust" domain.
137 public IStatus
validate(final IProject project
, final String path
) {
138 IStatus status
= super.validate(project
, path
);
139 if (status
instanceof CtfTraceValidationStatus
) {
140 Map
<String
, String
> environment
= ((CtfTraceValidationStatus
) status
).getEnvironment();
141 /* Make sure the domain is "ust" in the trace's env vars */
142 String domain
= environment
.get("domain"); //$NON-NLS-1$
143 if (domain
== null || !domain
.equals("\"ust\"")) { //$NON-NLS-1$
144 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngUstTrace_DomainError
);
146 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
151 // ------------------------------------------------------------------------
152 // Fields/methods bridging the Debug-info symbol provider
153 // ------------------------------------------------------------------------
156 * FIXME Once the symbol provider is split in core/ui components, the
157 * UstDebugInfoSymbolProvider should be moved to the core plugin, and this
158 * here can be removed.
162 * Configuration of the symbol provider.
166 public static class SymbolProviderConfig
{
168 private final boolean fUseCustomRootDir
;
169 private final @NonNull String fCustomRootDirPath
;
174 * Note that a path can be specified even if 'useCustomRootDir' is
175 * false. This will keep the setting in the text field even when it is
178 * @param useCustomRootDir
179 * Should a custom directory be used
181 * Custom directory path
183 public SymbolProviderConfig(boolean useCustomRootDir
, @NonNull String rootDirPath
) {
184 fUseCustomRootDir
= useCustomRootDir
;
185 fCustomRootDirPath
= rootDirPath
;
189 * @return Should a custom directory be used
191 public boolean useCustomRootDir() {
192 return fUseCustomRootDir
;
196 * @return The configured root directory
198 public String
getCustomRootDirPath() {
199 return fCustomRootDirPath
;
203 * Return the "real" path to use for symbol resolution. This is a
204 * convenience method that avoids having to check the state of
205 * {@link #useCustomRootDir()} separately.
207 * @return The actual root directory to use
209 public String
getActualRootDirPath() {
210 if (fUseCustomRootDir
) {
211 return fCustomRootDirPath
;
213 return ""; //$NON-NLS-1$
217 private @NonNull SymbolProviderConfig fCurrentProviderConfig
=
218 /* Default settings for new traces */
219 new SymbolProviderConfig(false, ""); //$NON-NLS-1$
223 * Get the current symbol provider configuration for this trace.
225 * @return The current symbol provider configuration
228 public @NonNull SymbolProviderConfig
getSymbolProviderConfig() {
229 return fCurrentProviderConfig
;
233 * Set the symbol provider configuration for this trace.
236 * The new symbol provider configuration to use
239 public void setSymbolProviderConfig(@NonNull SymbolProviderConfig config
) {
240 fCurrentProviderConfig
= config
;