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.

Pavel Raiskup added the opt-in knob.

Signed-off-by: Brian J. Murrell <brian@interlinx.bc.ca>
  • Loading branch information
brianjmurrell authored and praiskup committed Sep 11, 2024
1 parent b45d784 commit 76216e0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/Plugin-CCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The ccache plugin is enabled by default and has the following values built-in:
config_opts['plugin_conf']['ccache_opts']['dir'] = "%(cache_topdir)s/%(root)s/ccache/u%(chrootuid)s/"
config_opts['plugin_conf']['ccache_opts']['hashdir'] = True
config_opts['plugin_conf']['ccache_opts']['debug'] = False
config_opts['plugin_conf']['ccache_opts']['show_stats'] = False

To turn on ccache compression, use the following in a config file:

Expand All @@ -36,3 +37,7 @@ This option is available since Mock 5.7.
Setting `debug` to `True` creates per-object debug files that are helpful when debugging unexpected cache misses.
See [ccache documentation](https://ccache.dev/manual/4.10.html#config_debug).
This option is available since Mock 5.7.

If `show_stats` is set to True, Mock calls `ccache --zero-stats` first (before
doing the build), and then calls `ccache --show-stats`.
This option is available since Mock v5.7+.
1 change: 1 addition & 0 deletions mock/docs/site-defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
# config_opts['plugin_conf']['ccache_opts']['compress'] = None
# config_opts['plugin_conf']['ccache_opts']['dir'] = "{{cache_topdir}}/{{root}}/ccache/u{{chrootuid}}/"
# config_opts['plugin_conf']['ccache_opts']['hashdir'] = True
# config_opts['plugin_conf']['ccache_opts']['show_stats'] = False
# config_opts['plugin_conf']['ccache_opts']['debug'] = False
# config_opts['plugin_conf']['yum_cache_enable'] = True
# config_opts['plugin_conf']['yum_cache_opts'] = {}
Expand Down
1 change: 1 addition & 0 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def setup_default_config_opts():
'dir': "{{cache_topdir}}/{{root}}/ccache/u{{chrootuid}}/",
'hashdir': True,
'debug': False,
'show_stats': False,
},
'yum_cache_enable': True,
'yum_cache_opts': {
Expand Down
14 changes: 14 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,11 @@ def __init__(self, plugins, conf, buildroot):
@traceLog()
def _ccacheBuildHook(self):
self.buildroot.doChroot(["ccache", "-M", str(self.ccache_opts['max_cache_size'])], shell=False)
if not self.ccache_opts.get("show_stats"):
return
# 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 @@ -69,3 +75,11 @@ 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 """
if not self.ccache_opts.get("show_stats"):
return
getLog().info("ccache stats:")
self.buildroot.doChroot(["ccache", "--show-stats"], printOutput=True, shell=False)
3 changes: 3 additions & 0 deletions releng/release-notes-next/ccache-show-stats.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
There's a new [ccache](Plugin-CCache) plugin option
`config_opts['plugin_conf']['ccache_opts']['show_stats']`; if set to `True`,
Mock prints the ccache statistics (hits/misses) to logs.

0 comments on commit 76216e0

Please sign in to comment.