lttng: Add utility methods to get CTF tracer versions
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / trace / LttngUstTrace.java
1 /**********************************************************************
2 * Copyright (c) 2013, 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 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Add UST callstack state system
12 * Marc-Andre Laperle - Handle BufferOverflowException (Bug 420203)
13 **********************************************************************/
14
15 package org.eclipse.tracecompass.lttng2.ust.core.trace;
16
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.jdt.annotation.Nullable;
25 import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator;
26 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout;
27 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout;
28 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
29 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
30 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
31 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
32 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
33 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus;
34 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils;
35
36 /**
37 * Class to contain LTTng-UST traces
38 *
39 * @author Matthew Khouzam
40 */
41 public class LttngUstTrace extends CtfTmfTrace {
42
43 private static final int CONFIDENCE = 100;
44
45 private @Nullable ILttngUstEventLayout fLayout = null;
46
47 /**
48 * Default constructor
49 */
50 public LttngUstTrace() {
51 super();
52 }
53
54 /**
55 * Get the event layout to use with this trace. This normally depends on the
56 * tracer's version.
57 *
58 * @return The event layout
59 * @since 2.0
60 */
61 public @NonNull ILttngUstEventLayout getEventLayout() {
62 ILttngUstEventLayout layout = fLayout;
63 if (layout == null) {
64 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
65 }
66 return layout;
67 }
68
69 @Override
70 public void initTrace(IResource resource, String path,
71 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
72 super.initTrace(resource, path, eventType);
73
74 /* Determine the event layout to use from the tracer's version */
75 fLayout = getLayoutFromEnv();
76 }
77
78 private @NonNull ILttngUstEventLayout getLayoutFromEnv() {
79 String tracerName = CtfUtils.getTracerName(this);
80 int tracerMajor = CtfUtils.getTracerMajorVersion(this);
81 int tracerMinor = CtfUtils.getTracerMinorVersion(this);
82
83 if ("lttng-ust".equals(tracerName)) { //$NON-NLS-1$
84 if (tracerMajor >= 2) {
85 if (tracerMinor >= 7) {
86 return LttngUst27EventLayout.getInstance();
87 }
88 return LttngUst20EventLayout.getInstance();
89 }
90 }
91
92 /* Fallback to the UST 2.0 layout and hope for the best */
93 return LttngUst20EventLayout.getInstance();
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 "ust" domain.
101 */
102 @Override
103 public IStatus validate(final IProject project, final String path) {
104 IStatus status = super.validate(project, path);
105 if (status instanceof CtfTraceValidationStatus) {
106 Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment();
107 /* Make sure the domain is "ust" in the trace's env vars */
108 String domain = environment.get("domain"); //$NON-NLS-1$
109 if (domain == null || !domain.equals("\"ust\"")) { //$NON-NLS-1$
110 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngUstTrace_DomainError);
111 }
112 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
113 }
114 return status;
115 }
116 }
This page took 0.037383 seconds and 6 git commands to generate.