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; | |
dc0f7bfe | 19 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; |
11d6f468 AM |
20 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; |
21 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; | |
11d6f468 | 22 | import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend; |
6752f420 | 23 | import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.ThreadedHistoryTreeBackend; |
11d6f468 AM |
24 | import org.eclipse.linuxtools.tmf.core.statesystem.helpers.HistoryBuilder; |
25 | import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput; | |
26 | import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateHistoryBackend; | |
27 | ||
28 | /** | |
29 | * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel | |
30 | * traces. It uses the CtfKernelStateInput to generate the state history. | |
31 | * | |
32 | * @author alexmont | |
33 | * | |
34 | */ | |
35 | public class CtfKernelTrace extends CtfTmfTrace { | |
36 | ||
6752f420 AM |
37 | /** Size of the blocking queue to use when building a state history */ |
38 | private final static int QUEUE_SIZE = 10000; | |
39 | ||
11d6f468 AM |
40 | public CtfKernelTrace() { |
41 | super(); | |
42 | } | |
43 | ||
44 | @Override | |
45 | public boolean validate(final IProject project, final String path) { | |
46 | if (!super.validate(project, path)) { | |
47 | return false; | |
48 | } | |
f483ae24 | 49 | /* Add extra checks specific to kernel traces here */ |
11d6f468 AM |
50 | return true; |
51 | } | |
52 | ||
53 | @Override | |
54 | protected void buildStateSystem() throws TmfTraceException { | |
55 | /* Set up the path to the history tree file we'll use */ | |
f483ae24 | 56 | final String htPath = this.getPath() + ".ht"; //$NON-NLS-1$ |
11d6f468 AM |
57 | final File htFile = new File(htPath); |
58 | ||
59 | IStateHistoryBackend htBackend; | |
60 | IStateChangeInput htInput; | |
61 | HistoryBuilder builder; | |
62 | ||
63 | /* If the target file already exists, do not rebuild it uselessly */ | |
64 | // TODO for now we assume it's complete. Might be a good idea to check | |
65 | // at least if its range matches the trace's range. | |
6752f420 AM |
66 | if (htFile.exists()) { |
67 | /* Load an existing history */ | |
68 | try { | |
11d6f468 | 69 | htBackend = new HistoryTreeBackend(htFile); |
d26f90fd | 70 | this.ss = HistoryBuilder.openExistingHistory(htBackend); |
6752f420 AM |
71 | return; |
72 | } catch (IOException e) { | |
73 | /* | |
74 | * There was an error opening the existing file. Perhaps it was | |
75 | * corrupted, perhaps it's an old version? We'll just | |
76 | * fall-through and try to build a new one from scratch instead. | |
77 | */ | |
11d6f468 | 78 | } |
6752f420 AM |
79 | } |
80 | ||
81 | /* Create a new state history from scratch */ | |
82 | htInput = new CtfKernelStateInput(this); | |
83 | ||
84 | try { | |
85 | htBackend = new ThreadedHistoryTreeBackend(htFile, | |
86 | htInput.getStartTime(), QUEUE_SIZE); | |
87 | builder = new HistoryBuilder(htInput, htBackend); | |
11d6f468 | 88 | } catch (IOException e) { |
6752f420 AM |
89 | /* |
90 | * If it fails here however, it means there was a problem writing | |
91 | * to the disk, so throw a real exception this time. | |
92 | */ | |
11d6f468 AM |
93 | throw new TmfTraceException(e.getMessage()); |
94 | } | |
6752f420 | 95 | |
d26f90fd | 96 | this.ss = builder.getStateSystemQuerier(); |
db5abf97 AM |
97 | builder.run(); /* Start the construction of the history */ |
98 | ||
99 | //FIXME We will have to call close() once we are notified that the | |
100 | //construction is done. Until this is implemented, we will just | |
101 | //block here. | |
102 | builder.close(); | |
11d6f468 AM |
103 | } |
104 | } |