tmf: Remove the ITmfEventTableColumns extension point
[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 import java.util.Map;
18
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;
37
38 /**
39 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
40 * traces.
41 *
42 * @author Alexandre Montplaisir
43 */
44 public class LttngKernelTrace extends CtfTmfTrace {
45
46 /**
47 * Supported Linux kernel tracers
48 */
49 private enum OriginTracer {
50 LTTNG(LttngEventLayout.getInstance()),
51 LTTNG26(Lttng26EventLayout.getInstance()),
52 PERF(PerfEventLayout.getInstance());
53
54 private final @NonNull IKernelAnalysisEventLayout fLayout;
55
56 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout) {
57 fLayout = layout;
58 }
59 }
60
61 /**
62 * CTF metadata identifies trace type and tracer version pretty well, we are
63 * quite confident in the inferred trace type.
64 */
65 private static final int CONFIDENCE = 100;
66
67 /** The tracer which originated this trace */
68 private OriginTracer fOriginTracer = null;
69
70 /**
71 * Default constructor
72 */
73 public LttngKernelTrace() {
74 super();
75 }
76
77 /**
78 * Return the kernel event layout (event and field names) used in this
79 * trace.
80 *
81 * @return The event layout
82 */
83 public @NonNull IKernelAnalysisEventLayout getEventLayout() {
84 OriginTracer tracer = fOriginTracer;
85 if (tracer == null) {
86 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
87 }
88 return tracer.fLayout;
89 }
90
91 @Override
92 public void initTrace(IResource resource, String path,
93 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
94 super.initTrace(resource, path, eventType);
95
96 /*
97 * Set the 'fOriginTracer' in accordance to what is found in the
98 * metadata
99 */
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$
104
105 if ("\"perf\"".equals(tracerName)) { //$NON-NLS-1$
106 fOriginTracer = OriginTracer.PERF;
107
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;
112
113 } else {
114 fOriginTracer = OriginTracer.LTTNG;
115 }
116 }
117
118 /**
119 * {@inheritDoc}
120 * <p>
121 * This implementation sets the confidence to 100 if the trace is a valid
122 * CTF trace in the "kernel" domain.
123 */
124 @Override
125 public IStatus validate(final IProject project, final String path) {
126 /*
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".
129 */
130 try {
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);
136 }
137 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError);
138
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$
145 }
146 }
147
148 @Override
149 public Iterable<ITmfEventAspect> getEventAspects() {
150 return LttngEventAspects.getAspects();
151 }
152
153 }
This page took 0.040969 seconds and 5 git commands to generate.