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; |
747fd87b | 18 | import java.util.Map; |
1c6660ca | 19 | |
91fc3690 | 20 | import org.eclipse.core.resources.IProject; |
7443de72 | 21 | import org.eclipse.core.resources.IResource; |
91fc3690 AM |
22 | import org.eclipse.core.runtime.IStatus; |
23 | import org.eclipse.core.runtime.Status; | |
7443de72 AM |
24 | import org.eclipse.jdt.annotation.NonNull; |
25 | import org.eclipse.jdt.annotation.Nullable; | |
9bc60be7 | 26 | import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator; |
7443de72 AM |
27 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout; |
28 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout; | |
ef7f180d | 29 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst28EventLayout; |
df993132 | 30 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryAspect; |
a103fe67 | 31 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoSourceAspect; |
7443de72 AM |
32 | import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; |
33 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
ef7f180d | 34 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
7443de72 | 35 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; |
2bdf0193 | 36 | import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; |
9722e5d7 | 37 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
747fd87b | 38 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; |
542ddfb3 | 39 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils; |
91fc3690 | 40 | |
ef7f180d AM |
41 | import com.google.common.collect.ImmutableSet; |
42 | ||
91fc3690 AM |
43 | /** |
44 | * Class to contain LTTng-UST traces | |
45 | * | |
46 | * @author Matthew Khouzam | |
91fc3690 AM |
47 | */ |
48 | public class LttngUstTrace extends CtfTmfTrace { | |
49 | ||
ef7f180d AM |
50 | /** |
51 | * Name of the tracer that generates this trace type, as found in the CTF | |
52 | * metadata. | |
53 | * | |
54 | * @since 2.0 | |
55 | */ | |
56 | public static final String TRACER_NAME = "lttng-ust"; //$NON-NLS-1$ | |
57 | ||
cd43d683 PT |
58 | private static final int CONFIDENCE = 100; |
59 | ||
ec48d248 | 60 | private static final @NonNull Collection<ITmfEventAspect<?>> LTTNG_UST_ASPECTS; |
ef7f180d AM |
61 | |
62 | static { | |
ec48d248 | 63 | ImmutableSet.Builder<ITmfEventAspect<?>> builder = ImmutableSet.builder(); |
ef7f180d | 64 | builder.addAll(CtfTmfTrace.CTF_ASPECTS); |
df993132 | 65 | builder.add(UstDebugInfoBinaryAspect.INSTANCE); |
a103fe67 | 66 | builder.add(UstDebugInfoSourceAspect.INSTANCE); |
0e4f957e | 67 | LTTNG_UST_ASPECTS = builder.build(); |
ef7f180d AM |
68 | } |
69 | ||
7443de72 AM |
70 | private @Nullable ILttngUstEventLayout fLayout = null; |
71 | ||
91fc3690 AM |
72 | /** |
73 | * Default constructor | |
74 | */ | |
75 | public LttngUstTrace() { | |
5c82e602 | 76 | super(LttngUstEventFactory.instance()); |
91fc3690 AM |
77 | } |
78 | ||
7443de72 AM |
79 | /** |
80 | * Get the event layout to use with this trace. This normally depends on the | |
81 | * tracer's version. | |
82 | * | |
83 | * @return The event layout | |
84 | * @since 2.0 | |
85 | */ | |
86 | public @NonNull ILttngUstEventLayout getEventLayout() { | |
87 | ILttngUstEventLayout layout = fLayout; | |
88 | if (layout == null) { | |
89 | throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$ | |
90 | } | |
91 | return layout; | |
92 | } | |
93 | ||
94 | @Override | |
95 | public void initTrace(IResource resource, String path, | |
96 | Class<? extends ITmfEvent> eventType) throws TmfTraceException { | |
97 | super.initTrace(resource, path, eventType); | |
98 | ||
99 | /* Determine the event layout to use from the tracer's version */ | |
542ddfb3 | 100 | fLayout = getLayoutFromEnv(); |
7443de72 AM |
101 | } |
102 | ||
542ddfb3 AM |
103 | private @NonNull ILttngUstEventLayout getLayoutFromEnv() { |
104 | String tracerName = CtfUtils.getTracerName(this); | |
105 | int tracerMajor = CtfUtils.getTracerMajorVersion(this); | |
106 | int tracerMinor = CtfUtils.getTracerMinorVersion(this); | |
7443de72 | 107 | |
ef7f180d | 108 | if (TRACER_NAME.equals(tracerName)) { |
542ddfb3 | 109 | if (tracerMajor >= 2) { |
ef7f180d AM |
110 | if (tracerMinor >= 8) { |
111 | return LttngUst28EventLayout.getInstance(); | |
112 | } else if (tracerMinor >= 7) { | |
7443de72 AM |
113 | return LttngUst27EventLayout.getInstance(); |
114 | } | |
115 | return LttngUst20EventLayout.getInstance(); | |
116 | } | |
117 | } | |
118 | ||
119 | /* Fallback to the UST 2.0 layout and hope for the best */ | |
120 | return LttngUst20EventLayout.getInstance(); | |
121 | } | |
122 | ||
ef7f180d | 123 | @Override |
ec48d248 | 124 | public Iterable<ITmfEventAspect<?>> getEventAspects() { |
ef7f180d AM |
125 | return LTTNG_UST_ASPECTS; |
126 | } | |
127 | ||
cd43d683 PT |
128 | /** |
129 | * {@inheritDoc} | |
130 | * <p> | |
131 | * This implementation sets the confidence to 100 if the trace is a valid | |
132 | * CTF trace in the "ust" domain. | |
133 | */ | |
91fc3690 | 134 | @Override |
b562a24f | 135 | public IStatus validate(final IProject project, final String path) { |
747fd87b PT |
136 | IStatus status = super.validate(project, path); |
137 | if (status instanceof CtfTraceValidationStatus) { | |
138 | Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment(); | |
dd9752d5 | 139 | /* Make sure the domain is "ust" in the trace's env vars */ |
747fd87b PT |
140 | String domain = environment.get("domain"); //$NON-NLS-1$ |
141 | if (domain == null || !domain.equals("\"ust\"")) { //$NON-NLS-1$ | |
142 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngUstTrace_DomainError); | |
dd9752d5 | 143 | } |
747fd87b | 144 | return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); |
91fc3690 | 145 | } |
747fd87b | 146 | return status; |
91fc3690 AM |
147 | } |
148 | } |