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