Bug 1918118 - Cache parsing of glean metrics r=mkmelin a=pascalc

Glean metrics are described in yaml, which is notably slow to parse.
Instead of repeatedly parsing the same metrics again and again, cache
the parsing result.

Differential Revision: https://phabricator.services.mozilla.com/D242930
This commit is contained in:
serge-sans-paille 2025-03-26 15:27:43 +00:00
parent dee0fe51d1
commit 7ea5adab57
3 changed files with 60 additions and 8 deletions

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import pickle
import sys
from run_glean_parser import parse
def main(out_fd, *args):
parse_result = parse(args)
pickle.dump(parse_result, out_fd)
if __name__ == "__main__":
main(*sys.argv[1:])

View file

@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import pickle
import sys
from pathlib import Path
@ -68,6 +69,11 @@ def parse(args):
then return the parsed objects for further processing.
"""
if len(args) == 2 and args[0].endswith(".cached"):
cache_file, _ = args
with open(cache_file, "rb") as cache:
return pickle.load(cache)
# Unfortunately, GeneratedFile appends `flags` directly after `inputs`
# instead of listifying either, so we need to pull stuff from a *args.
yaml_array = args[:-1]

View file

@ -132,6 +132,33 @@ metrics_yamls = ["../../../" + x for x in metrics_yamls]
pings_yamls = ["../../../" + x for x in pings_yamls]
tags_yamls = ["../../../" + x for x in tags_yamls]
GeneratedFile(
"metrics_yamls.cached",
script="build_scripts/glean_parser_ext/cache_yaml.py",
flags=[
CONFIG["MOZ_APP_VERSION"],
],
inputs=metrics_yamls + tags_yamls,
)
GeneratedFile(
"pings_yamls.cached",
script="build_scripts/glean_parser_ext/cache_yaml.py",
flags=[
CONFIG["MOZ_APP_VERSION"],
],
inputs=pings_yamls + tags_yamls,
)
GeneratedFile(
"metrics_n_pings_yamls.cached",
script="build_scripts/glean_parser_ext/cache_yaml.py",
flags=[
CONFIG["MOZ_APP_VERSION"],
],
inputs=metrics_yamls + pings_yamls + tags_yamls,
)
GeneratedFile(
"GleanMetrics.h",
"GleanJSMetricsLookup.h",
@ -144,7 +171,7 @@ GeneratedFile(
"GleanJSMetricsLookup.cpp",
"api/src/metrics.rs",
],
inputs=metrics_yamls + tags_yamls,
inputs=["!metrics_yamls.cached"],
)
GeneratedFile(
@ -159,7 +186,7 @@ GeneratedFile(
"GleanJSPingsLookup.cpp",
"api/src/pings.rs",
],
inputs=pings_yamls + tags_yamls,
inputs=["!pings_yamls.cached"],
)
# Glean Interface For Firefox Telemetry Maps from Glean MetricId to Telemetry ProbeId
@ -169,7 +196,7 @@ GeneratedFile(
script="build_scripts/glean_parser_ext/run_glean_parser.py",
entry_point="gifft_map",
flags=[CONFIG["MOZ_APP_VERSION"], "Event"],
inputs=metrics_yamls + tags_yamls,
inputs=["!metrics_yamls.cached"],
)
GeneratedFile(
@ -177,7 +204,7 @@ GeneratedFile(
script="build_scripts/glean_parser_ext/run_glean_parser.py",
entry_point="gifft_map",
flags=[CONFIG["MOZ_APP_VERSION"], "Histogram"],
inputs=metrics_yamls + tags_yamls,
inputs=["!metrics_yamls.cached"],
)
GeneratedFile(
@ -185,7 +212,7 @@ GeneratedFile(
script="build_scripts/glean_parser_ext/run_glean_parser.py",
entry_point="gifft_map",
flags=[CONFIG["MOZ_APP_VERSION"], "Scalar"],
inputs=metrics_yamls + tags_yamls,
inputs=["!metrics_yamls.cached"],
)
# JOG provides both the Rust factory for building runtime-registered metrics
@ -197,7 +224,7 @@ GeneratedFile(
script="build_scripts/glean_parser_ext/run_glean_parser.py",
entry_point="jog_factory",
flags=[CONFIG["MOZ_APP_VERSION"]],
inputs=pings_yamls + metrics_yamls + tags_yamls,
inputs=["!metrics_n_pings_yamls.cached"],
)
# Only generate jogfile.json in Artifact Builds since
@ -208,7 +235,7 @@ if CONFIG["MOZ_ARTIFACT_BUILDS"]:
script="build_scripts/glean_parser_ext/run_glean_parser.py",
entry_point="jog_file",
flags=[CONFIG["MOZ_APP_VERSION"]],
inputs=pings_yamls + metrics_yamls + tags_yamls,
inputs=["!metrics_n_pings_yamls.cached"],
)
# Once generated, it needs to be placed in GreD so it can be found.
FINAL_TARGET_FILES += ["!jogfile.json"]
@ -221,7 +248,7 @@ GeneratedFile(
script="build_scripts/glean_parser_ext/run_glean_parser.py",
entry_point="ohttp_pings",
flags=[CONFIG["MOZ_APP_VERSION"]],
inputs=pings_yamls + tags_yamls,
inputs=["!pings_yamls.cached"],
)
DIRS += [