tmf: Use TMF signals to trigger the state history building
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core / src / org / eclipse / linuxtools / lttng2 / kernel / core / trace / CtfKernelTrace.java
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;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
22 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
23 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
24 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
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;
28 import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend;
29 import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.ThreadedHistoryTreeBackend;
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
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
45 /** Size of the blocking queue to use when building a state history */
46 private final static int QUEUE_SIZE = 10000;
47
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 }
57 /* Add extra checks specific to kernel traces here */
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 */
64 IResource resource = getResource();
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) {
71 throw new TmfTraceException(e.toString(), e);
72 }
73
74 final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME);
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.
83 if (htFile.exists()) {
84 /* Load an existing history */
85 try {
86 htBackend = new HistoryTreeBackend(htFile);
87 this.ss = HistoryBuilder.openExistingHistory(htBackend);
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 */
95 }
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);
105 } catch (IOException e) {
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 */
110 throw new TmfTraceException(e.toString(), e);
111 }
112
113 this.ss = builder.getStateSystemQuerier();
114 }
115 }
This page took 0.032925 seconds and 5 git commands to generate.