bug 1355961 - add some sccache stats to build_metrics. r=gps
authorTed Mielczarek <ted@mielczarek.org>
Wed, 12 Apr 2017 15:06:22 -0400
changeset 353399 b5552791f6c8da640cfcb248ba4681d4d31594a5
parent 353398 8c8aba039a48898e87b64be661c2b353d3197bb6
child 353400 bc81a56620c3c6dc29480806efd7a4729624663d
push id89250
push usertmielczarek@mozilla.com
push dateMon, 17 Apr 2017 11:34:37 +0000
treeherdermozilla-inbound@b5552791f6c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1355961
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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(stats_file, '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']