This is more generic for multiple implementations of IHistoryTree.
From running the state system benchmarks, there was no performance impact
with this patch by returning a Collection instead of a single element.
Change-Id: I9775c856e5e30d94eba01af001495dbd61191b22
Signed-off-by: Loïc Prieur-Drevon <loic.prieurdrevon@gmail.com>
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/78279
Reviewed-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Tested-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-by: Hudson CI
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
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 org.eclipse.jdt.annotation.NonNull;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
throws TimeRangeException, StateSystemDisposedException {
checkValidTime(t);
throws TimeRangeException, StateSystemDisposedException {
checkValidTime(t);
+ /* Queue is a stack of nodes containing nodes intersecting t */
+ Deque<HTNode> queue = new LinkedList<>();
+
/* We start by reading the information in the root node */
/* We start by reading the information in the root node */
- HTNode currentNode = getSHT().getRootNode();
- currentNode.writeInfoFromNode(stateInfo, t);
+ queue.add(getSHT().getRootNode());
- /* Then we follow the branch down in the relevant children */
+ /* Then we follow the down in the relevant children */
- while (currentNode.getNodeType() == HTNode.NodeType.CORE) {
- currentNode = getSHT().selectNextChild((CoreNode) currentNode, t);
+ while (!queue.isEmpty()) {
+ HTNode currentNode = queue.pop();
+ if (currentNode.getNodeType() == HTNode.NodeType.CORE) {
+ /* Here we add the relevant children nodes for BFS */
+ queue.addAll(getSHT().selectNextChildren((CoreNode) currentNode, t));
+ }
currentNode.writeInfoFromNode(stateInfo, t);
}
} catch (ClosedChannelException e) {
currentNode.writeInfoFromNode(stateInfo, t);
}
} catch (ClosedChannelException e) {
@Override
public ITmfStateInterval doSingularQuery(long t, int attributeQuark)
throws TimeRangeException, StateSystemDisposedException {
@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) {
}
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.
/**
* 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)
*/
private HTInterval getRelevantInterval(long t, int key)
- throws TimeRangeException, StateSystemDisposedException {
+ throws TimeRangeException, ClosedChannelException {
- 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<HTNode> queue = new LinkedList<>();
+ queue.add(getSHT().getRootNode());
+ HTInterval interval = null;
+ while (interval == null && !queue.isEmpty()) {
+ HTNode currentNode = queue.pop();
+ if (currentNode.getNodeType() == HTNode.NodeType.CORE) {
+ queue.addAll(getSHT().selectNextChildren((CoreNode) currentNode, t));
- } catch (ClosedChannelException e) {
- throw new StateSystemDisposedException(e);
+ interval = currentNode.getRelevantInterval(key, t);
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Collections;
import java.util.List;
- public HTNode selectNextChild(CoreNode currentNode, long t) throws ClosedChannelException {
+ public Collection<HTNode> selectNextChildren(CoreNode currentNode, long t) throws ClosedChannelException {
assert (currentNode.getNbChildren() > 0);
int potentialNextSeqNb = currentNode.getSequenceNumber();
assert (currentNode.getNbChildren() > 0);
int potentialNextSeqNb = currentNode.getSequenceNumber();
* node has to be on disk
*/
if (currentNode.isOnDisk()) {
* node has to be on disk
*/
if (currentNode.isOnDisk()) {
- return fTreeIO.readNode(potentialNextSeqNb);
+ return Collections.singleton(fTreeIO.readNode(potentialNextSeqNb));
- return readNode(potentialNextSeqNb);
+ return Collections.singleton(readNode(potentialNextSeqNb));
import java.io.File;
import java.io.FileInputStream;
import java.nio.channels.ClosedChannelException;
import java.io.File;
import java.io.FileInputStream;
import java.nio.channels.ClosedChannelException;
+import java.util.Collection;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
void insertInterval(HTInterval interval) throws TimeRangeException;
/**
void insertInterval(HTInterval interval) throws TimeRangeException;
/**
- * Inner method to select the next child of the current node intersecting
+ * Inner method to select the next children of the current node intersecting
* the given timestamp. Useful for moving down the tree following one
* branch.
*
* the given timestamp. Useful for moving down the tree following one
* branch.
*
* The node on which the request is made
* @param t
* The timestamp to choose which child is the next one
* The node on which the request is made
* @param t
* The timestamp to choose which child is the next one
- * @return The child node intersecting t
+ * @return The child nodes intersecting t
* @throws ClosedChannelException
* If the file channel was closed while we were reading the tree
*/
* @throws ClosedChannelException
* If the file channel was closed while we were reading the tree
*/
- HTNode selectNextChild(CoreNode currentNode, long t) throws ClosedChannelException;
+ Collection<HTNode> selectNextChildren(CoreNode currentNode, long t) throws ClosedChannelException;
/**
* Get the current size of the history file.
/**
* Get the current size of the history file.