Bug 1445383 - update ccache stats parser for ccache 3.4 and 3.5 r=froydnj

MozReview-Commit-ID: KTr9RhkJN5B

--HG--
extra : rebase_source : b384a7e79f2e349a29942cf85f52aa306ddaa3c8
This commit is contained in:
Peter Simonyi 2018-06-09 14:55:46 -04:00
Родитель ee92007fde
Коммит 542cefeac8
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -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:

Просмотреть файл

@ -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()