Commit | Line | Data |
---|---|---|
11d6f468 | 1 | /******************************************************************************* |
94cce698 | 2 | * Copyright (c) 2012, 2013 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 | ||
16 | import java.io.File; | |
11d6f468 AM |
17 | |
18 | import org.eclipse.core.resources.IProject; | |
5e4bf87d | 19 | import org.eclipse.core.resources.IResource; |
e12ecd30 | 20 | import org.eclipse.core.runtime.CoreException; |
a94410d9 MK |
21 | import org.eclipse.core.runtime.IStatus; |
22 | import org.eclipse.core.runtime.Status; | |
7c60c8b4 AM |
23 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
24 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; | |
a94410d9 | 25 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Activator; |
dc0f7bfe | 26 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; |
e12ecd30 | 27 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
11d6f468 AM |
28 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; |
29 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; | |
18ab1d18 | 30 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; |
a51b2b9f | 31 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
6e71ce46 | 32 | import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager; |
11d6f468 AM |
33 | |
34 | /** | |
35 | * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel | |
36 | * traces. It uses the CtfKernelStateInput to generate the state history. | |
d85d2a6d | 37 | * |
2cb26548 AM |
38 | * @version 1.0 |
39 | * @author Alexandre Montplaisir | |
11d6f468 AM |
40 | */ |
41 | public class CtfKernelTrace extends CtfTmfTrace { | |
42 | ||
e12ecd30 BH |
43 | /** |
44 | * The file name of the History Tree | |
45 | */ | |
46 | public final static String HISTORY_TREE_FILE_NAME = "stateHistory.ht"; //$NON-NLS-1$ | |
6752f420 | 47 | |
a76f1067 AM |
48 | /** |
49 | * ID of the state system we will build | |
50 | * @since 2.0 | |
51 | * */ | |
52 | public static final String STATE_ID = "org.eclipse.linuxtools.lttng2.kernel"; //$NON-NLS-1$ | |
53 | ||
d85d2a6d AM |
54 | /** |
55 | * Default constructor | |
56 | */ | |
11d6f468 AM |
57 | public CtfKernelTrace() { |
58 | super(); | |
59 | } | |
60 | ||
a94410d9 MK |
61 | /** |
62 | * @since 2.0 | |
63 | */ | |
11d6f468 | 64 | @Override |
a94410d9 | 65 | public IStatus validate(final IProject project, final String path) { |
7c60c8b4 | 66 | CTFTrace temp; |
a94410d9 | 67 | IStatus validStatus; |
7c60c8b4 AM |
68 | /* |
69 | * Make sure the trace is openable as a CTF trace. We do this here | |
70 | * instead of calling super.validate() to keep the reference to "temp". | |
71 | */ | |
72 | try { | |
73 | temp = new CTFTrace(path); | |
74 | } catch (CTFReaderException e) { | |
a94410d9 MK |
75 | validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e); |
76 | return validStatus; | |
77 | } catch (NullPointerException e){ | |
78 | validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e); | |
79 | return validStatus; | |
11d6f468 | 80 | } |
7c60c8b4 AM |
81 | |
82 | /* Make sure the domain is "kernel" in the trace's env vars */ | |
83 | String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$ | |
81fe3479 | 84 | temp.dispose(); |
7c60c8b4 | 85 | if (dom != null && dom.equals("\"kernel\"")) { //$NON-NLS-1$ |
a94410d9 | 86 | return Status.OK_STATUS; |
7c60c8b4 | 87 | } |
a94410d9 MK |
88 | validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfKernelTrace_DomainError); |
89 | return validStatus; | |
11d6f468 AM |
90 | } |
91 | ||
92 | @Override | |
93 | protected void buildStateSystem() throws TmfTraceException { | |
a51b2b9f AM |
94 | super.buildStateSystem(); |
95 | ||
11d6f468 | 96 | /* Set up the path to the history tree file we'll use */ |
6e71ce46 | 97 | IResource resource = this.getResource(); |
d85d2a6d | 98 | String supplDirectory = null; |
e12ecd30 BH |
99 | |
100 | try { | |
101 | // get the directory where the history file will be stored. | |
102 | supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); | |
103 | } catch (CoreException e) { | |
9fa32496 | 104 | throw new TmfTraceException(e.toString(), e); |
e12ecd30 BH |
105 | } |
106 | ||
107 | final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME); | |
6e71ce46 | 108 | final IStateChangeInput htInput = new CtfKernelStateInput(this); |
11d6f468 | 109 | |
e45de797 | 110 | ITmfStateSystem ss = StateSystemManager.loadStateHistory(htFile, htInput, false); |
a51b2b9f | 111 | fStateSystems.put(STATE_ID, ss); |
faa38350 PT |
112 | } |
113 | ||
11d6f468 | 114 | } |