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
.trace
.layout
.IKernelAnalysisEventLayout
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.LttngEventLayout
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.PerfEventLayout
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.Lttng26EventLayout
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
34 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
37 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
40 * @author Alexandre Montplaisir
42 public class LttngKernelTrace
extends CtfTmfTrace
{
45 * Supported Linux kernel tracers
47 private enum OriginTracer
{
48 LTTNG(LttngEventLayout
.getInstance()),
49 LTTNG26(Lttng26EventLayout
.getInstance()),
50 PERF(PerfEventLayout
.getInstance());
52 private final @NonNull IKernelAnalysisEventLayout fLayout
;
54 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
60 * CTF metadata identifies trace type and tracer version pretty well, we are
61 * quite confident in the inferred trace type.
63 private static final int CONFIDENCE
= 100;
65 /** The tracer which originated this trace */
66 private OriginTracer fOriginTracer
= null;
71 public LttngKernelTrace() {
76 * Return the kernel event layout (event and field names) used in this
79 * @return The event layout
81 public @NonNull IKernelAnalysisEventLayout
getEventLayout() {
82 OriginTracer tracer
= fOriginTracer
;
84 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
86 return tracer
.fLayout
;
90 public void initTrace(IResource resource
, String path
,
91 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
92 super.initTrace(resource
, path
, eventType
);
95 * Set the 'fOriginTracer' in accordance to what is found in the
98 Map
<String
, String
> traceEnv
= this.getCTFTrace().getEnvironment();
99 String domain
= traceEnv
.get("domain"); //$NON-NLS-1$
100 String tracerName
= traceEnv
.get("tracer_name"); //$NON-NLS-1$
101 String tracerMajor
= traceEnv
.get("tracer_major"); //$NON-NLS-1$
102 String tracerMinor
= traceEnv
.get("tracer_minor"); //$NON-NLS-1$
104 if ("\"kernel-perf\"".equals(domain
)) { //$NON-NLS-1$
105 fOriginTracer
= OriginTracer
.PERF
;
107 } else if ("\"lttng-modules\"".equals(tracerName
) && //$NON-NLS-1$
108 tracerMajor
!= null && (Integer
.valueOf(tracerMajor
) >= 2) &&
109 tracerMinor
!= null && (Integer
.valueOf(tracerMinor
) >= 6)) {
110 fOriginTracer
= OriginTracer
.LTTNG26
;
113 fOriginTracer
= OriginTracer
.LTTNG
;
120 * This implementation sets the confidence to 100 if the trace is a valid
121 * CTF trace in the "kernel" domain.
124 public IStatus
validate(final IProject project
, final String path
) {
126 * Make sure the trace is openable as a CTF trace. We do this here
127 * instead of calling super.validate() to keep the reference to "temp".
129 try (CTFTrace temp
= new CTFTrace(path
);) {
130 /* Make sure the domain is "kernel" in the trace's env vars */
131 String dom
= temp
.getEnvironment().get("domain"); //$NON-NLS-1$
132 if (dom
!= null && dom
.startsWith("\"kernel")) { //$NON-NLS-1$
133 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
135 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
137 } catch (CTFReaderException e
) {
138 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
139 } catch (NullPointerException e
) {
140 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
141 } catch (final BufferOverflowException e
) {
142 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_TraceReadError
+ ": " + Messages
.LttngKernelTrace_MalformedTrace
); //$NON-NLS-1$