bug 1355961 - add some sccache stats to build_metrics. r?gps draft
authorTed Mielczarek <ted@mielczarek.org>
Wed, 12 Apr 2017 15:06:22 -0400
changeset 561492 97d38947730c6d89e6ebec01f9eb7dc8d40870d1
parent 561262 a1d207dca92b92719325c3591eb3c55d89cd9ef9
child 623989 85b3ee9e678a02662e4a83272338006b34fef1a9
push id53746
push userbmo:ted@mielczarek.org
push dateWed, 12 Apr 2017 19:08:25 +0000
reviewersgps
bugs1355961
milestone55.0a1
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
Makefile.in
testing/mozharness/mozharness/mozilla/building/buildbase.py
--- 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']