Skip to content

Commit 72576c7

Browse files
committed
Add size to cache stats
1 parent f3c20a1 commit 72576c7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/src/dotty/tools/dotc/core/Caches.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ object Caches:
4343
s"${this.getClass.getSimpleName}(stats() = ${stats()})"
4444

4545
/** Statistics about a cache */
46-
final case class CacheStats(total: Long, misses: Long, uncached: Long):
46+
final case class CacheStats(total: Long, misses: Long, size: Long, uncached: Long):
4747
val hits: Long = total - misses - uncached
4848

4949
override def toString: String =
50-
s"(total = $total, hits = $hits, misses = $misses, uncached = $uncached)"
50+
s"(total = $total, hits = $hits, misses = $misses, size = $size, uncached = $uncached)"
5151

5252
/** A no-op cache implementation that does not cache anything. */
5353
final class NoopCache[K, V] extends Cache[K, V]:
@@ -61,7 +61,7 @@ object Caches:
6161
false
6262

6363
def stats(): CacheStats =
64-
CacheStats(total, misses = 0, uncached = total)
64+
CacheStats(total, misses = 0, size = 0, uncached = total)
6565

6666
private def noStamp[K](key: K): Option[Unit] = Some(())
6767

@@ -95,7 +95,7 @@ object Caches:
9595
getStamp(key).isDefined
9696

9797
def stats(): CacheStats =
98-
CacheStats(total, misses, uncached)
98+
CacheStats(total, misses, map.size, uncached)
9999

100100
/** A thread-safe cache implementation based on a Java [[ConcurrentHashMap]].
101101
*
@@ -128,7 +128,7 @@ object Caches:
128128
getStamp(key).isDefined
129129

130130
def stats(): CacheStats =
131-
CacheStats(total.longValue(), misses.longValue(), uncached.longValue())
131+
CacheStats(total.longValue(), misses.longValue(), map.size(), uncached.longValue())
132132

133133
/** A cache where keys are [[AbstractFile]]s.
134134
*
@@ -206,7 +206,8 @@ object Caches:
206206
CacheStats(
207207
total = baseStats.total + uncached.longValue(),
208208
misses = baseStats.misses,
209-
uncached = baseStats.uncached + uncached.longValue()
209+
size = baseStats.size,
210+
uncached = baseStats.uncached + uncached.longValue(),
210211
)
211212

212213
def mightContain(key: K): Boolean =

0 commit comments

Comments
 (0)