]> source.dussan.org Git - jgit.git/commitdiff
DfsBlockCacheTable: extract stats get* methods to interface 57/1197857/2
authorLaura Hamelin <haowl@google.com>
Mon, 15 Jul 2024 18:35:56 +0000 (11:35 -0700)
committerIvan Frade <ifrade@google.com>
Mon, 15 Jul 2024 19:13:05 +0000 (19:13 +0000)
Having the DfsBlockCacheTable methods extracted to an interface will
allow alternative implementations of BlockCacheStats not tied to the
current implementation.

Change-Id: I534f7998f46253cdb7a68d5ec21d4f42ea586e8e

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/ClockBlockCacheTable.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTable.java

index d0907bcc8d65fd084ad841d3e74435d9deb9aaf6..ce71a71d67b015dbeefb069e41e02b8dc1087e5d 100644 (file)
@@ -135,7 +135,7 @@ final class ClockBlockCacheTable implements DfsBlockCacheTable {
        }
 
        @Override
-       public DfsBlockCacheStats getDfsBlockCacheStats() {
+       public BlockCacheStats getBlockCacheStats() {
                return dfsBlockCacheStats;
        }
 
index 56719cf0f49fd905124d1737ab95ce910979980e..3e1300c8677645e79d59ec6eeee3d119c7226bfa 100644 (file)
@@ -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();
        }
 
        /**
index 701d1fdce3c3b0342a7604cd8d7c90c6a2f07363..309f2d15957ab676f28dd839e153dd412f3f2ea8 100644 (file)
@@ -129,18 +129,72 @@ public interface DfsBlockCacheTable {
        <T> 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);
                }