aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Bergeron2013-12-04 19:26:33 (EST)
committerAlexandre Montplaisir2013-12-05 17:07:00 (EST)
commit8726834cd5a1a1883b8d963e0f2c52de9d664db5 (patch)
tree37f7ad57ea61534d9a2781dd4c05dd22868bc30d
parent7eea528e3cb68353f8ecc74436adea045cef29ce (diff)
downloadorg.eclipse.linuxtools-8726834cd5a1a1883b8d963e0f2c52de9d664db5.zip
org.eclipse.linuxtools-8726834cd5a1a1883b8d963e0f2c52de9d664db5.tar.gz
org.eclipse.linuxtools-8726834cd5a1a1883b8d963e0f2c52de9d664db5.tar.bz2
tmf: Add a HTNode cache to decrease the number of disk accessrefs/changes/08/19408/2
On startup, a cache of 256 entries give this ratio: 7778/8000 [97.23%] After running a while: 42375/42600 [99.47%] Change-Id: Icf2f6af3c9f40d4532196b18a87f2aa728341a58 Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com> Signed-off-by: Florian Wininger <florian.wininger@polymtl.ca> Reviewed-on: https://git.eclipse.org/r/19408 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
index c8ff18e..6f75532 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
@@ -40,6 +40,9 @@ class HT_IO {
private final FileChannel fcIn;
private final FileChannel fcOut;
+ private final int CACHE_SIZE = 256;
+ private final HTNode fNodeCache[] = new HTNode[CACHE_SIZE];
+
/**
* Standard constructor
*
@@ -116,10 +119,20 @@ class HT_IO {
* just catch this exception.
*/
synchronized HTNode readNodeFromDisk(int seqNumber) throws ClosedChannelException {
- HTNode readNode;
+ /* Do a cache lookup */
+ int offset = seqNumber & (CACHE_SIZE - 1);
+ HTNode readNode = fNodeCache[offset];
+ if (readNode != null && readNode.getSequenceNumber() == seqNumber) {
+ return readNode;
+ }
+
+ /* Lookup on disk */
try {
seekFCToNodePos(fcIn, seqNumber);
readNode = HTNode.readNode(tree, fcIn);
+
+ /* Put the node in the cache. */
+ fNodeCache[offset] = readNode;
return readNode;
} catch (ClosedChannelException e) {
throw e;
@@ -132,8 +145,13 @@ class HT_IO {
void writeNode(HTNode node) {
try {
+ /* Insert the node into the cache. */
+ int seqNumber = node.getSequenceNumber();
+ int offset = seqNumber & (CACHE_SIZE - 1);
+ fNodeCache[offset] = node;
+
/* Position ourselves at the start of the node and write it */
- seekFCToNodePos(fcOut, node.getSequenceNumber());
+ seekFCToNodePos(fcOut, seqNumber);
node.writeSelf(fcOut);
} catch (IOException e) {
/* If we were able to open the file, we should be fine now... */
@@ -179,7 +197,7 @@ class HT_IO {
synchronized void deleteFile() {
closeFile();
- if(!historyTreeFile.delete()) {
+ if (!historyTreeFile.delete()) {
/* We didn't succeed in deleting the file */
//TODO log it?
}