aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColby Ranger2011-11-03 18:30:17 (EDT)
committerShawn O. Pearce2011-11-04 14:14:32 (EDT)
commitf70ecabb3090bebb38b7f5d2a369a79742c51d6e (patch)
treec81b00111271308327bacaeb05eb914aca8ec14e
parent0f8e486a4d5f4e232c4a01119fec0e5d0148620d (diff)
downloadjgit-f70ecabb3090bebb38b7f5d2a369a79742c51d6e.zip
jgit-f70ecabb3090bebb38b7f5d2a369a79742c51d6e.tar.gz
jgit-f70ecabb3090bebb38b7f5d2a369a79742c51d6e.tar.bz2
DfsBlockCache: Update hits to not include contains()refs/changes/46/4546/2
Also expose the underlying hit and miss counters, in addition to the hit ratio. Change-Id: Icea2572d62e59318133b0a88848019f34ad70975
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java35
1 files changed, 23 insertions, 12 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 bd68ae5..d3dadbe 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
@@ -230,6 +230,21 @@ public final class DfsBlockCache {
return getCurrentSize() * 100 / maxBytes;
}
+ /** @return number of requests for items in the cache. */
+ public long getHitCount() {
+ return statHit.get();
+ }
+
+ /** @return number of requests for items not in the cache. */
+ public long getMissCount() {
+ return statMiss.get();
+ }
+
+ /** @return total number of requests (hit + miss). */
+ public long getTotalRequestCount() {
+ return getHitCount() + getMissCount();
+ }
+
/** @return 0..100, defining number of cache hits. */
public long getHitRatio() {
long hits = statHit.get();
@@ -315,8 +330,10 @@ public final class DfsBlockCache {
int slot = slot(key, position);
HashEntry e1 = table.get(slot);
DfsBlock v = scan(e1, key, position);
- if (v != null)
+ if (v != null) {
+ statHit.incrementAndGet();
return v;
+ }
reserveSpace(blockSize);
ReentrantLock regionLock = lockFor(key, position);
@@ -326,6 +343,7 @@ public final class DfsBlockCache {
if (e2 != e1) {
v = scan(e2, key, position);
if (v != null) {
+ statHit.incrementAndGet();
creditSpace(blockSize);
return v;
}
@@ -469,6 +487,8 @@ public final class DfsBlockCache {
T val = (T) scan(table.get(slot(key, position)), key, position);
if (val == null)
statMiss.incrementAndGet();
+ else
+ statHit.incrementAndGet();
return val;
}
@@ -500,17 +520,8 @@ public final class DfsBlockCache {
@SuppressWarnings("unchecked")
private <T> T scan(HashEntry n, DfsPackKey pack, long position) {
- for (; n != null; n = n.next) {
- Ref<T> r = n.ref;
- if (r.pack != pack || r.position != position)
- continue;
- T v = r.get();
- if (v == null)
- return null;
- statHit.incrementAndGet();
- return v;
- }
- return null;
+ Ref<T> r = scanRef(n, pack, position);
+ return r != null ? r.get() : null;
}
@SuppressWarnings("unchecked")