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