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
.ThreadPriorityAspect
;
26 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelTidAspect
;
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
.LttngEventLayout
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.PerfEventLayout
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
38 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
39 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
41 import com
.google
.common
.collect
.ImmutableSet
;
44 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
47 * @author Alexandre Montplaisir
49 public class LttngKernelTrace
extends CtfTmfTrace
implements IKernelTrace
{
52 * Supported Linux kernel tracers
54 private enum OriginTracer
{
55 LTTNG(LttngEventLayout
.getInstance()),
56 LTTNG26(Lttng26EventLayout
.getInstance()),
57 PERF(PerfEventLayout
.getInstance());
59 private final @NonNull IKernelAnalysisEventLayout fLayout
;
61 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
67 * Event aspects available for all Lttng Kernel traces
69 private static final @NonNull Collection
<ITmfEventAspect
> LTTNG_KERNEL_ASPECTS
;
72 ImmutableSet
.Builder
<ITmfEventAspect
> builder
= ImmutableSet
.builder();
73 builder
.addAll(CtfTmfTrace
.CTF_ASPECTS
);
74 builder
.add(KernelTidAspect
.INSTANCE
);
75 builder
.add(ThreadPriorityAspect
.INSTANCE
);
76 LTTNG_KERNEL_ASPECTS
= NonNullUtils
.checkNotNull(builder
.build());
80 * CTF metadata identifies trace type and tracer version pretty well, we are
81 * quite confident in the inferred trace type.
83 private static final int CONFIDENCE
= 100;
85 /** The tracer which originated this trace */
86 private OriginTracer fOriginTracer
= null;
91 public LttngKernelTrace() {
96 public @NonNull IKernelAnalysisEventLayout
getKernelEventLayout() {
97 OriginTracer tracer
= fOriginTracer
;
99 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
101 return tracer
.fLayout
;
105 public void initTrace(IResource resource
, String path
,
106 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
107 super.initTrace(resource
, path
, eventType
);
110 * Set the 'fOriginTracer' in accordance to what is found in the
113 Map
<String
, String
> traceEnv
= this.getEnvironment();
114 String tracerName
= traceEnv
.get("tracer_name"); //$NON-NLS-1$
115 String tracerMajor
= traceEnv
.get("tracer_major"); //$NON-NLS-1$
116 String tracerMinor
= traceEnv
.get("tracer_minor"); //$NON-NLS-1$
118 if ("\"perf\"".equals(tracerName
)) { //$NON-NLS-1$
119 fOriginTracer
= OriginTracer
.PERF
;
121 } else if ("\"lttng-modules\"".equals(tracerName
) && //$NON-NLS-1$
122 tracerMajor
!= null && (Integer
.valueOf(tracerMajor
) >= 2) &&
123 tracerMinor
!= null && (Integer
.valueOf(tracerMinor
) >= 6)) {
124 fOriginTracer
= OriginTracer
.LTTNG26
;
127 fOriginTracer
= OriginTracer
.LTTNG
;
134 * This implementation sets the confidence to 100 if the trace is a valid
135 * CTF trace in the "kernel" domain.
138 public IStatus
validate(final IProject project
, final String path
) {
140 * Make sure the trace is openable as a CTF trace. We do this here
141 * instead of calling super.validate() to keep the reference to "temp".
143 try (CtfTmfTrace temp
= new CtfTmfTrace();) {
144 temp
.initTrace((IResource
) null, path
, CtfTmfEvent
.class);
146 /* Make sure the domain is "kernel" in the trace's env vars */
147 String dom
= temp
.getEnvironment().get("domain"); //$NON-NLS-1$
148 if (dom
!= null && dom
.equals("\"kernel\"")) { //$NON-NLS-1$
149 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
151 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
153 } catch (TmfTraceException e
) {
154 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
155 } catch (NullPointerException e
) {
156 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
157 } catch (final BufferOverflowException e
) {
158 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_TraceReadError
+ ": " + Messages
.LttngKernelTrace_MalformedTrace
); //$NON-NLS-1$
163 public Iterable
<ITmfEventAspect
> getEventAspects() {
164 return LTTNG_KERNEL_ASPECTS
;