tmf: allow intervals with variable size
authorFlorian Wininger <florian.wininger@polymtl.ca>
Mon, 14 Apr 2014 18:06:15 +0000 (14:06 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 14 Apr 2014 21:53:26 +0000 (17:53 -0400)
Remove the fix data size of a HTInterval in HTNode.

Change-Id: I116053884328318379a72643e7c4bf64b3b912c0
Signed-off-by: Florian Wininger <florian.wininger@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/24795
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java

index aa1a12f17a76145be027c0807bd09472e533bacf..f99cb8b5b39a5e6300748351ea0b26d4643953c3 100644 (file)
@@ -1,6 +1,5 @@
 /*******************************************************************************
- * 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
@@ -8,6 +7,9 @@
  * 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;
@@ -31,6 +33,18 @@ public final class HTInterval implements ITmfStateInterval, Comparable<HTInterva
 
     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;
@@ -368,7 +382,7 @@ public final class HTInterval implements ITmfStateInterval, Comparable<HTInterva
      * @return The interval size
      */
     public int getIntervalSize() {
-        return stringsEntrySize + HTNode.DATA_ENTRY_SIZE;
+        return stringsEntrySize + DATA_ENTRY_SIZE;
     }
 
     private int computeStringsEntrySize() {
index a81afe764e3a9c4369b75616e3fba2df06a3d87f..37c70e296455f7b53a5354bd56138cafbabc6371 100644 (file)
@@ -33,18 +33,6 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
  */
 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;
 
@@ -59,6 +47,9 @@ public abstract class HTNode {
     /* 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;
 
@@ -87,6 +78,7 @@ public abstract class HTNode {
         this.parentSequenceNumber = parentSeqNumber;
 
         this.stringSectionOffset = config.getBlockSize();
+        this.sizeOfIntervalSection = 0;
         this.isOnDisk = false;
         this.intervals = new ArrayList<>();
     }
@@ -322,6 +314,7 @@ public abstract class HTNode {
             assert (newInterval.getIntervalSize() <= this.getNodeFreeSpace());
 
             intervals.add(newInterval);
+            sizeOfIntervalSection += newInterval.getIntervalSize();
 
             /* Update the in-node offset "pointer" */
             stringSectionOffset -= (newInterval.getStringsEntrySize());
@@ -510,7 +503,7 @@ public abstract class HTNode {
      * @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;
     }
 
     /**
This page took 0.033189 seconds and 5 git commands to generate.