Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / lttng2 / kernel / core / trace / LttngKernelTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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 * Alexandre Montplaisir - Initial API and implementation
11 * Matthew Khouzam - Improved validation
12 ******************************************************************************/
13
14 package org.eclipse.tracecompass.lttng2.kernel.core.trace;
15
16 import java.nio.BufferOverflowException;
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.tracecompass.analysis.os.linux.core.kernelanalysis.KernelTidAspect;
26 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
27 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
28 import org.eclipse.tracecompass.common.core.NonNullUtils;
29 import org.eclipse.tracecompass.internal.lttng2.kernel.core.Activator;
30 import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.Lttng26EventLayout;
31 import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.LttngEventLayout;
32 import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.PerfEventLayout;
33 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
34 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
35 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
36 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
37 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
38 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
39
40 import com.google.common.collect.ImmutableSet;
41
42 /**
43 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
44 * traces.
45 *
46 * @author Alexandre Montplaisir
47 */
48 public class LttngKernelTrace extends CtfTmfTrace implements IKernelTrace {
49
50 /**
51 * Supported Linux kernel tracers
52 */
53 private enum OriginTracer {
54 LTTNG(LttngEventLayout.getInstance()),
55 LTTNG26(Lttng26EventLayout.getInstance()),
56 PERF(PerfEventLayout.getInstance());
57
58 private final @NonNull IKernelAnalysisEventLayout fLayout;
59
60 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout) {
61 fLayout = layout;
62 }
63 }
64
65 /**
66 * Event aspects available for all Lttng Kernel traces
67 */
68 private static final @NonNull Collection<ITmfEventAspect> LTTNG_KERNEL_ASPECTS;
69
70 static {
71 ImmutableSet.Builder<ITmfEventAspect> builder = ImmutableSet.builder();
72 builder.addAll(CtfTmfTrace.CTF_ASPECTS);
73 builder.add(KernelTidAspect.INSTANCE);
74 LTTNG_KERNEL_ASPECTS = NonNullUtils.checkNotNull(builder.build());
75 }
76
77 /**
78 * CTF metadata identifies trace type and tracer version pretty well, we are
79 * quite confident in the inferred trace type.
80 */
81 private static final int CONFIDENCE = 100;
82
83 /** The tracer which originated this trace */
84 private OriginTracer fOriginTracer = null;
85
86 /**
87 * Default constructor
88 */
89 public LttngKernelTrace() {
90 super();
91 }
92
93 @Override
94 public @NonNull IKernelAnalysisEventLayout getKernelEventLayout() {
95 OriginTracer tracer = fOriginTracer;
96 if (tracer == null) {
97 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
98 }
99 return tracer.fLayout;
100 }
101
102 @Override
103 public void initTrace(IResource resource, String path,
104 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
105 super.initTrace(resource, path, eventType);
106
107 /*
108 * Set the 'fOriginTracer' in accordance to what is found in the
109 * metadata
110 */
111 Map<String, String> traceEnv = this.getEnvironment();
112 String tracerName = traceEnv.get("tracer_name"); //$NON-NLS-1$
113 String tracerMajor = traceEnv.get("tracer_major"); //$NON-NLS-1$
114 String tracerMinor = traceEnv.get("tracer_minor"); //$NON-NLS-1$
115
116 if ("\"perf\"".equals(tracerName)) { //$NON-NLS-1$
117 fOriginTracer = OriginTracer.PERF;
118
119 } else if ("\"lttng-modules\"".equals(tracerName) && //$NON-NLS-1$
120 tracerMajor != null && (Integer.valueOf(tracerMajor) >= 2) &&
121 tracerMinor != null && (Integer.valueOf(tracerMinor) >= 6)) {
122 fOriginTracer = OriginTracer.LTTNG26;
123
124 } else {
125 fOriginTracer = OriginTracer.LTTNG;
126 }
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 "kernel" domain.
134 */
135 @Override
136 public IStatus validate(final IProject project, final String path) {
137 /*
138 * Make sure the trace is openable as a CTF trace. We do this here
139 * instead of calling super.validate() to keep the reference to "temp".
140 */
141 try (CtfTmfTrace temp = new CtfTmfTrace();) {
142 temp.initTrace((IResource) null, path, CtfTmfEvent.class);
143
144 /* Make sure the domain is "kernel" in the trace's env vars */
145 String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$
146 if (dom != null && dom.equals("\"kernel\"")) { //$NON-NLS-1$
147 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
148 }
149 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError);
150
151 } catch (TmfTraceException e) {
152 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e);
153 } catch (NullPointerException e) {
154 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e);
155 } catch (final BufferOverflowException e) {
156 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_TraceReadError + ": " + Messages.LttngKernelTrace_MalformedTrace); //$NON-NLS-1$
157 }
158 }
159
160 @Override
161 public Iterable<ITmfEventAspect> getEventAspects() {
162 return LTTNG_KERNEL_ASPECTS;
163 }
164
165 }
This page took 0.035024 seconds and 5 git commands to generate.