bug 1355961 - add some sccache stats to build_metrics. r?gps
This commit makes sccache dump JSON stats at the end of the build, and then
reads them in `BuildScript.generate_build_stats` and adds them to the
build_metrics we submit to Perfherder. The stats dumping is done in
Makefile.in where we currently dump verbose sccache stats because sccache
doesn't persist stats to disk right now and it will also shut down its server
process after 5 minutes, so when the post-build automation steps take more
than 5 minutes the server shuts down and the stats are lost.
Currently it's collecting:
* Cache hit rate
* Cache write errors
* Non-cacheable requests (compiler invocations that sccache can't cache)
We can always grow this list later.
MozReview-Commit-ID: J9CwU7XB05I
--- a/Makefile.in
+++ b/Makefile.in
@@ -233,18 +233,18 @@ endif
endif
default all::
$(call BUILDSTATUS,TIERS $(TIERS) $(if $(MOZ_AUTOMATION),$(MOZ_AUTOMATION_TIERS)))
include $(topsrcdir)/config/rules.mk
ifdef SCCACHE_VERBOSE_STATS
-# This won't contain stats for both halves of a universal build, but I can live with that.
default::
+ -$(CCACHE) --show-stats --stats-format=json > sccache-stats.json
@echo "===SCCACHE STATS==="
-$(CCACHE) --show-stats
@echo "==================="
endif
distclean::
$(RM) $(DIST_GARBAGE)
--- a/testing/mozharness/mozharness/mozilla/building/buildbase.py
+++ b/testing/mozharness/mozharness/mozilla/building/buildbase.py
@@ -1879,16 +1879,48 @@ or run without that action (ie: --no-{ac
continue
data['subtests'].append({
'name': phase['name'],
'value': phase['duration'],
})
return data
+
+ def _load_sccache_stats(self):
+ stats_file = os.path.join(
+ self.query_abs_dirs()['abs_obj_dir'], 'sccache_stats.json'
+ )
+ if not os.path.exists(stats_file):
+ self.info('%s does not exist; not loading sccache stats' % stats_file)
+ return
+
+ with open(p, 'rb') as fh:
+ stats = json.load(fh)
+
+ total = stats['stats']['requests_executed']
+ hits = stats['stats']['cache_hits']
+ if total > 0:
+ hits /= float(total)
+
+ yield {
+ 'name': 'sccache hit rate',
+ 'value': hits,
+ 'extraOptions': self.perfherder_resource_options(),
+ 'subtests': [],
+ }
+
+ for stat in ['cache_write_errors', 'requests_not_cacheable']:
+ yield {
+ 'name': 'sccache %s' % stat,
+ 'value': stats['stats'][stat],
+ 'extraOptions': self.perfherder_resource_options(),
+ 'subtests': [],
+ }
+
def get_firefox_version(self):
versionFilePath = os.path.join(
self.query_abs_dirs()['abs_src_dir'], 'browser/config/version.txt')
with open(versionFilePath, 'r') as versionFile:
return versionFile.readline().strip()
def generate_build_stats(self):
"""grab build stats following a compile.
@@ -1993,16 +2025,17 @@ or run without that action (ie: --no-{ac
"value": installer_size,
"alertThreshold": 0.25,
"subtests": size_measurements
})
build_metrics = self._load_build_resources()
if build_metrics:
perfherder_data['suites'].append(build_metrics)
+ perfherder_data['suites'].extend(self._load_sccache_stats())
if self.query_is_nightly():
for suite in perfherder_data['suites']:
if 'extraOptions' in suite:
suite['extraOptions'] = ['nightly'] + suite['extraOptions']
else:
suite['extraOptions'] = ['nightly']