Skip to content

Commit

Permalink
Show ccache stats at the end of the build
Browse files Browse the repository at this point in the history
Zero the ccache stats at the beginning of the build and then display the
ccache stats at the end of the build to see how effective ccache was.

Signed-off-by: Brian J. Murrell <[email protected]>
  • Loading branch information
brianjmurrell authored Jan 30, 2024
1 parent ac6f488 commit e87d916
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mock/py/mockbuild/plugins/ccache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, plugins, conf, buildroot):
buildroot.preexisting_deps.append("ccache")
plugins.add_hook("prebuild", self._ccacheBuildHook)
plugins.add_hook("preinit", self._ccachePreInitHook)
plugins.add_hook("postbuild", self._ccachePostBuildHook)
buildroot.mounts.add(
BindMountPoint(srcpath=self.ccachePath, bindpath=buildroot.make_chroot_path("/var/tmp/ccache")))

Expand All @@ -47,6 +48,9 @@ def __init__(self, plugins, conf, buildroot):
@traceLog()
def _ccacheBuildHook(self):
self.buildroot.doChroot(["ccache", "-M", str(self.ccache_opts['max_cache_size'])], shell=False)
# zero ccache stats
getLog().info("Zero ccache stats:")
self.buildroot.doChroot(["ccache", "--zero-stats"], printOutput=True, shell=False)

# set up the ccache dir.
# we also set a few variables used by ccache to find the shared cache.
Expand All @@ -61,3 +65,10 @@ def _ccachePreInitHook(self):
file_util.mkdirIfAbsent(self.buildroot.make_chroot_path('/var/tmp/ccache'))
file_util.mkdirIfAbsent(self.ccachePath)
self.buildroot.uid_manager.changeOwner(self.ccachePath, recursive=True)

# get some cache stats
def _ccachePostBuildHook(self):
# show the cache hit stats
getLog().info("ccache stats:")
self.buildroot.doChroot(["ccache", "--show-stats"], printOutput=True, shell=False)
+

0 comments on commit e87d916

Please sign in to comment.