Bug 1943654 - Generate the C++, JS and Rust metric files in parallel, r=chutten,sergesanspaille.

Differential Revision: https://phabricator.services.mozilla.com/D235470
This commit is contained in:
Florian Quèze
2025-02-07 14:31:11 +00:00
parent 4d0574d59e
commit 5ae7163fc4
2 changed files with 72 additions and 29 deletions

View File

@@ -144,8 +144,6 @@ def main(cpp_fd, *args):
def open_output(filename): def open_output(filename):
return FileAvoidWrite(os.path.join(os.path.dirname(cpp_fd.name), filename)) return FileAvoidWrite(os.path.join(os.path.dirname(cpp_fd.name), filename))
[js_h_path, js_cpp_path, rust_path] = args[-3:]
args = args[:-3]
all_objs, options = parse(args) all_objs, options = parse(args)
all_metric_header_files = {} all_metric_header_files = {}
@@ -164,37 +162,69 @@ def main(cpp_fd, *args):
all_metric_header_files[filename][category_name] = {} all_metric_header_files[filename][category_name] = {}
all_metric_header_files[filename][category_name][name] = metric all_metric_header_files[filename][category_name][name] = metric
if "pings" in all_objs: get_metric_id = generate_metric_ids(all_objs, options)
cpp.output_cpp(all_objs, cpp_fd, options) for header_name, objs in all_metric_header_files.items():
else: cpp.output_cpp(
get_metric_id = generate_metric_ids(all_objs, options) objs,
for header_name, objs in all_metric_header_files.items(): (
cpp.output_cpp( cpp_fd
objs, if header_name == "GleanMetrics"
( else open_output(header_name + ".h")
cpp_fd ),
if header_name == "GleanMetrics" {"header_name": header_name, "get_metric_id": get_metric_id},
else open_output(header_name + ".h") )
),
{"header_name": header_name, "get_metric_id": get_metric_id}, return get_deps()
)
def js_metrics(js_cpp_fd, *args):
def open_output(filename):
return FileAvoidWrite(os.path.join(os.path.dirname(js_cpp_fd.name), filename))
js_h_path = args[-1]
args = args[:-1]
all_objs, options = parse(args)
with open_output(js_h_path) as js_fd:
js.output_js(all_objs, js_fd, js_cpp_fd, options)
return get_deps()
def rust_metrics(rust_fd, *args):
all_objs, options = parse(args)
# We only need this info if we're dealing with pings.
ping_names_by_app_id = {}
rust.output_rust(all_objs, rust_fd, ping_names_by_app_id, options)
return get_deps()
def pings(cpp_fd, *args):
def open_output(filename):
return FileAvoidWrite(os.path.join(os.path.dirname(cpp_fd.name), filename))
[js_h_path, js_cpp_path, rust_path] = args[-3:]
args = args[:-3]
all_objs, options = parse(args)
cpp.output_cpp(all_objs, cpp_fd, options)
with open_output(js_h_path) as js_fd: with open_output(js_h_path) as js_fd:
with open_output(js_cpp_path) as js_cpp_fd: with open_output(js_cpp_path) as js_cpp_fd:
js.output_js(all_objs, js_fd, js_cpp_fd, options) js.output_js(all_objs, js_fd, js_cpp_fd, options)
# We only need this info if we're dealing with pings.
ping_names_by_app_id = {} ping_names_by_app_id = {}
if "pings" in all_objs: from os import path
from os import path
sys.path.append(path.join(path.dirname(__file__), path.pardir, path.pardir)) sys.path.append(path.join(path.dirname(__file__), path.pardir, path.pardir))
from metrics_index import pings_by_app_id from metrics_index import pings_by_app_id
for app_id, ping_yamls in pings_by_app_id.items(): for app_id, ping_yamls in pings_by_app_id.items():
input_files = [Path(path.join(topsrcdir, x)) for x in ping_yamls] input_files = [Path(path.join(topsrcdir, x)) for x in ping_yamls]
ping_objs, _ = parse_with_options(input_files, options) ping_objs, _ = parse_with_options(input_files, options)
ping_names_by_app_id[app_id] = sorted(ping_objs["pings"].keys()) ping_names_by_app_id[app_id] = sorted(ping_objs["pings"].keys())
with open_output(rust_path) as rust_fd: with open_output(rust_path) as rust_fd:
rust.output_rust(all_objs, rust_fd, ping_names_by_app_id, options) rust.output_rust(all_objs, rust_fd, ping_names_by_app_id, options)

View File

@@ -173,24 +173,37 @@ GeneratedFile(
GeneratedFile( GeneratedFile(
"GleanMetrics.h", "GleanMetrics.h",
*metrics_headers, *metrics_headers,
"GleanJSMetricsLookup.h", script="build_scripts/glean_parser_ext/run_glean_parser.py",
flags=glean_parser_flags,
inputs=["!metrics_yamls.cached"],
)
GeneratedFile(
"GleanJSMetricsLookup.cpp", "GleanJSMetricsLookup.cpp",
"api/src/metrics.rs", "GleanJSMetricsLookup.h",
entry_point="js_metrics",
script="build_scripts/glean_parser_ext/run_glean_parser.py", script="build_scripts/glean_parser_ext/run_glean_parser.py",
flags=glean_parser_flags flags=glean_parser_flags
+ [ + [
"GleanJSMetricsLookup.h", "GleanJSMetricsLookup.h",
"GleanJSMetricsLookup.cpp",
"api/src/metrics.rs",
], ],
inputs=["!metrics_yamls.cached"], inputs=["!metrics_yamls.cached"],
) )
GeneratedFile(
"api/src/metrics.rs",
entry_point="rust_metrics",
script="build_scripts/glean_parser_ext/run_glean_parser.py",
flags=glean_parser_flags,
inputs=["!metrics_yamls.cached"],
)
GeneratedFile( GeneratedFile(
"GleanPings.h", "GleanPings.h",
"GleanJSPingsLookup.h", "GleanJSPingsLookup.h",
"GleanJSPingsLookup.cpp", "GleanJSPingsLookup.cpp",
"api/src/pings.rs", "api/src/pings.rs",
entry_point="pings",
script="build_scripts/glean_parser_ext/run_glean_parser.py", script="build_scripts/glean_parser_ext/run_glean_parser.py",
flags=glean_parser_flags flags=glean_parser_flags
+ [ + [