Commit | Line | Data |
---|---|---|
11d6f468 | 1 | /******************************************************************************* |
cd43d683 | 2 | * Copyright (c) 2012, 2014 Ericsson |
11d6f468 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 | * Alexandre Montplaisir - Initial API and implementation | |
a94410d9 | 11 | * Matthew Khouzam - Improved validation |
11d6f468 AM |
12 | ******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.lttng2.kernel.core.trace; | |
15 | ||
96c0f2af | 16 | import java.nio.BufferOverflowException; |
11d6f468 AM |
17 | |
18 | import org.eclipse.core.resources.IProject; | |
a94410d9 MK |
19 | import org.eclipse.core.runtime.IStatus; |
20 | import org.eclipse.core.runtime.Status; | |
7c60c8b4 AM |
21 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
22 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; | |
a94410d9 | 23 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Activator; |
cd43d683 | 24 | import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus; |
91e7f946 | 25 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; |
11d6f468 AM |
26 | |
27 | /** | |
28 | * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel | |
4bc53929 | 29 | * traces. |
d85d2a6d | 30 | * |
2cb26548 | 31 | * @author Alexandre Montplaisir |
d3ba47d4 | 32 | * @since 2.0 |
11d6f468 | 33 | */ |
d3ba47d4 | 34 | public class LttngKernelTrace extends CtfTmfTrace { |
11d6f468 | 35 | |
cd43d683 PT |
36 | private static final int CONFIDENCE = 100; |
37 | ||
d85d2a6d AM |
38 | /** |
39 | * Default constructor | |
40 | */ | |
d3ba47d4 | 41 | public LttngKernelTrace() { |
11d6f468 AM |
42 | super(); |
43 | } | |
44 | ||
a94410d9 | 45 | /** |
cd43d683 PT |
46 | * {@inheritDoc} |
47 | * <p> | |
48 | * This implementation sets the confidence to 100 if the trace is a valid | |
49 | * CTF trace in the "kernel" domain. | |
a94410d9 | 50 | */ |
11d6f468 | 51 | @Override |
dd9752d5 | 52 | public IStatus validate(final IProject project, final String path) { |
7c60c8b4 AM |
53 | /* |
54 | * Make sure the trace is openable as a CTF trace. We do this here | |
55 | * instead of calling super.validate() to keep the reference to "temp". | |
56 | */ | |
dd9752d5 AM |
57 | try (CTFTrace temp = new CTFTrace(path);) { |
58 | /* Make sure the domain is "kernel" in the trace's env vars */ | |
59 | String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$ | |
60 | if (dom != null && dom.equals("\"kernel\"")) { //$NON-NLS-1$ | |
61 | return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); | |
62 | } | |
63 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError); | |
64 | ||
7c60c8b4 | 65 | } catch (CTFReaderException e) { |
dd9752d5 AM |
66 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e); |
67 | } catch (NullPointerException e) { | |
68 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e); | |
96c0f2af | 69 | } catch (final BufferOverflowException e) { |
dd9752d5 | 70 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_TraceReadError + ": " + Messages.LttngKernelTrace_MalformedTrace); //$NON-NLS-1$ |
7c60c8b4 | 71 | } |
11d6f468 AM |
72 | } |
73 | ||
11d6f468 | 74 | } |