diff options
author | Dave Borowitz | 2011-11-03 19:54:21 +0000 |
---|---|---|
committer | Shawn O. Pearce | 2011-11-04 18:14:32 +0000 |
commit | 4fc1af68501c70407ade42dc13906061939a499c (patch) | |
tree | a91568df80f61975154397deb62f72396f57f277 | |
parent | dff9d56b946552b4a6b802908a22793f95d3738c (diff) | |
download | jgit-4fc1af68501c70407ade42dc13906061939a499c.tar.gz jgit-4fc1af68501c70407ade42dc13906061939a499c.tar.xz jgit-4fc1af68501c70407ade42dc13906061939a499c.zip |
Add a DfsPackFile method to get the number of cached bytes
The counter is actually stored in the DfsPackKey so it can be
manipulated by the cache.
Change-Id: I10cee76c92d65c68d1aa1a9dd0c4fd7173c4cede
3 files changed, 19 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java index 871a2c5034..bd68ae520d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java @@ -115,8 +115,12 @@ public final class DfsBlockCache { DfsBlockCache oc = cache; cache = nc; - if (oc != null && oc.readAheadService != null) - oc.readAheadService.shutdown(); + if (oc != null) { + if (oc.readAheadService != null) + oc.readAheadService.shutdown(); + for (DfsPackFile pack : oc.getPackFiles()) + pack.key.cachedSize.set(0); + } } /** @return the currently active DfsBlockCache. */ @@ -343,6 +347,7 @@ public final class DfsBlockCache { e2 = table.get(slot); } + key.cachedSize.addAndGet(v.size()); Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v); ref.hot = true; for (;;) { @@ -389,6 +394,7 @@ public final class DfsBlockCache { dead.next = null; dead.value = null; live -= dead.size; + dead.pack.cachedSize.addAndGet(-dead.size); statEvict++; } while (maxBytes < live); clockHand = prev; @@ -438,6 +444,7 @@ public final class DfsBlockCache { } } + key.cachedSize.addAndGet(size); ref = new Ref<T>(key, pos, size, v); ref.hot = true; for (;;) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java index 02ba0a0b20..573e8e7067 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java @@ -171,6 +171,11 @@ public final class DfsPackFile { return packDesc; } + /** @return bytes cached in memory for this pack, excluding the index. */ + public long getCachedSize() { + return key.cachedSize.get(); + } + private String getPackName() { return packDesc.getPackName(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java index 8e77dbaa27..880ac9909a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java @@ -43,13 +43,18 @@ package org.eclipse.jgit.storage.dfs; +import java.util.concurrent.atomic.AtomicLong; + final class DfsPackKey { final int hash; + final AtomicLong cachedSize; + DfsPackKey() { // Multiply by 31 here so we can more directly combine with another // value without doing the multiply there. // hash = System.identityHashCode(this) * 31; + cachedSize = new AtomicLong(); } } |