1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFReaderException
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.Activator
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.aspect
.LttngEventAspects
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.IKernelAnalysisEventLayout
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.Lttng26EventLayout
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.LttngEventLayout
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.PerfEventLayout
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
36 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
39 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
42 * @author Alexandre Montplaisir
44 public class LttngKernelTrace
extends CtfTmfTrace
{
47 * Supported Linux kernel tracers
49 private enum OriginTracer
{
50 LTTNG(LttngEventLayout
.getInstance()),
51 LTTNG26(Lttng26EventLayout
.getInstance()),
52 PERF(PerfEventLayout
.getInstance());
54 private final @NonNull IKernelAnalysisEventLayout fLayout
;
56 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
62 * CTF metadata identifies trace type and tracer version pretty well, we are
63 * quite confident in the inferred trace type.
65 private static final int CONFIDENCE
= 100;
67 /** The tracer which originated this trace */
68 private OriginTracer fOriginTracer
= null;
73 public LttngKernelTrace() {
78 * Return the kernel event layout (event and field names) used in this
81 * @return The event layout
83 public @NonNull IKernelAnalysisEventLayout
getEventLayout() {
84 OriginTracer tracer
= fOriginTracer
;
86 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
88 return tracer
.fLayout
;
92 public void initTrace(IResource resource
, String path
,
93 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
94 super.initTrace(resource
, path
, eventType
);
97 * Set the 'fOriginTracer' in accordance to what is found in the
100 Map
<String
, String
> traceEnv
= this.getCTFTrace().getEnvironment();
101 String tracerName
= traceEnv
.get("tracer_name"); //$NON-NLS-1$
102 String tracerMajor
= traceEnv
.get("tracer_major"); //$NON-NLS-1$
103 String tracerMinor
= traceEnv
.get("tracer_minor"); //$NON-NLS-1$
105 if ("\"perf\"".equals(tracerName
)) { //$NON-NLS-1$
106 fOriginTracer
= OriginTracer
.PERF
;
108 } else if ("\"lttng-modules\"".equals(tracerName
) && //$NON-NLS-1$
109 tracerMajor
!= null && (Integer
.valueOf(tracerMajor
) >= 2) &&
110 tracerMinor
!= null && (Integer
.valueOf(tracerMinor
) >= 6)) {
111 fOriginTracer
= OriginTracer
.LTTNG26
;
114 fOriginTracer
= OriginTracer
.LTTNG
;
121 * This implementation sets the confidence to 100 if the trace is a valid
122 * CTF trace in the "kernel" domain.
125 public IStatus
validate(final IProject project
, final String path
) {
127 * Make sure the trace is openable as a CTF trace. We do this here
128 * instead of calling super.validate() to keep the reference to "temp".
131 CTFTrace temp
= new CTFTrace(path
);
132 /* Make sure the domain is "kernel" in the trace's env vars */
133 String dom
= temp
.getEnvironment().get("domain"); //$NON-NLS-1$
134 if (dom
!= null && dom
.equals("\"kernel\"")) { //$NON-NLS-1$
135 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
137 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
139 } catch (CTFReaderException e
) {
140 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
141 } catch (NullPointerException e
) {
142 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
143 } catch (final BufferOverflowException e
) {
144 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_TraceReadError
+ ": " + Messages
.LttngKernelTrace_MalformedTrace
); //$NON-NLS-1$
149 public Iterable
<ITmfEventAspect
> getEventAspects() {
150 return LttngEventAspects
.getAspects();