ctf: Assign a CtfTmfEventFactory to each trace
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / trace / LttngUstTrace.java
CommitLineData
91fc3690 1/**********************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
91fc3690
AM
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
1c6660ca 11 * Alexandre Montplaisir - Add UST callstack state system
af015d44 12 * Marc-Andre Laperle - Handle BufferOverflowException (Bug 420203)
91fc3690
AM
13 **********************************************************************/
14
9bc60be7 15package org.eclipse.tracecompass.lttng2.ust.core.trace;
91fc3690 16
ef7f180d 17import java.util.Collection;
747fd87b 18import java.util.Map;
1c6660ca 19
91fc3690 20import org.eclipse.core.resources.IProject;
7443de72 21import org.eclipse.core.resources.IResource;
91fc3690
AM
22import org.eclipse.core.runtime.IStatus;
23import org.eclipse.core.runtime.Status;
7443de72
AM
24import org.eclipse.jdt.annotation.NonNull;
25import org.eclipse.jdt.annotation.Nullable;
ef7f180d 26import org.eclipse.tracecompass.common.core.NonNullUtils;
9bc60be7 27import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator;
7443de72
AM
28import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout;
29import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout;
ef7f180d
AM
30import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst28EventLayout;
31import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoAspect;
7443de72
AM
32import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
33import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
ef7f180d 34import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
7443de72 35import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
2bdf0193 36import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
9722e5d7 37import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
747fd87b 38import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus;
542ddfb3 39import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils;
91fc3690 40
ef7f180d
AM
41import com.google.common.collect.ImmutableSet;
42
91fc3690
AM
43/**
44 * Class to contain LTTng-UST traces
45 *
46 * @author Matthew Khouzam
91fc3690
AM
47 */
48public class LttngUstTrace extends CtfTmfTrace {
49
ef7f180d
AM
50 /**
51 * Name of the tracer that generates this trace type, as found in the CTF
52 * metadata.
53 *
54 * @since 2.0
55 */
56 public static final String TRACER_NAME = "lttng-ust"; //$NON-NLS-1$
57
cd43d683
PT
58 private static final int CONFIDENCE = 100;
59
ef7f180d
AM
60 private static final @NonNull Collection<ITmfEventAspect> LTTNG_UST_ASPECTS;
61
62 static {
63 ImmutableSet.Builder<ITmfEventAspect> builder = ImmutableSet.builder();
64 builder.addAll(CtfTmfTrace.CTF_ASPECTS);
65 builder.add(UstDebugInfoAspect.INSTANCE);
66 LTTNG_UST_ASPECTS = NonNullUtils.checkNotNull(builder.build());
67 }
68
7443de72
AM
69 private @Nullable ILttngUstEventLayout fLayout = null;
70
91fc3690
AM
71 /**
72 * Default constructor
73 */
74 public LttngUstTrace() {
75 super();
76 }
77
7443de72
AM
78 /**
79 * Get the event layout to use with this trace. This normally depends on the
80 * tracer's version.
81 *
82 * @return The event layout
83 * @since 2.0
84 */
85 public @NonNull ILttngUstEventLayout getEventLayout() {
86 ILttngUstEventLayout layout = fLayout;
87 if (layout == null) {
88 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
89 }
90 return layout;
91 }
92
93 @Override
94 public void initTrace(IResource resource, String path,
95 Class<? extends ITmfEvent> eventType) throws TmfTraceException {
96 super.initTrace(resource, path, eventType);
97
98 /* Determine the event layout to use from the tracer's version */
542ddfb3 99 fLayout = getLayoutFromEnv();
7443de72
AM
100 }
101
542ddfb3
AM
102 private @NonNull ILttngUstEventLayout getLayoutFromEnv() {
103 String tracerName = CtfUtils.getTracerName(this);
104 int tracerMajor = CtfUtils.getTracerMajorVersion(this);
105 int tracerMinor = CtfUtils.getTracerMinorVersion(this);
7443de72 106
ef7f180d 107 if (TRACER_NAME.equals(tracerName)) {
542ddfb3 108 if (tracerMajor >= 2) {
ef7f180d
AM
109 if (tracerMinor >= 8) {
110 return LttngUst28EventLayout.getInstance();
111 } else if (tracerMinor >= 7) {
7443de72
AM
112 return LttngUst27EventLayout.getInstance();
113 }
114 return LttngUst20EventLayout.getInstance();
115 }
116 }
117
118 /* Fallback to the UST 2.0 layout and hope for the best */
119 return LttngUst20EventLayout.getInstance();
120 }
121
ef7f180d
AM
122 @Override
123 public Iterable<ITmfEventAspect> getEventAspects() {
124 return LTTNG_UST_ASPECTS;
125 }
126
cd43d683
PT
127 /**
128 * {@inheritDoc}
129 * <p>
130 * This implementation sets the confidence to 100 if the trace is a valid
131 * CTF trace in the "ust" domain.
132 */
91fc3690 133 @Override
b562a24f 134 public IStatus validate(final IProject project, final String path) {
747fd87b
PT
135 IStatus status = super.validate(project, path);
136 if (status instanceof CtfTraceValidationStatus) {
137 Map<String, String> environment = ((CtfTraceValidationStatus) status).getEnvironment();
dd9752d5 138 /* Make sure the domain is "ust" in the trace's env vars */
747fd87b
PT
139 String domain = environment.get("domain"); //$NON-NLS-1$
140 if (domain == null || !domain.equals("\"ust\"")) { //$NON-NLS-1$
141 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngUstTrace_DomainError);
dd9752d5 142 }
747fd87b 143 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
91fc3690 144 }
747fd87b 145 return status;
91fc3690
AM
146 }
147}
This page took 0.062095 seconds and 5 git commands to generate.