/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
- * Copyright (c) 2010, 2011 École Polytechnique de Montréal
+ * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
*
* All rights reserved. This program and the accompanying materials are
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ * Florian Wininger - Allow to change the size of a interval
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree;
private static final String errMsg = "Invalid interval data. Maybe your file is corrupt?"; //$NON-NLS-1$
+ /**
+ * Size of an entry in the data section.
+ *
+ * <pre>
+ * 16 2 x Timevalue/long (interval start + end)
+ * + 4 int (key)
+ * + 1 byte (type)
+ * + 4 int (valueOffset)
+ * </pre>
+ */
+ private static final int DATA_ENTRY_SIZE = 25;
+
/* 'Byte' equivalent for state values types */
private static final byte TYPE_NULL = -1;
private static final byte TYPE_INTEGER = 0;
* @return The interval size
*/
public int getIntervalSize() {
- return stringsEntrySize + HTNode.DATA_ENTRY_SIZE;
+ return stringsEntrySize + DATA_ENTRY_SIZE;
}
private int computeStringsEntrySize() {
*/
public abstract class HTNode {
- /**
- * Size of an entry in the data section.
- *
- * <pre>
- * 16 2 x Timevalue/long (interval start + end)
- * + 4 int (key)
- * + 1 byte (type)
- * + 4 int (valueOffset)
- * </pre>
- */
- protected static final int DATA_ENTRY_SIZE = 25;
-
/* Configuration of the History Tree to which belongs this node */
private final HTConfig config;
/* Where the Strings section begins (from the start of the node */
private int stringSectionOffset;
+ /* Sum of bytes of all intervals in the node */
+ private int sizeOfIntervalSection;
+
/* True if this node was read from disk (meaning its end time is now fixed) */
private volatile boolean isOnDisk;
this.parentSequenceNumber = parentSeqNumber;
this.stringSectionOffset = config.getBlockSize();
+ this.sizeOfIntervalSection = 0;
this.isOnDisk = false;
this.intervals = new ArrayList<>();
}
assert (newInterval.getIntervalSize() <= this.getNodeFreeSpace());
intervals.add(newInterval);
+ sizeOfIntervalSection += newInterval.getIntervalSize();
/* Update the in-node offset "pointer" */
stringSectionOffset -= (newInterval.getStringsEntrySize());
* @return The offset, within the node, where the Data section ends
*/
private int getDataSectionEndOffset() {
- return this.getTotalHeaderSize() + HTNode.DATA_ENTRY_SIZE * intervals.size();
+ return this.getTotalHeaderSize() + sizeOfIntervalSection;
}
/**