From 542cefeac8a7f6102b51c22b8675537876d3b7fd Mon Sep 17 00:00:00 2001 From: Peter Simonyi Date: Sat, 9 Jun 2018 14:55:46 -0400 Subject: [PATCH] Bug 1445383 - update ccache stats parser for ccache 3.4 and 3.5 r=froydnj MozReview-Commit-ID: KTr9RhkJN5B --HG-- extra : rebase_source : b384a7e79f2e349a29942cf85f52aa306ddaa3c8 --- .../mozbuild/mozbuild/controller/building.py | 9 ++++++ .../test/controller/test_ccachestats.py | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/python/mozbuild/mozbuild/controller/building.py b/python/mozbuild/mozbuild/controller/building.py index fbd5a0dc242a..94f8a7895c9f 100644 --- a/python/mozbuild/mozbuild/controller/building.py +++ b/python/mozbuild/mozbuild/controller/building.py @@ -757,6 +757,8 @@ class CCacheStats(object): STATS_KEYS = [ # (key, description) # Refer to stats.c in ccache project for all the descriptions. + ('stats_zero_time', 'stats zero time'), + ('stats_updated', 'stats updated'), ('cache_hit_direct', 'cache hit (direct)'), ('cache_hit_preprocessed', 'cache hit (preprocessed)'), ('cache_hit_rate', 'cache hit rate'), @@ -838,6 +840,13 @@ class CCacheStats(object): @staticmethod def _parse_value(raw_value): + try: + # ccache calls strftime with '%c' (src/stats.c) + ts = time.strptime(raw_value, '%c') + return int(time.mktime(ts)) + except ValueError: + pass + value = raw_value.split() unit = '' if len(value) == 1: diff --git a/python/mozbuild/mozbuild/test/controller/test_ccachestats.py b/python/mozbuild/mozbuild/test/controller/test_ccachestats.py index 8ee50d73cbfd..e0f6b4719746 100644 --- a/python/mozbuild/mozbuild/test/controller/test_ccachestats.py +++ b/python/mozbuild/mozbuild/test/controller/test_ccachestats.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals +import time import unittest from mozunit import main @@ -174,6 +175,30 @@ class TestCcacheStats(unittest.TestCase): max cache size 5.0 GB """ + # Substitute a locally-generated timestamp because the timestamp format is + # locale-dependent. + STAT8 = """ + cache directory /home/psimonyi/.ccache + primary config /home/psimonyi/.ccache/ccache.conf + secondary config (readonly) /etc/ccache.conf + stats zero time {timestamp} + cache hit (direct) 571 + cache hit (preprocessed) 1203 + cache miss 11747 + cache hit rate 13.12 % + called for link 623 + called for preprocessing 7194 + compile failed 32 + preprocessor error 137 + bad compiler arguments 4 + autoconf compile/link 348 + no input file 162 + cleanups performed 77 + files in cache 13464 + cache size 6.2 GB + max cache size 7.0 GB + """.format(timestamp=time.strftime('%c')) + def test_parse_garbage_stats_message(self): self.assertRaises(ValueError, CCacheStats, self.STAT_GARBAGE) @@ -231,5 +256,10 @@ class TestCcacheStats(unittest.TestCase): stat7 = CCacheStats(self.STAT7) self.assertTrue(stat7) + def test_stats_version34(self): + # Test parsing 3.4 output. + stat8 = CCacheStats(self.STAT8) + self.assertTrue(stat8) + if __name__ == '__main__': main()