1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 * Matthew Khouzam - Improved validation
12 ******************************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.trace
;
16 import java
.util
.Collection
;
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
.kernelanalysis
.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
.common
.core
.NonNullUtils
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.Activator
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.Lttng26EventLayout
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.Lttng27EventLayout
;
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
;
44 import com
.google
.common
.collect
.ImmutableSet
;
47 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
50 * @author Alexandre Montplaisir
52 public class LttngKernelTrace
extends CtfTmfTrace
implements IKernelTrace
{
55 * Supported Linux kernel tracers
57 private enum OriginTracer
{
58 LTTNG(LttngEventLayout
.getInstance()),
59 LTTNG26(Lttng26EventLayout
.getInstance()),
60 LTTNG27(Lttng27EventLayout
.INSTANCE
),
61 PERF(PerfEventLayout
.getInstance());
63 private final @NonNull IKernelAnalysisEventLayout fLayout
;
65 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
71 * Event aspects available for all Lttng Kernel traces
73 private static final @NonNull Collection
<ITmfEventAspect
> LTTNG_KERNEL_ASPECTS
;
76 ImmutableSet
.Builder
<ITmfEventAspect
> builder
= ImmutableSet
.builder();
77 builder
.addAll(CtfTmfTrace
.CTF_ASPECTS
);
78 builder
.add(KernelTidAspect
.INSTANCE
);
79 builder
.add(ThreadPriorityAspect
.INSTANCE
);
80 LTTNG_KERNEL_ASPECTS
= NonNullUtils
.checkNotNull(builder
.build());
84 * CTF metadata identifies trace type and tracer version pretty well, we are
85 * quite confident in the inferred trace type.
87 private static final int CONFIDENCE
= 100;
89 /** The tracer which originated this trace */
90 private OriginTracer fOriginTracer
= null;
95 public LttngKernelTrace() {
100 public @NonNull IKernelAnalysisEventLayout
getKernelEventLayout() {
101 OriginTracer tracer
= fOriginTracer
;
102 if (tracer
== null) {
103 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
105 return tracer
.fLayout
;
109 public void initTrace(IResource resource
, String path
,
110 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
111 super.initTrace(resource
, path
, eventType
);
112 fOriginTracer
= getTracerFromEnv();
116 * Identify which tracer generated a trace from its metadata.
118 private OriginTracer
getTracerFromEnv() {
119 String tracerName
= CtfUtils
.getTracerName(this);
120 int tracerMajor
= CtfUtils
.getTracerMajorVersion(this);
121 int tracerMinor
= CtfUtils
.getTracerMinorVersion(this);
123 if ("perf".equals(tracerName
)) { //$NON-NLS-1$
124 return OriginTracer
.PERF
;
126 } else if ("lttng-modules".equals(tracerName
)) { //$NON-NLS-1$
127 /* Look for specific versions of LTTng */
128 if (tracerMajor
>= 2) {
129 if (tracerMinor
>= 7) {
130 return OriginTracer
.LTTNG27
;
131 } else if (tracerMinor
>= 6) {
132 return OriginTracer
.LTTNG26
;
137 /* Use base LTTng layout as default */
138 return OriginTracer
.LTTNG
;
144 * This implementation sets the confidence to 100 if the trace is a valid
145 * CTF trace in the "kernel" domain.
148 public IStatus
validate(final IProject project
, final String path
) {
149 IStatus status
= super.validate(project
, path
);
150 if (status
instanceof CtfTraceValidationStatus
) {
151 Map
<String
, String
> environment
= ((CtfTraceValidationStatus
) status
).getEnvironment();
152 /* Make sure the domain is "kernel" in the trace's env vars */
153 String domain
= environment
.get("domain"); //$NON-NLS-1$
154 if (domain
== null || !domain
.equals("\"kernel\"")) { //$NON-NLS-1$
155 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
157 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
163 public Iterable
<ITmfEventAspect
> getEventAspects() {
164 return LTTNG_KERNEL_ASPECTS
;
168 * Needs explicit @NonNull generic type annotation. Can be removed once this
169 * class becomes @NonNullByDefault.
172 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
173 return super.getContainedEventTypes();