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
.kernel
.KernelTidAspect
;
26 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.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
;
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
.getInstance()),
61 LTTNG28(Lttng28EventLayout
.getInstance()),
62 PERF(PerfEventLayout
.getInstance());
64 private final @NonNull IKernelAnalysisEventLayout fLayout
;
66 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
72 * Event aspects available for all Lttng Kernel traces
74 private static final @NonNull Collection
<ITmfEventAspect
> LTTNG_KERNEL_ASPECTS
;
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();
85 * CTF metadata identifies trace type and tracer version pretty well, we are
86 * quite confident in the inferred trace type.
88 private static final int CONFIDENCE
= 100;
90 /** The tracer which originated this trace */
91 private OriginTracer fOriginTracer
= null;
96 public LttngKernelTrace() {
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$
106 return tracer
.fLayout
;
110 public void initTrace(IResource resource
, String path
,
111 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
112 super.initTrace(resource
, path
, eventType
);
113 fOriginTracer
= getTracerFromEnv();
117 * Identify which tracer generated a trace from its metadata.
119 private OriginTracer
getTracerFromEnv() {
120 String tracerName
= CtfUtils
.getTracerName(this);
121 int tracerMajor
= CtfUtils
.getTracerMajorVersion(this);
122 int tracerMinor
= CtfUtils
.getTracerMinorVersion(this);
124 if ("perf".equals(tracerName
)) { //$NON-NLS-1$
125 return OriginTracer
.PERF
;
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
;
140 /* Use base LTTng layout as default */
141 return OriginTracer
.LTTNG
;
147 * This implementation sets the confidence to 100 if the trace is a valid
148 * CTF trace in the "kernel" domain.
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
);
160 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
166 public Iterable
<ITmfEventAspect
> getEventAspects() {
167 return LTTNG_KERNEL_ASPECTS
;
171 * Needs explicit @NonNull generic type annotation. Can be removed once this
172 * class becomes @NonNullByDefault.
175 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
176 return super.getContainedEventTypes();