Commit | Line | Data |
---|---|---|
11d6f468 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2015 Ericsson |
11d6f468 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 | * Alexandre Montplaisir - Initial API and implementation | |
a94410d9 | 11 | * Matthew Khouzam - Improved validation |
11d6f468 AM |
12 | ******************************************************************************/ |
13 | ||
9bc60be7 | 14 | package org.eclipse.tracecompass.lttng2.kernel.core.trace; |
11d6f468 | 15 | |
312f397a | 16 | import java.util.Collection; |
acba092b | 17 | import java.util.Map; |
df2597e0 | 18 | import java.util.Set; |
11d6f468 AM |
19 | |
20 | import org.eclipse.core.resources.IProject; | |
7411cd67 | 21 | import org.eclipse.core.resources.IResource; |
a94410d9 MK |
22 | import org.eclipse.core.runtime.IStatus; |
23 | import org.eclipse.core.runtime.Status; | |
7411cd67 | 24 | import org.eclipse.jdt.annotation.NonNull; |
312f397a | 25 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelTidAspect; |
747fd87b | 26 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.ThreadPriorityAspect; |
e363eae1 AM |
27 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; |
28 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace; | |
9bc60be7 | 29 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.Activator; |
b04903a2 | 30 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.Lttng26EventLayout; |
ff5e31e0 | 31 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.Lttng27EventLayout; |
e8e92916 | 32 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.Lttng28EventLayout; |
7411cd67 | 33 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.LttngEventLayout; |
bd0e2f70 | 34 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.PerfEventLayout; |
7411cd67 | 35 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
312f397a | 36 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
7411cd67 | 37 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; |
2bdf0193 | 38 | import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; |
df2597e0 | 39 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType; |
9722e5d7 | 40 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
747fd87b | 41 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; |
542ddfb3 | 42 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils; |
11d6f468 | 43 | |
312f397a GB |
44 | import com.google.common.collect.ImmutableSet; |
45 | ||
11d6f468 AM |
46 | /** |
47 | * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel | |
4bc53929 | 48 | * traces. |
d85d2a6d | 49 | * |
2cb26548 | 50 | * @author Alexandre Montplaisir |
11d6f468 | 51 | */ |
e363eae1 | 52 | public class LttngKernelTrace extends CtfTmfTrace implements IKernelTrace { |
11d6f468 | 53 | |
7411cd67 AM |
54 | /** |
55 | * Supported Linux kernel tracers | |
56 | */ | |
57 | private enum OriginTracer { | |
acba092b | 58 | LTTNG(LttngEventLayout.getInstance()), |
bd0e2f70 | 59 | LTTNG26(Lttng26EventLayout.getInstance()), |
e8e92916 FG |
60 | LTTNG27(Lttng27EventLayout.getInstance()), |
61 | LTTNG28(Lttng28EventLayout.getInstance()), | |
bd0e2f70 | 62 | PERF(PerfEventLayout.getInstance()); |
7411cd67 AM |
63 | |
64 | private final @NonNull IKernelAnalysisEventLayout fLayout; | |
65 | ||
66 | private OriginTracer(@NonNull IKernelAnalysisEventLayout layout) { | |
67 | fLayout = layout; | |
68 | } | |
69 | } | |
70 | ||
312f397a GB |
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); | |
9049e763 | 79 | builder.add(KernelTidAspect.INSTANCE); |
2531b10a | 80 | builder.add(ThreadPriorityAspect.INSTANCE); |
0e4f957e | 81 | LTTNG_KERNEL_ASPECTS = builder.build(); |
312f397a GB |
82 | } |
83 | ||
7411cd67 AM |
84 | /** |
85 | * CTF metadata identifies trace type and tracer version pretty well, we are | |
86 | * quite confident in the inferred trace type. | |
87 | */ | |
cd43d683 PT |
88 | private static final int CONFIDENCE = 100; |
89 | ||
7411cd67 AM |
90 | /** The tracer which originated this trace */ |
91 | private OriginTracer fOriginTracer = null; | |
92 | ||
d85d2a6d AM |
93 | /** |
94 | * Default constructor | |
95 | */ | |
d3ba47d4 | 96 | public LttngKernelTrace() { |
11d6f468 AM |
97 | super(); |
98 | } | |
99 | ||
e363eae1 AM |
100 | @Override |
101 | public @NonNull IKernelAnalysisEventLayout getKernelEventLayout() { | |
7411cd67 AM |
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 { | |
acba092b | 112 | super.initTrace(resource, path, eventType); |
542ddfb3 | 113 | fOriginTracer = getTracerFromEnv(); |
ff5e31e0 | 114 | } |
acba092b | 115 | |
ff5e31e0 SL |
116 | /** |
117 | * Identify which tracer generated a trace from its metadata. | |
118 | */ | |
542ddfb3 AM |
119 | private OriginTracer getTracerFromEnv() { |
120 | String tracerName = CtfUtils.getTracerName(this); | |
121 | int tracerMajor = CtfUtils.getTracerMajorVersion(this); | |
122 | int tracerMinor = CtfUtils.getTracerMinorVersion(this); | |
7411cd67 | 123 | |
542ddfb3 | 124 | if ("perf".equals(tracerName)) { //$NON-NLS-1$ |
ff5e31e0 SL |
125 | return OriginTracer.PERF; |
126 | ||
542ddfb3 | 127 | } else if ("lttng-modules".equals(tracerName)) { //$NON-NLS-1$ |
ff5e31e0 | 128 | /* Look for specific versions of LTTng */ |
542ddfb3 | 129 | if (tracerMajor >= 2) { |
e8e92916 FG |
130 | if (tracerMinor >= 8) { |
131 | return OriginTracer.LTTNG28; | |
132 | } else if (tracerMinor >= 7) { | |
ff5e31e0 | 133 | return OriginTracer.LTTNG27; |
542ddfb3 | 134 | } else if (tracerMinor >= 6) { |
ff5e31e0 SL |
135 | return OriginTracer.LTTNG26; |
136 | } | |
137 | } | |
acba092b | 138 | } |
ff5e31e0 SL |
139 | |
140 | /* Use base LTTng layout as default */ | |
141 | return OriginTracer.LTTNG; | |
7411cd67 AM |
142 | } |
143 | ||
a94410d9 | 144 | /** |
cd43d683 PT |
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. | |
a94410d9 | 149 | */ |
11d6f468 | 150 | @Override |
dd9752d5 | 151 | public IStatus validate(final IProject project, final String path) { |
747fd87b PT |
152 | IStatus status = super.validate(project, path); |
153 | if (status instanceof CtfTraceValidationStatus) { | |
154 | Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment(); | |
dd9752d5 | 155 | /* Make sure the domain is "kernel" in the trace's env vars */ |
747fd87b PT |
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); | |
dd9752d5 | 159 | } |
747fd87b | 160 | return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); |
7c60c8b4 | 161 | } |
747fd87b | 162 | return status; |
11d6f468 AM |
163 | } |
164 | ||
312f397a GB |
165 | @Override |
166 | public Iterable<ITmfEventAspect> getEventAspects() { | |
167 | return LTTNG_KERNEL_ASPECTS; | |
168 | } | |
169 | ||
df2597e0 AM |
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 | ||
11d6f468 | 179 | } |