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
.nio
.BufferOverflowException
;
17 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
.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
.LttngEventLayout
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.PerfEventLayout
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
37 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
38 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
40 import com
.google
.common
.collect
.ImmutableSet
;
43 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
46 * @author Alexandre Montplaisir
48 public class LttngKernelTrace
extends CtfTmfTrace
implements IKernelTrace
{
51 * Supported Linux kernel tracers
53 private enum OriginTracer
{
54 LTTNG(LttngEventLayout
.getInstance()),
55 LTTNG26(Lttng26EventLayout
.getInstance()),
56 PERF(PerfEventLayout
.getInstance());
58 private final @NonNull IKernelAnalysisEventLayout fLayout
;
60 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
66 * Event aspects available for all Lttng Kernel traces
68 private static final @NonNull Collection
<ITmfEventAspect
> LTTNG_KERNEL_ASPECTS
;
71 ImmutableSet
.Builder
<ITmfEventAspect
> builder
= ImmutableSet
.builder();
72 builder
.addAll(CtfTmfTrace
.CTF_ASPECTS
);
73 builder
.add(KernelTidAspect
.INSTANCE
);
74 LTTNG_KERNEL_ASPECTS
= NonNullUtils
.checkNotNull(builder
.build());
78 * CTF metadata identifies trace type and tracer version pretty well, we are
79 * quite confident in the inferred trace type.
81 private static final int CONFIDENCE
= 100;
83 /** The tracer which originated this trace */
84 private OriginTracer fOriginTracer
= null;
89 public LttngKernelTrace() {
94 public @NonNull IKernelAnalysisEventLayout
getKernelEventLayout() {
95 OriginTracer tracer
= fOriginTracer
;
97 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
99 return tracer
.fLayout
;
103 public void initTrace(IResource resource
, String path
,
104 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
105 super.initTrace(resource
, path
, eventType
);
108 * Set the 'fOriginTracer' in accordance to what is found in the
111 Map
<String
, String
> traceEnv
= this.getEnvironment();
112 String tracerName
= traceEnv
.get("tracer_name"); //$NON-NLS-1$
113 String tracerMajor
= traceEnv
.get("tracer_major"); //$NON-NLS-1$
114 String tracerMinor
= traceEnv
.get("tracer_minor"); //$NON-NLS-1$
116 if ("\"perf\"".equals(tracerName
)) { //$NON-NLS-1$
117 fOriginTracer
= OriginTracer
.PERF
;
119 } else if ("\"lttng-modules\"".equals(tracerName
) && //$NON-NLS-1$
120 tracerMajor
!= null && (Integer
.valueOf(tracerMajor
) >= 2) &&
121 tracerMinor
!= null && (Integer
.valueOf(tracerMinor
) >= 6)) {
122 fOriginTracer
= OriginTracer
.LTTNG26
;
125 fOriginTracer
= OriginTracer
.LTTNG
;
132 * This implementation sets the confidence to 100 if the trace is a valid
133 * CTF trace in the "kernel" domain.
136 public IStatus
validate(final IProject project
, final String path
) {
138 * Make sure the trace is openable as a CTF trace. We do this here
139 * instead of calling super.validate() to keep the reference to "temp".
141 try (CtfTmfTrace temp
= new CtfTmfTrace();) {
142 temp
.initTrace((IResource
) null, path
, CtfTmfEvent
.class);
144 /* Make sure the domain is "kernel" in the trace's env vars */
145 String dom
= temp
.getEnvironment().get("domain"); //$NON-NLS-1$
146 if (dom
!= null && dom
.equals("\"kernel\"")) { //$NON-NLS-1$
147 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
149 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
151 } catch (TmfTraceException e
) {
152 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
153 } catch (NullPointerException e
) {
154 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
155 } catch (final BufferOverflowException e
) {
156 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_TraceReadError
+ ": " + Messages
.LttngKernelTrace_MalformedTrace
); //$NON-NLS-1$
161 public Iterable
<ITmfEventAspect
> getEventAspects() {
162 return LTTNG_KERNEL_ASPECTS
;