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 | |
747fd87b | 17 | import java.util.Map; |
1c6660ca | 18 | |
91fc3690 | 19 | import org.eclipse.core.resources.IProject; |
7443de72 | 20 | import org.eclipse.core.resources.IResource; |
91fc3690 AM |
21 | import org.eclipse.core.runtime.IStatus; |
22 | import org.eclipse.core.runtime.Status; | |
7443de72 AM |
23 | import org.eclipse.jdt.annotation.NonNull; |
24 | import org.eclipse.jdt.annotation.Nullable; | |
9bc60be7 | 25 | import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator; |
7443de72 AM |
26 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout; |
27 | import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout; | |
28 | import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout; | |
29 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
30 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | |
2bdf0193 | 31 | import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; |
9722e5d7 | 32 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
747fd87b | 33 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; |
91fc3690 AM |
34 | |
35 | /** | |
36 | * Class to contain LTTng-UST traces | |
37 | * | |
38 | * @author Matthew Khouzam | |
91fc3690 AM |
39 | */ |
40 | public class LttngUstTrace extends CtfTmfTrace { | |
41 | ||
cd43d683 PT |
42 | private static final int CONFIDENCE = 100; |
43 | ||
7443de72 AM |
44 | private @Nullable ILttngUstEventLayout fLayout = null; |
45 | ||
91fc3690 AM |
46 | /** |
47 | * Default constructor | |
48 | */ | |
49 | public LttngUstTrace() { | |
50 | super(); | |
51 | } | |
52 | ||
7443de72 AM |
53 | /** |
54 | * Get the event layout to use with this trace. This normally depends on the | |
55 | * tracer's version. | |
56 | * | |
57 | * @return The event layout | |
58 | * @since 2.0 | |
59 | */ | |
60 | public @NonNull ILttngUstEventLayout getEventLayout() { | |
61 | ILttngUstEventLayout layout = fLayout; | |
62 | if (layout == null) { | |
63 | throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$ | |
64 | } | |
65 | return layout; | |
66 | } | |
67 | ||
68 | @Override | |
69 | public void initTrace(IResource resource, String path, | |
70 | Class<? extends ITmfEvent> eventType) throws TmfTraceException { | |
71 | super.initTrace(resource, path, eventType); | |
72 | ||
73 | /* Determine the event layout to use from the tracer's version */ | |
74 | fLayout = getLayoutFromEnv(this.getEnvironment()); | |
75 | } | |
76 | ||
77 | private static @NonNull ILttngUstEventLayout getLayoutFromEnv(Map<String, String> traceEnv) { | |
78 | String tracerName = traceEnv.get("tracer_name"); //$NON-NLS-1$ | |
79 | String tracerMajor = traceEnv.get("tracer_major"); //$NON-NLS-1$ | |
80 | String tracerMinor = traceEnv.get("tracer_minor"); //$NON-NLS-1$ | |
81 | ||
82 | if ("\"lttng-ust\"".equals(tracerName) && tracerMajor != null && tracerMinor != null) { //$NON-NLS-1$ | |
83 | if (Integer.valueOf(tracerMajor) >= 2) { | |
84 | if (Integer.valueOf(tracerMinor) >= 7) { | |
85 | return LttngUst27EventLayout.getInstance(); | |
86 | } | |
87 | return LttngUst20EventLayout.getInstance(); | |
88 | } | |
89 | } | |
90 | ||
91 | /* Fallback to the UST 2.0 layout and hope for the best */ | |
92 | return LttngUst20EventLayout.getInstance(); | |
93 | } | |
94 | ||
cd43d683 PT |
95 | /** |
96 | * {@inheritDoc} | |
97 | * <p> | |
98 | * This implementation sets the confidence to 100 if the trace is a valid | |
99 | * CTF trace in the "ust" domain. | |
100 | */ | |
91fc3690 | 101 | @Override |
b562a24f | 102 | public IStatus validate(final IProject project, final String path) { |
747fd87b PT |
103 | IStatus status = super.validate(project, path); |
104 | if (status instanceof CtfTraceValidationStatus) { | |
105 | Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment(); | |
dd9752d5 | 106 | /* Make sure the domain is "ust" in the trace's env vars */ |
747fd87b PT |
107 | String domain = environment.get("domain"); //$NON-NLS-1$ |
108 | if (domain == null || !domain.equals("\"ust\"")) { //$NON-NLS-1$ | |
109 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngUstTrace_DomainError); | |
dd9752d5 | 110 | } |
747fd87b | 111 | return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); |
91fc3690 | 112 | } |
747fd87b | 113 | return status; |
91fc3690 AM |
114 | } |
115 | } |