lttng: Add interface to abstract the event layout away
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / lttng2 / kernel / core / trace / LttngKernelTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 * Matthew Khouzam - Improved validation
12 ******************************************************************************/
13
14 package org.eclipse.tracecompass.lttng2.kernel.core.trace;
15
16 import java.nio.BufferOverflowException;
17
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;
32
33 /**
34 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
35 * traces.
36 *
37 * @author Alexandre Montplaisir
38 */
39 public class LttngKernelTrace extends CtfTmfTrace {
40
41 /**
42 * Supported Linux kernel tracers
43 */
44 private enum OriginTracer {
45 LTTNG(LttngEventLayout.getInstance());
46
47 private final @NonNull IKernelAnalysisEventLayout fLayout;
48
49 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout) {
50 fLayout = layout;
51 }
52 }
53
54 /**
55 * CTF metadata identifies trace type and tracer version pretty well, we are
56 * quite confident in the inferred trace type.
57 */
58 private static final int CONFIDENCE = 100;
59
60 /** The tracer which originated this trace */
61 private OriginTracer fOriginTracer = null;
62
63 /**
64 * Default constructor
65 */
66 public LttngKernelTrace() {
67 super();
68 }
69
70 /**
71 * Return the kernel event layout (event and field names) used in this
72 * trace.
73 *
74 * @return The event layout
75 */
76 public @NonNull IKernelAnalysisEventLayout getEventLayout() {
77 OriginTracer tracer = fOriginTracer;
78 if (tracer == null) {
79 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
80 }
81 return tracer.fLayout;
82 }
83
84 @Override
85 public void initTrace(IResource resource, String path,
86 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
87 /*
88 * Set the 'fOriginTracer' in accordance to what is found in the
89 * metadata
90 */
91 fOriginTracer = OriginTracer.LTTNG;
92
93 super.initTrace(resource, path, eventType);
94 }
95
96 /**
97 * {@inheritDoc}
98 * <p>
99 * This implementation sets the confidence to 100 if the trace is a valid
100 * CTF trace in the "kernel" domain.
101 */
102 @Override
103 public IStatus validate(final IProject project, final String path) {
104 /*
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".
107 */
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);
113 }
114 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError);
115
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$
122 }
123 }
124
125 }
This page took 0.033672 seconds and 5 git commands to generate.