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; | |
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 | ||
37 | public CtfKernelTrace() { | |
38 | super(); | |
39 | } | |
40 | ||
41 | @Override | |
42 | public boolean validate(final IProject project, final String path) { | |
43 | if (!super.validate(project, path)) { | |
44 | return false; | |
45 | } | |
46 | /* Add extra checks specific to kernel traces here */; | |
47 | return true; | |
48 | } | |
49 | ||
50 | @Override | |
51 | protected void buildStateSystem() throws TmfTraceException { | |
52 | /* Set up the path to the history tree file we'll use */ | |
53 | final String htPath = this.getPath() + ".ht"; | |
54 | final File htFile = new File(htPath); | |
55 | ||
56 | IStateHistoryBackend htBackend; | |
57 | IStateChangeInput htInput; | |
58 | HistoryBuilder builder; | |
59 | ||
60 | /* If the target file already exists, do not rebuild it uselessly */ | |
61 | // TODO for now we assume it's complete. Might be a good idea to check | |
62 | // at least if its range matches the trace's range. | |
63 | try { | |
64 | if (htFile.exists()) { | |
65 | /* Load an existing history */ | |
66 | htBackend = new HistoryTreeBackend(htFile); | |
67 | this.ss = new StateHistorySystem(htBackend, false); | |
68 | } else { | |
69 | /* Create a new state history from scratch */ | |
dc0f7bfe | 70 | htInput = new CtfKernelStateInput(this); |
11d6f468 AM |
71 | htBackend = new HistoryTreeBackend(htFile, |
72 | htInput.getStartTime()); | |
73 | builder = new HistoryBuilder(htInput, htBackend); | |
74 | ||
75 | // TODO this is blocking for now... | |
76 | builder.run(); | |
77 | } | |
78 | } catch (IOException e) { | |
79 | throw new TmfTraceException(e.getMessage()); | |
80 | } | |
81 | } | |
82 | } |