From 5a7beb0db0cc0530e8808f1703e633852e7b2529 Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Fri, 8 Aug 2014 03:06:00 -0400 Subject: [PATCH] Bug 1049263 - Do not report ccache stats unless ccache was used. r=glandium --- python/mozbuild/mozbuild/controller/building.py | 6 ++++++ python/mozbuild/mozbuild/mach_commands.py | 5 +++-- .../mozbuild/test/controller/test_ccachestats.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/python/mozbuild/mozbuild/controller/building.py b/python/mozbuild/mozbuild/controller/building.py index 78ff61ec5f84..c3294e86f611 100644 --- a/python/mozbuild/mozbuild/controller/building.py +++ b/python/mozbuild/mozbuild/controller/building.py @@ -611,6 +611,12 @@ class CCacheStats(object): return '\n'.join(lines) + def __nonzero__(self): + relative_values = [v for k, v in self._values.items() + if k not in self.ABSOLUTE_KEYS] + return (all(v >= 0 for v in relative_values) and + any(v > 0 for v in relative_values)) + @staticmethod def _format_value(v): if v > CCacheStats.GiB: diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py index b43c4326b6e7..2a498ded8a3c 100644 --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -397,8 +397,9 @@ class Build(MachCommandBase): if ccache_start and ccache_end: ccache_diff = ccache_end - ccache_start - self.log(logging.INFO, 'ccache', - {'msg': ccache_diff.hit_rate_message()}, "{msg}") + if ccache_diff: + self.log(logging.INFO, 'ccache', + {'msg': ccache_diff.hit_rate_message()}, "{msg}") if monitor.elapsed > 300: # Display a notification when the build completes. diff --git a/python/mozbuild/mozbuild/test/controller/test_ccachestats.py b/python/mozbuild/mozbuild/test/controller/test_ccachestats.py index bb430d12dc75..6678977304f2 100644 --- a/python/mozbuild/mozbuild/test/controller/test_ccachestats.py +++ b/python/mozbuild/mozbuild/test/controller/test_ccachestats.py @@ -73,6 +73,21 @@ class TestCcacheStats(unittest.TestCase): stats_diff = stats2 - stats1 self.assertEqual(stats_diff.hit_rates(), (0.9, 0.05, 0.05)) + def test_stats_contains_data(self): + stats0 = CCacheStats(self.STAT0) + stats1 = CCacheStats(self.STAT1) + stats2 = CCacheStats(self.STAT2) + stats_diff_zero = stats1 - stats1 + stats_diff_negative1 = stats0 - stats1 + stats_diff_negative2 = stats1 - stats2 + + self.assertFalse(stats0) + self.assertTrue(stats1) + self.assertTrue(stats2) + self.assertFalse(stats_diff_zero) + self.assertFalse(stats_diff_negative1) + self.assertFalse(stats_diff_negative2) + if __name__ == '__main__': main()