summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/CHANGES.txt2
-rw-r--r--src/engine/SCons/CacheDir.py14
-rw-r--r--test/CacheDir/debug.py20
-rw-r--r--test/Interactive/cache-debug.py1
4 files changed, 37 insertions, 0 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 07532c1..d09f01d 100755
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -67,6 +67,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
- Fix more re patterns that contain \ but not specified as raw strings
(affects scanners for D, LaTeX, swig)
+ From Mathew Robinson:
+ - Update cache debug output to include cache hit rate.
RELEASE 3.0.5 - Mon, 26 Mar 2019 15:04:42 -0700
diff --git a/src/engine/SCons/CacheDir.py b/src/engine/SCons/CacheDir.py
index 0a378c2..704b9a5 100644
--- a/src/engine/SCons/CacheDir.py
+++ b/src/engine/SCons/CacheDir.py
@@ -47,10 +47,12 @@ def CacheRetrieveFunc(target, source, env):
t = target[0]
fs = t.fs
cd = env.get_CacheDir()
+ cd.requests += 1
cachedir, cachefile = cd.cachepath(t)
if not fs.exists(cachefile):
cd.CacheDebug('CacheRetrieve(%s): %s not in cache\n', t, cachefile)
return 1
+ cd.hits += 1
cd.CacheDebug('CacheRetrieve(%s): retrieving from %s\n', t, cachefile)
if SCons.Action.execute_actions:
if fs.islink(cachefile):
@@ -148,6 +150,8 @@ class CacheDir(object):
one exists, if not the config file is created and
the default config is written, as well as saved in the object.
"""
+ self.requests = 0
+ self.hits = 0
self.path = path
self.current_cache_debug = None
self.debugFP = None
@@ -269,6 +273,16 @@ class CacheDir(object):
self.current_cache_debug = cache_debug
if self.debugFP:
self.debugFP.write(fmt % (target, os.path.split(cachefile)[1]))
+ self.debugFP.write("requests: %d, hits: %d, misses: %d, hit rate: %.2f%%\n" %
+ (self.requests, self.hits, self.misses, self.hit_ratio))
+
+ @property
+ def hit_ratio(self):
+ return (100.0 * self.hits / self.requests if self.requests > 0 else 100)
+
+ @property
+ def misses(self):
+ return self.requests - self.hits
def is_enabled(self):
return cache_enabled and self.path is not None
diff --git a/test/CacheDir/debug.py b/test/CacheDir/debug.py
index 16f4702..9b3b633 100644
--- a/test/CacheDir/debug.py
+++ b/test/CacheDir/debug.py
@@ -88,9 +88,13 @@ test.run(chdir='src',
expect = \
r"""CacheRetrieve\(aaa.out\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(bbb.out\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(ccc.out\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(all\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
"""
test.must_match(debug_out, expect, mode='r')
@@ -102,17 +106,25 @@ test.must_match(debug_out, expect, mode='r')
expect = \
r"""CacheRetrieve\(aaa.out\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
cat\(\["aaa.out"\], \["aaa.in"\]\)
CachePush\(aaa.out\): pushing to [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(bbb.out\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
cat\(\["bbb.out"\], \["bbb.in"\]\)
CachePush\(bbb.out\): pushing to [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(ccc.out\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
cat\(\["ccc.out"\], \["ccc.in"\]\)
CachePush\(ccc.out\): pushing to [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(all\): [0-9a-fA-F]+ not in cache
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
cat\(\["all"\], \["aaa.out", "bbb.out", "ccc.out"\]\)
CachePush\(all\): pushing to [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
"""
test.run(chdir='src',
@@ -134,12 +146,16 @@ test.unlink(['src', 'cat.out'])
expect = \
r"""Retrieved `aaa.out' from cache
CacheRetrieve\(aaa.out\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
Retrieved `bbb.out' from cache
CacheRetrieve\(bbb.out\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
Retrieved `ccc.out' from cache
CacheRetrieve\(ccc.out\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
Retrieved `all' from cache
CacheRetrieve\(all\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
"""
test.run(chdir='src',
@@ -164,9 +180,13 @@ test.run(chdir='src',
expect = \
r"""CacheRetrieve\(aaa.out\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(bbb.out\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(ccc.out\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
CacheRetrieve\(all\): retrieving from [0-9a-fA-F]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
"""
test.must_match(debug_out, expect, mode='r')
diff --git a/test/Interactive/cache-debug.py b/test/Interactive/cache-debug.py
index 68bedb8..e1856bb 100644
--- a/test/Interactive/cache-debug.py
+++ b/test/Interactive/cache-debug.py
@@ -106,6 +106,7 @@ scons>>> Removed foo.out
scons>>> Touch\("4"\)
scons>>> Retrieved `foo.out' from cache
CacheRetrieve\(foo.out\): retrieving from [0-9A-za-z]+
+requests: [0-9]+, hits: [0-9]+, misses: [0-9]+, hit rate: [0-9]+\.[0-9]{2,}%
scons>>> Touch\("5"\)
scons>>>
"""