import java.io.FileInputStream;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
+import java.util.Deque;
+import java.util.LinkedList;
import java.util.List;
+import java.util.logging.Logger;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
import org.eclipse.tracecompass.internal.statesystem.core.Activator;
import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
*/
public class HistoryTreeBackend implements IStateHistoryBackend {
+ private static final Logger LOGGER = TraceCompassLog.getLogger(HistoryTreeBackend.class);
+
private final @NonNull String fSsid;
/**
@Override
public void dispose() {
if (fFinishedBuilding) {
+ LOGGER.info(() -> "[HistoryTreeBackend:ClosingFile] size=" + getSHT().getFileSize()); //$NON-NLS-1$
getSHT().closeFile();
} else {
/*
throws TimeRangeException, StateSystemDisposedException {
checkValidTime(t);
+ /* Queue is a stack of nodes containing nodes intersecting t */
+ Deque<Integer> queue = new LinkedList<>();
+
/* We start by reading the information in the root node */
- HTNode currentNode = getSHT().getRootNode();
- currentNode.writeInfoFromNode(stateInfo, t);
+ queue.add(getSHT().getRootNode().getSequenceNumber());
- /* Then we follow the branch down in the relevant children */
+ /* Then we follow the down in the relevant children */
try {
- while (currentNode.getNodeType() == HTNode.NodeType.CORE) {
- currentNode = getSHT().selectNextChild((CoreNode) currentNode, t);
+ while (!queue.isEmpty()) {
+ int sequenceNumber = queue.pop();
+ HTNode currentNode = getSHT().readNode(sequenceNumber);
+ if (currentNode.getNodeType() == HTNode.NodeType.CORE) {
+ /* Here we add the relevant children nodes for BFS */
+ queue.addAll(((ParentNode) currentNode).selectNextChildren(t));
+ }
currentNode.writeInfoFromNode(stateInfo, t);
}
} catch (ClosedChannelException e) {
@Override
public ITmfStateInterval doSingularQuery(long t, int attributeQuark)
throws TimeRangeException, StateSystemDisposedException {
- return getRelevantInterval(t, attributeQuark);
+ try {
+ return getRelevantInterval(t, attributeQuark);
+ } catch (ClosedChannelException e) {
+ throw new StateSystemDisposedException(e);
+ }
}
private void checkValidTime(long t) {
/**
* Inner method to find the interval in the tree containing the requested
* key/timestamp pair, wherever in which node it is.
- *
- * @param t
- * @param key
- * @return The node containing the information we want
*/
private HTInterval getRelevantInterval(long t, int key)
- throws TimeRangeException, StateSystemDisposedException {
+ throws TimeRangeException, ClosedChannelException {
checkValidTime(t);
- HTNode currentNode = getSHT().getRootNode();
- HTInterval interval = currentNode.getRelevantInterval(key, t);
-
- try {
- while (interval == null && currentNode.getNodeType() == HTNode.NodeType.CORE) {
- currentNode = getSHT().selectNextChild((CoreNode) currentNode, t);
- interval = currentNode.getRelevantInterval(key, t);
+ Deque<Integer> queue = new LinkedList<>();
+ queue.add(getSHT().getRootNode().getSequenceNumber());
+ HTInterval interval = null;
+ while (interval == null && !queue.isEmpty()) {
+ int sequenceNumber = queue.pop();
+ HTNode currentNode = getSHT().readNode(sequenceNumber);
+ if (currentNode.getNodeType() == HTNode.NodeType.CORE) {
+ /* Here we add the relevant children nodes for BFS */
+ queue.addAll(((ParentNode) currentNode).selectNextChildren(t));
}
- } catch (ClosedChannelException e) {
- throw new StateSystemDisposedException(e);
+ interval = currentNode.getRelevantInterval(key, t);
}
return interval;
}