Commit 719bed6d authored by Christian Dietrich's avatar Christian Dietrich
Browse files

historical: restrict the number of cache misses to the actual compilation

parent 05f48bde
...@@ -90,10 +90,6 @@ class HistoricalCompilation(Experiment, ClangHashHelper): ...@@ -90,10 +90,6 @@ class HistoricalCompilation(Experiment, ClangHashHelper):
"commit-hash": self.metadata["project-hash"], "commit-hash": self.metadata["project-hash"],
'builds': []} 'builds': []}
hash_log = self.tmp_directory.new_file("clang-hash.log")
if "clang-hash" in self.mode.value:
os.environ["CLANG_HASH_LOGFILE"] = hash_log.path
with self.project as src_path: with self.project as src_path:
(commits, _) = shell("cd %s; git log --no-merges --oneline --topo-order --format='%%H %%P %%s'", src_path) (commits, _) = shell("cd %s; git log --no-merges --oneline --topo-order --format='%%H %%P %%s'", src_path)
# [0] is hash. [1] is parent, [2] rest # [0] is hash. [1] is parent, [2] rest
...@@ -151,13 +147,6 @@ class HistoricalCompilation(Experiment, ClangHashHelper): ...@@ -151,13 +147,6 @@ class HistoricalCompilation(Experiment, ClangHashHelper):
with open(self.stats.path, "w+") as fd: with open(self.stats.path, "w+") as fd:
fd.write(repr(self.build_info)) fd.write(repr(self.build_info))
if "ccache" in self.mode.value:
shell("ccache -s > %s", self.ccache_stats.path)
# Copy Log to the result directory
with open(hash_log.path) as fd:
self.clang_hash_stats.value = fd.read()
def variant_name(self): def variant_name(self):
return "%s-%s"%(self.project_name(), self.metadata['mode']) return "%s-%s"%(self.project_name(), self.metadata['mode'])
......
...@@ -3,6 +3,7 @@ import fnmatch ...@@ -3,6 +3,7 @@ import fnmatch
import time import time
from versuchung.execute import shell, CommandFailed, shell_failok from versuchung.execute import shell, CommandFailed, shell_failok
import logging import logging
import tempfile
def read_hash_directory(hash_dir, remove_keys = []): def read_hash_directory(hash_dir, remove_keys = []):
"""Read in all records from a hash dir """Read in all records from a hash dir
...@@ -88,7 +89,25 @@ class ClangHashHelper: ...@@ -88,7 +89,25 @@ class ClangHashHelper:
else: else:
return shell("cd %s; make -j %s", path, str(self.jobs.value)) return shell("cd %s; make -j %s", path, str(self.jobs.value))
def ccache_hits(self):
(lines, _) = shell("ccache -s")
ccache_hits = 0
ccache_misses = 0
for line in lines:
if "cache hit" in line and "rate" not in line:
ccache_hits += int(line[line.index(")")+1:].strip())
if "cache miss" in line:
ccache_misses += int(line[line.index("miss")+4:].strip())
return ccache_hits, ccache_misses
def rebuild(self, path, info, fail_ok=False): def rebuild(self, path, info, fail_ok=False):
if "ccache" in self.mode.value:
old_ccache_hits, old_ccache_misses = self.ccache_hits()
if "clang-hash" in self.mode.value:
hash_log = tempfile.NamedTemporaryFile()
os.environ["CLANG_HASH_LOGFILE"] = hash_log.name
# Recompile! # Recompile!
start_time = time.time() start_time = time.time()
try: try:
...@@ -101,9 +120,20 @@ class ClangHashHelper: ...@@ -101,9 +120,20 @@ class ClangHashHelper:
ret = ("", 1) ret = ("", 1)
end_time = time.time() end_time = time.time()
# Account only nano seconds, everywhere
build_time = int((end_time - start_time) * 1e9) build_time = int((end_time - start_time) * 1e9)
info['build-time'] = build_time info['build-time'] = build_time
# Record Cache misses and hits
if "ccache" in self.mode.value:
ccache_hits, ccache_misses = self.ccache_hits()
info['ccache-hits'] = ccache_hits - old_ccache_hits
info['ccache-misses'] = ccache_misses - old_ccache_misses
if "clang-hash" in self.mode.value:
log = hash_log.read()
info['clang-hash-hits'] = log.count("H")
info['clang-hash-misses'] = log.count("M")
logging.info("Rebuild done[%s]: %s s; failed=%s", logging.info("Rebuild done[%s]: %s s; failed=%s",
info.get("filename") or info.get("commit"), info.get("filename") or info.get("commit"),
build_time / 1e9, build_time / 1e9,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment