From 89e2a980b9fcd1b575c1290cc728e9a3240e6c9a Mon Sep 17 00:00:00 2001 From: Laura Hamelin Date: Mon, 15 Jul 2024 11:35:56 -0700 Subject: [PATCH] DfsBlockCacheTable: extract stats get* methods to interface Having the DfsBlockCacheTable methods extracted to an interface will allow alternative implementations of BlockCacheStats not tied to the current implementation. Change-Id: I534f7998f46253cdb7a68d5ec21d4f42ea586e8e --- .../storage/dfs/ClockBlockCacheTable.java | 2 +- .../internal/storage/dfs/DfsBlockCache.java | 12 +- .../storage/dfs/DfsBlockCacheTable.java | 117 +++++++++++------- 3 files changed, 77 insertions(+), 54 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/ClockBlockCacheTable.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/ClockBlockCacheTable.java index d0907bcc8d..ce71a71d67 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/ClockBlockCacheTable.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/ClockBlockCacheTable.java @@ -135,7 +135,7 @@ final class ClockBlockCacheTable implements DfsBlockCacheTable { } @Override - public DfsBlockCacheStats getDfsBlockCacheStats() { + public BlockCacheStats getBlockCacheStats() { return dfsBlockCacheStats; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java index 56719cf0f4..3e1300c867 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java @@ -119,7 +119,7 @@ public final class DfsBlockCache { * @return total number of bytes in the cache, per pack file extension. */ public long[] getCurrentSize() { - return dfsBlockCacheTable.getDfsBlockCacheStats().getCurrentSize(); + return dfsBlockCacheTable.getBlockCacheStats().getCurrentSize(); } /** @@ -138,7 +138,7 @@ public final class DfsBlockCache { * extension. */ public long[] getHitCount() { - return dfsBlockCacheTable.getDfsBlockCacheStats().getHitCount(); + return dfsBlockCacheTable.getBlockCacheStats().getHitCount(); } /** @@ -149,7 +149,7 @@ public final class DfsBlockCache { * extension. */ public long[] getMissCount() { - return dfsBlockCacheTable.getDfsBlockCacheStats().getMissCount(); + return dfsBlockCacheTable.getBlockCacheStats().getMissCount(); } /** @@ -158,7 +158,7 @@ public final class DfsBlockCache { * @return total number of requests (hit + miss), per pack file extension. */ public long[] getTotalRequestCount() { - return dfsBlockCacheTable.getDfsBlockCacheStats() + return dfsBlockCacheTable.getBlockCacheStats() .getTotalRequestCount(); } @@ -168,7 +168,7 @@ public final class DfsBlockCache { * @return hit ratios */ public long[] getHitRatio() { - return dfsBlockCacheTable.getDfsBlockCacheStats().getHitRatio(); + return dfsBlockCacheTable.getBlockCacheStats().getHitRatio(); } /** @@ -179,7 +179,7 @@ public final class DfsBlockCache { * file extension. */ public long[] getEvictions() { - return dfsBlockCacheTable.getDfsBlockCacheStats().getEvictions(); + return dfsBlockCacheTable.getBlockCacheStats().getEvictions(); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTable.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTable.java index 701d1fdce3..309f2d1595 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTable.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTable.java @@ -129,18 +129,72 @@ public interface DfsBlockCacheTable { T get(DfsStreamKey key, long position); /** - * Get the DfsBlockCacheStats object for this block cache table's + * Get the {@link BlockCacheStats} object for this block cache table's * statistics. * - * @return the DfsBlockCacheStats tracking this block cache table's + * @return the {@link BlockCacheStats} tracking this block cache table's * statistics. */ - DfsBlockCacheStats getDfsBlockCacheStats(); + BlockCacheStats getBlockCacheStats(); + + /** + * Provides methods used with Block Cache statistics. + */ + interface BlockCacheStats { + /** + * Get total number of bytes in the cache, per pack file extension. + * + * @return total number of bytes in the cache, per pack file extension. + */ + long[] getCurrentSize(); + + /** + * Get number of requests for items in the cache, per pack file + * extension. + * + * @return the number of requests for items in the cache, per pack file + * extension. + */ + long[] getHitCount(); + + /** + * Get number of requests for items not in the cache, per pack file + * extension. + * + * @return the number of requests for items not in the cache, per pack + * file extension. + */ + long[] getMissCount(); + + /** + * Get total number of requests (hit + miss), per pack file extension. + * + * @return total number of requests (hit + miss), per pack file + * extension. + */ + long[] getTotalRequestCount(); + + /** + * Get hit ratios. + * + * @return hit ratios. + */ + long[] getHitRatio(); + + /** + * Get number of evictions performed due to cache being full, per pack + * file extension. + * + * @return the number of evictions performed due to cache being full, + * per pack file extension. + */ + long[] getEvictions(); + } /** * Keeps track of stats for a Block Cache table. */ - class DfsBlockCacheStats { + class DfsBlockCacheStats implements BlockCacheStats { /** * Number of times a block was found in the cache, per pack file * extension. @@ -214,44 +268,23 @@ public interface DfsBlockCacheTable { getStat(liveBytes, key).addAndGet(size); } - /** - * Get total number of bytes in the cache, per pack file extension. - * - * @return total number of bytes in the cache, per pack file extension. - */ - long[] getCurrentSize() { + @Override + public long[] getCurrentSize() { return getStatVals(liveBytes); } - /** - * Get number of requests for items in the cache, per pack file - * extension. - * - * @return the number of requests for items in the cache, per pack file - * extension. - */ - long[] getHitCount() { + @Override + public long[] getHitCount() { return getStatVals(statHit); } - /** - * Get number of requests for items not in the cache, per pack file - * extension. - * - * @return the number of requests for items not in the cache, per pack - * file extension. - */ - long[] getMissCount() { + @Override + public long[] getMissCount() { return getStatVals(statMiss); } - /** - * Get total number of requests (hit + miss), per pack file extension. - * - * @return total number of requests (hit + miss), per pack file - * extension. - */ - long[] getTotalRequestCount() { + @Override + public long[] getTotalRequestCount() { AtomicLong[] hit = statHit.get(); AtomicLong[] miss = statMiss.get(); long[] cnt = new long[Math.max(hit.length, miss.length)]; @@ -264,12 +297,8 @@ public interface DfsBlockCacheTable { return cnt; } - /** - * Get hit ratios. - * - * @return hit ratios. - */ - long[] getHitRatio() { + @Override + public long[] getHitRatio() { AtomicLong[] hit = statHit.get(); AtomicLong[] miss = statMiss.get(); long[] ratio = new long[Math.max(hit.length, miss.length)]; @@ -288,14 +317,8 @@ public interface DfsBlockCacheTable { return ratio; } - /** - * Get number of evictions performed due to cache being full, per pack - * file extension. - * - * @return the number of evictions performed due to cache being full, - * per pack file extension. - */ - long[] getEvictions() { + @Override + public long[] getEvictions() { return getStatVals(statEvict); } -- 2.39.5