lttng: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / lttng / 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.util.Collection;
17 import java.util.Map;
18
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelTidAspect;
25 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.ThreadPriorityAspect;
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.Lttng27EventLayout;
32 import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.LttngEventLayout;
33 import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.PerfEventLayout;
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
41 import com.google.common.collect.ImmutableSet;
42
43 /**
44 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
45 * traces.
46 *
47 * @author Alexandre Montplaisir
48 */
49 public class LttngKernelTrace extends CtfTmfTrace implements IKernelTrace {
50
51 /**
52 * Supported Linux kernel tracers
53 */
54 private enum OriginTracer {
55 LTTNG(LttngEventLayout.getInstance()),
56 LTTNG26(Lttng26EventLayout.getInstance()),
57 LTTNG27(Lttng27EventLayout.INSTANCE),
58 PERF(PerfEventLayout.getInstance());
59
60 private final @NonNull IKernelAnalysisEventLayout fLayout;
61
62 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout) {
63 fLayout = layout;
64 }
65 }
66
67 /**
68 * Event aspects available for all Lttng Kernel traces
69 */
70 private static final @NonNull Collection<ITmfEventAspect> LTTNG_KERNEL_ASPECTS;
71
72 static {
73 ImmutableSet.Builder<ITmfEventAspect> builder = ImmutableSet.builder();
74 builder.addAll(CtfTmfTrace.CTF_ASPECTS);
75 builder.add(KernelTidAspect.INSTANCE);
76 builder.add(ThreadPriorityAspect.INSTANCE);
77 LTTNG_KERNEL_ASPECTS = NonNullUtils.checkNotNull(builder.build());
78 }
79
80 /**
81 * CTF metadata identifies trace type and tracer version pretty well, we are
82 * quite confident in the inferred trace type.
83 */
84 private static final int CONFIDENCE = 100;
85
86 /** The tracer which originated this trace */
87 private OriginTracer fOriginTracer = null;
88
89 /**
90 * Default constructor
91 */
92 public LttngKernelTrace() {
93 super();
94 }
95
96 @Override
97 public @NonNull IKernelAnalysisEventLayout getKernelEventLayout() {
98 OriginTracer tracer = fOriginTracer;
99 if (tracer == null) {
100 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
101 }
102 return tracer.fLayout;
103 }
104
105 @Override
106 public void initTrace(IResource resource, String path,
107 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
108 super.initTrace(resource, path, eventType);
109 fOriginTracer = getTracerFromEnv(this.getEnvironment());
110 }
111
112 /**
113 * Identify which tracer generated a trace from its metadata.
114 */
115 private static OriginTracer getTracerFromEnv(Map<String, String> traceEnv) {
116 String tracerName = traceEnv.get("tracer_name"); //$NON-NLS-1$
117 String tracerMajor = traceEnv.get("tracer_major"); //$NON-NLS-1$
118 String tracerMinor = traceEnv.get("tracer_minor"); //$NON-NLS-1$
119
120 if ("\"perf\"".equals(tracerName)) { //$NON-NLS-1$
121 return OriginTracer.PERF;
122
123 } else if ("\"lttng-modules\"".equals(tracerName) && tracerMajor != null && tracerMinor != null) { //$NON-NLS-1$
124 /* Look for specific versions of LTTng */
125 if (Integer.valueOf(tracerMajor) >= 2) {
126 if (Integer.valueOf(tracerMinor) >= 7) {
127 return OriginTracer.LTTNG27;
128 } else if (Integer.valueOf(tracerMinor) >= 6) {
129 return OriginTracer.LTTNG26;
130 }
131 }
132 }
133
134 /* Use base LTTng layout as default */
135 return OriginTracer.LTTNG;
136 }
137
138 /**
139 * {@inheritDoc}
140 * <p>
141 * This implementation sets the confidence to 100 if the trace is a valid
142 * CTF trace in the "kernel" domain.
143 */
144 @Override
145 public IStatus validate(final IProject project, final String path) {
146 IStatus status = super.validate(project, path);
147 if (status instanceof CtfTraceValidationStatus) {
148 Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment();
149 /* Make sure the domain is "kernel" in the trace's env vars */
150 String domain = environment.get("domain"); //$NON-NLS-1$
151 if (domain == null || !domain.equals("\"kernel\"")) { //$NON-NLS-1$
152 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError);
153 }
154 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
155 }
156 return status;
157 }
158
159 @Override
160 public Iterable<ITmfEventAspect> getEventAspects() {
161 return LTTNG_KERNEL_ASPECTS;
162 }
163
164 }
This page took 0.055683 seconds and 6 git commands to generate.