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
;
18 import org
.eclipse
.core
.resources
.IProject
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFReaderException
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.Activator
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.IKernelAnalysisEventLayout
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.LttngEventLayout
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
34 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
37 * @author Alexandre Montplaisir
39 public class LttngKernelTrace
extends CtfTmfTrace
{
42 * Supported Linux kernel tracers
44 private enum OriginTracer
{
45 LTTNG(LttngEventLayout
.getInstance());
47 private final @NonNull IKernelAnalysisEventLayout fLayout
;
49 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
55 * CTF metadata identifies trace type and tracer version pretty well, we are
56 * quite confident in the inferred trace type.
58 private static final int CONFIDENCE
= 100;
60 /** The tracer which originated this trace */
61 private OriginTracer fOriginTracer
= null;
66 public LttngKernelTrace() {
71 * Return the kernel event layout (event and field names) used in this
74 * @return The event layout
76 public @NonNull IKernelAnalysisEventLayout
getEventLayout() {
77 OriginTracer tracer
= fOriginTracer
;
79 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
81 return tracer
.fLayout
;
85 public void initTrace(IResource resource
, String path
,
86 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
88 * Set the 'fOriginTracer' in accordance to what is found in the
91 fOriginTracer
= OriginTracer
.LTTNG
;
93 super.initTrace(resource
, path
, eventType
);
99 * This implementation sets the confidence to 100 if the trace is a valid
100 * CTF trace in the "kernel" domain.
103 public IStatus
validate(final IProject project
, final String path
) {
105 * Make sure the trace is openable as a CTF trace. We do this here
106 * instead of calling super.validate() to keep the reference to "temp".
108 try (CTFTrace temp
= new CTFTrace(path
);) {
109 /* Make sure the domain is "kernel" in the trace's env vars */
110 String dom
= temp
.getEnvironment().get("domain"); //$NON-NLS-1$
111 if (dom
!= null && dom
.equals("\"kernel\"")) { //$NON-NLS-1$
112 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
114 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
116 } catch (CTFReaderException e
) {
117 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
118 } catch (NullPointerException e
) {
119 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.toString(), e
);
120 } catch (final BufferOverflowException e
) {
121 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_TraceReadError
+ ": " + Messages
.LttngKernelTrace_MalformedTrace
); //$NON-NLS-1$