Bug 1578661 - Add a crappy histogram parser for the devtools database, for probe-scraper. r=chutten

(And test it.)

Differential Revision: https://phabricator.services.mozilla.com/D46111

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-09-18 13:27:40 +00:00
Родитель f16f5c928d
Коммит 6d6c54d595
2 изменённых файлов: 50 добавлений и 0 удалений

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

@ -773,11 +773,35 @@ def from_counted_unknown_properties(filename, strict_type_checks):
return histograms
# This is only used for probe-scraper.
def from_properties_db(filename, strict_type_checks):
histograms = collections.OrderedDict()
with open(filename, 'r') as f:
in_css_properties = False
for line in f:
if not in_css_properties:
if line.startswith("exports.CSS_PROPERTIES = {"):
in_css_properties = True
continue
if line.startswith("};"):
break
if not line.startswith(" \""):
continue
name = line.split("\"")[1]
add_css_property_counters(histograms, name)
return histograms
FILENAME_PARSERS = [
(lambda x: from_json if x.endswith('.json') else None),
(lambda x: from_nsDeprecatedOperationList if x == 'nsDeprecatedOperationList.h' else None),
(lambda x: from_ServoCSSPropList if x == 'ServoCSSPropList.py' else None),
(lambda x: from_counted_unknown_properties if x == 'counted_unknown_properties.py' else None),
(lambda x: from_properties_db if x == 'properties-db.js' else None),
]
# Similarly to the dance above with buildconfig, usecounters may not be

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

@ -65,6 +65,32 @@ class TestParser(unittest.TestCase):
self.assertEqual(hist.n_buckets(), 101)
self.assertEqual(hist.high(), 12)
def test_devtools_database_parsing(self):
db = path.join(TELEMETRY_ROOT_PATH,
path.pardir,
path.pardir,
path.pardir,
"devtools",
"shared",
"css",
"generated",
"properties-db.js")
histograms = list(parse_histograms.from_files([db], strict_type_checks=False))
histograms = [h.name() for h in histograms]
# Test a shorthand (animation)
self.assertTrue("USE_COUNTER2_CSS_PROPERTY_Animation_DOCUMENT" in histograms)
# Test a shorthand alias (-moz-animation).
self.assertTrue("USE_COUNTER2_CSS_PROPERTY_MozAnimation_DOCUMENT" in histograms)
# Test a longhand (animation-name)
self.assertTrue("USE_COUNTER2_CSS_PROPERTY_AnimationName_DOCUMENT" in histograms)
# Test a longhand alias (-moz-animation-name)
self.assertTrue("USE_COUNTER2_CSS_PROPERTY_MozAnimationName_DOCUMENT" in histograms)
def test_current_histogram(self):
HISTOGRAMS_PATH = path.join(TELEMETRY_ROOT_PATH, "Histograms.json")
all_histograms = list(parse_histograms.from_files([HISTOGRAMS_PATH],