1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 * Matthew Khouzam - Improved validation
12 ******************************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.trace
;
16 import java
.util
.Collection
;
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
.analysis
.os
.linux
.core
.kernelanalysis
.KernelTidAspect
;
25 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.ThreadPriorityAspect
;
26 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
27 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelTrace
;
28 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.Activator
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.Lttng26EventLayout
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.Lttng27EventLayout
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.LttngEventLayout
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.trace
.layout
.PerfEventLayout
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
38 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
39 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTraceValidationStatus
;
41 import com
.google
.common
.collect
.ImmutableSet
;
44 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
47 * @author Alexandre Montplaisir
49 public class LttngKernelTrace
extends CtfTmfTrace
implements IKernelTrace
{
52 * Supported Linux kernel tracers
54 private enum OriginTracer
{
55 LTTNG(LttngEventLayout
.getInstance()),
56 LTTNG26(Lttng26EventLayout
.getInstance()),
57 LTTNG27(Lttng27EventLayout
.INSTANCE
),
58 PERF(PerfEventLayout
.getInstance());
60 private final @NonNull IKernelAnalysisEventLayout fLayout
;
62 private OriginTracer(@NonNull IKernelAnalysisEventLayout layout
) {
68 * Event aspects available for all Lttng Kernel traces
70 private static final @NonNull Collection
<ITmfEventAspect
> LTTNG_KERNEL_ASPECTS
;
73 ImmutableSet
.Builder
<ITmfEventAspect
> builder
= ImmutableSet
.builder();
74 builder
.addAll(CtfTmfTrace
.CTF_ASPECTS
);
75 builder
.add(KernelTidAspect
.INSTANCE
);
76 builder
.add(ThreadPriorityAspect
.INSTANCE
);
77 LTTNG_KERNEL_ASPECTS
= NonNullUtils
.checkNotNull(builder
.build());
81 * CTF metadata identifies trace type and tracer version pretty well, we are
82 * quite confident in the inferred trace type.
84 private static final int CONFIDENCE
= 100;
86 /** The tracer which originated this trace */
87 private OriginTracer fOriginTracer
= null;
92 public LttngKernelTrace() {
97 public @NonNull IKernelAnalysisEventLayout
getKernelEventLayout() {
98 OriginTracer tracer
= fOriginTracer
;
100 throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
102 return tracer
.fLayout
;
106 public void initTrace(IResource resource
, String path
,
107 Class
<?
extends ITmfEvent
> eventType
) throws TmfTraceException
{
108 super.initTrace(resource
, path
, eventType
);
109 fOriginTracer
= getTracerFromEnv(this.getEnvironment());
113 * Identify which tracer generated a trace from its metadata.
115 private static OriginTracer
getTracerFromEnv(Map
<String
, String
> traceEnv
) {
116 String tracerName
= traceEnv
.get("tracer_name"); //$NON-NLS-1$
117 String tracerMajor
= traceEnv
.get("tracer_major"); //$NON-NLS-1$
118 String tracerMinor
= traceEnv
.get("tracer_minor"); //$NON-NLS-1$
120 if ("\"perf\"".equals(tracerName
)) { //$NON-NLS-1$
121 return OriginTracer
.PERF
;
123 } else if ("\"lttng-modules\"".equals(tracerName
) && tracerMajor
!= null && tracerMinor
!= null) { //$NON-NLS-1$
124 /* Look for specific versions of LTTng */
125 if (Integer
.valueOf(tracerMajor
) >= 2) {
126 if (Integer
.valueOf(tracerMinor
) >= 7) {
127 return OriginTracer
.LTTNG27
;
128 } else if (Integer
.valueOf(tracerMinor
) >= 6) {
129 return OriginTracer
.LTTNG26
;
134 /* Use base LTTng layout as default */
135 return OriginTracer
.LTTNG
;
141 * This implementation sets the confidence to 100 if the trace is a valid
142 * CTF trace in the "kernel" domain.
145 public IStatus
validate(final IProject project
, final String path
) {
146 IStatus status
= super.validate(project
, path
);
147 if (status
instanceof CtfTraceValidationStatus
) {
148 Map
<String
, String
> environment
= ((CtfTraceValidationStatus
) status
).getEnvironment();
149 /* Make sure the domain is "kernel" in the trace's env vars */
150 String domain
= environment
.get("domain"); //$NON-NLS-1$
151 if (domain
== null || !domain
.equals("\"kernel\"")) { //$NON-NLS-1$
152 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.LttngKernelTrace_DomainError
);
154 return new TraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
);
160 public Iterable
<ITmfEventAspect
> getEventAspects() {
161 return LTTNG_KERNEL_ASPECTS
;