Commit | Line | Data |
---|---|---|
11d6f468 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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 | * Alexandre Montplaisir - Initial API and implementation | |
11 | ******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng2.kernel.core.trace; | |
14 | ||
15 | import java.io.File; | |
16 | import java.io.IOException; | |
17 | ||
18 | import org.eclipse.core.resources.IProject; | |
5e4bf87d | 19 | import org.eclipse.core.resources.IResource; |
e12ecd30 | 20 | import org.eclipse.core.runtime.CoreException; |
dc0f7bfe | 21 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; |
e12ecd30 | 22 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
11d6f468 AM |
23 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; | |
18ab1d18 AM |
25 | import org.eclipse.linuxtools.tmf.core.statesystem.HistoryBuilder; |
26 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; | |
27 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateHistoryBackend; | |
11d6f468 | 28 | import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend; |
6752f420 | 29 | import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.ThreadedHistoryTreeBackend; |
11d6f468 AM |
30 | |
31 | /** | |
32 | * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel | |
33 | * traces. It uses the CtfKernelStateInput to generate the state history. | |
34 | * | |
35 | * @author alexmont | |
36 | * | |
37 | */ | |
38 | public class CtfKernelTrace extends CtfTmfTrace { | |
39 | ||
e12ecd30 BH |
40 | /** |
41 | * The file name of the History Tree | |
42 | */ | |
43 | public final static String HISTORY_TREE_FILE_NAME = "stateHistory.ht"; //$NON-NLS-1$ | |
44 | ||
6752f420 AM |
45 | /** Size of the blocking queue to use when building a state history */ |
46 | private final static int QUEUE_SIZE = 10000; | |
47 | ||
11d6f468 AM |
48 | public CtfKernelTrace() { |
49 | super(); | |
50 | } | |
51 | ||
52 | @Override | |
53 | public boolean validate(final IProject project, final String path) { | |
54 | if (!super.validate(project, path)) { | |
55 | return false; | |
56 | } | |
f483ae24 | 57 | /* Add extra checks specific to kernel traces here */ |
11d6f468 AM |
58 | return true; |
59 | } | |
60 | ||
61 | @Override | |
62 | protected void buildStateSystem() throws TmfTraceException { | |
63 | /* Set up the path to the history tree file we'll use */ | |
5e4bf87d | 64 | IResource resource = getResource(); |
e12ecd30 BH |
65 | String supplDirectory = null; |
66 | ||
67 | try { | |
68 | // get the directory where the history file will be stored. | |
69 | supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); | |
70 | } catch (CoreException e) { | |
9fa32496 | 71 | throw new TmfTraceException(e.toString(), e); |
e12ecd30 BH |
72 | } |
73 | ||
74 | final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME); | |
11d6f468 AM |
75 | |
76 | IStateHistoryBackend htBackend; | |
77 | IStateChangeInput htInput; | |
78 | HistoryBuilder builder; | |
79 | ||
80 | /* If the target file already exists, do not rebuild it uselessly */ | |
81 | // TODO for now we assume it's complete. Might be a good idea to check | |
82 | // at least if its range matches the trace's range. | |
6752f420 AM |
83 | if (htFile.exists()) { |
84 | /* Load an existing history */ | |
85 | try { | |
11d6f468 | 86 | htBackend = new HistoryTreeBackend(htFile); |
d26f90fd | 87 | this.ss = HistoryBuilder.openExistingHistory(htBackend); |
6752f420 AM |
88 | return; |
89 | } catch (IOException e) { | |
90 | /* | |
91 | * There was an error opening the existing file. Perhaps it was | |
92 | * corrupted, perhaps it's an old version? We'll just | |
93 | * fall-through and try to build a new one from scratch instead. | |
94 | */ | |
11d6f468 | 95 | } |
6752f420 AM |
96 | } |
97 | ||
98 | /* Create a new state history from scratch */ | |
99 | htInput = new CtfKernelStateInput(this); | |
100 | ||
101 | try { | |
102 | htBackend = new ThreadedHistoryTreeBackend(htFile, | |
103 | htInput.getStartTime(), QUEUE_SIZE); | |
104 | builder = new HistoryBuilder(htInput, htBackend); | |
11d6f468 | 105 | } catch (IOException e) { |
6752f420 AM |
106 | /* |
107 | * If it fails here however, it means there was a problem writing | |
108 | * to the disk, so throw a real exception this time. | |
109 | */ | |
9fa32496 | 110 | throw new TmfTraceException(e.toString(), e); |
11d6f468 | 111 | } |
6752f420 | 112 | |
d26f90fd | 113 | this.ss = builder.getStateSystemQuerier(); |
11d6f468 AM |
114 | } |
115 | } |