1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
;
16 import java
.io
.IOException
;
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
;
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.
38 public class CtfKernelTrace
extends CtfTmfTrace
{
41 * The file name of the History Tree
43 public final static String HISTORY_TREE_FILE_NAME
= "stateHistory.ht"; //$NON-NLS-1$
45 /** Size of the blocking queue to use when building a state history */
46 private final static int QUEUE_SIZE
= 10000;
48 public CtfKernelTrace() {
53 public boolean validate(final IProject project
, final String path
) {
54 if (!super.validate(project
, path
)) {
57 /* Add extra checks specific to kernel traces here */
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;
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
);
74 final File htFile
= new File(supplDirectory
+ File
.separator
+ HISTORY_TREE_FILE_NAME
);
76 IStateHistoryBackend htBackend
;
77 IStateChangeInput htInput
;
78 HistoryBuilder builder
;
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 */
86 htBackend
= new HistoryTreeBackend(htFile
);
87 this.ss
= HistoryBuilder
.openExistingHistory(htBackend
);
89 } catch (IOException e
) {
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.
98 /* Create a new state history from scratch */
99 htInput
= new CtfKernelStateInput(this);
102 htBackend
= new ThreadedHistoryTreeBackend(htFile
,
103 htInput
.getStartTime(), QUEUE_SIZE
);
104 builder
= new HistoryBuilder(htInput
, htBackend
);
105 } catch (IOException e
) {
107 * If it fails here however, it means there was a problem writing
108 * to the disk, so throw a real exception this time.
110 throw new TmfTraceException(e
.toString(), e
);
113 this.ss
= builder
.getStateSystemQuerier();