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