lttng: Add a ILttngUstEventLayout
[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
35 /**
36 * Class to contain LTTng-UST traces
37 *
38 * @author Matthew Khouzam
39 */
40 public class LttngUstTrace extends CtfTmfTrace {
41
42 private static final int CONFIDENCE = 100;
43
44 private @Nullable ILttngUstEventLayout fLayout = null;
45
46 /**
47 * Default constructor
48 */
49 public LttngUstTrace() {
50 super();
51 }
52
53 /**
54 * Get the event layout to use with this trace. This normally depends on the
55 * tracer's version.
56 *
57 * @return The event layout
58 * @since 2.0
59 */
60 public @NonNull ILttngUstEventLayout getEventLayout() {
61 ILttngUstEventLayout layout = fLayout;
62 if (layout == null) {
63 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
64 }
65 return layout;
66 }
67
68 @Override
69 public void initTrace(IResource resource, String path,
70 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
71 super.initTrace(resource, path, eventType);
72
73 /* Determine the event layout to use from the tracer's version */
74 fLayout = getLayoutFromEnv(this.getEnvironment());
75 }
76
77 private static @NonNull ILttngUstEventLayout getLayoutFromEnv(Map<String, String> traceEnv) {
78 String tracerName = traceEnv.get("tracer_name"); //$NON-NLS-1$
79 String tracerMajor = traceEnv.get("tracer_major"); //$NON-NLS-1$
80 String tracerMinor = traceEnv.get("tracer_minor"); //$NON-NLS-1$
81
82 if ("\"lttng-ust\"".equals(tracerName) && tracerMajor != null && tracerMinor != null) { //$NON-NLS-1$
83 if (Integer.valueOf(tracerMajor) >= 2) {
84 if (Integer.valueOf(tracerMinor) >= 7) {
85 return LttngUst27EventLayout.getInstance();
86 }
87 return LttngUst20EventLayout.getInstance();
88 }
89 }
90
91 /* Fallback to the UST 2.0 layout and hope for the best */
92 return LttngUst20EventLayout.getInstance();
93 }
94
95 /**
96 * {@inheritDoc}
97 * <p>
98 * This implementation sets the confidence to 100 if the trace is a valid
99 * CTF trace in the "ust" domain.
100 */
101 @Override
102 public IStatus validate(final IProject project, final String path) {
103 IStatus status = super.validate(project, path);
104 if (status instanceof CtfTraceValidationStatus) {
105 Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment();
106 /* Make sure the domain is "ust" in the trace's env vars */
107 String domain = environment.get("domain"); //$NON-NLS-1$
108 if (domain == null || !domain.equals("\"ust\"")) { //$NON-NLS-1$
109 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngUstTrace_DomainError);
110 }
111 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
112 }
113 return status;
114 }
115 }
This page took 0.033959 seconds and 6 git commands to generate.