From c86eb08ce316d1e7351ff4b8758561a68c55c374 Mon Sep 17 00:00:00 2001 From: Andrew Bradshaw Date: Wed, 23 Jul 2025 15:19:07 -0700 Subject: [PATCH] SERVER-107518 Package in perf tool with bolt (#38997) GitOrigin-RevId: 883ef3540dea29856a21570652b0edd1f63be766 --- MODULE.bazel | 9 +++++++-- bazel/repository_rules/bolt_data.bzl | 12 ++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index e629d15e7cc..0d0a43194cd 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -45,14 +45,19 @@ filegroup( srcs = ["bolt/bin/perf2bolt"], ) +filegroup( + name = "perf", + srcs = ["bolt/bin/perf"], +) + filegroup( name = "libbolt_rt_instr", srcs = ["bolt/lib/libbolt_rt_instr.a"], ) """, - sha256 = "3075be7271266550a02a0fce25622a7130a9fdf947d708e0abd45213ee17e0cf", + sha256 = "9bf3a978edd852b7975c65921ad207a5dad44254fd39eb223830057d35bb9c94", urls = [ - "https://mdb-build-public.s3.us-east-1.amazonaws.com/andrew_pgo_scratch/bolt_good.tar.gz", + "https://mdb-build-public.s3.us-east-1.amazonaws.com/andrew_pgo_scratch/bolt_perf.tar.gz", ] * 5, ) diff --git a/bazel/repository_rules/bolt_data.bzl b/bazel/repository_rules/bolt_data.bzl index 9c6d3baeda1..ff2b36c026e 100644 --- a/bazel/repository_rules/bolt_data.bzl +++ b/bazel/repository_rules/bolt_data.bzl @@ -16,6 +16,10 @@ def _setup_bolt_data(repository_ctx): # Incase you want to bolt a binary instead of the main binary mongod bolt_binary_name = repository_ctx.os.environ.get("bolt_binary_name", None) + # Perf2bolt will use the path to call the perf tool + path_env = repository_ctx.os.environ.get("PATH", None) + perf_path_env = str(repository_ctx.path(repository_ctx.attr._perf_binary).dirname) + ":" + path_env + if bolt_binary_name == None: bolt_binary_name = "mongod" @@ -62,7 +66,10 @@ def _setup_bolt_data(repository_ctx): for file in data_files: fdata_file_name = "bolt" + str(processed_fdata_files) + ".fdata" arguments = [repository_ctx.attr._perf2bolt_binary, "-nl", "-p", file, "-o", fdata_file_name, binary] - result = repository_ctx.execute(arguments) + + # We execute perf through path so it doesn't get executable permissions normally + repository_ctx.execute(["chmod", "+x", repository_ctx.attr._perf_binary]) + result = repository_ctx.execute(arguments, environment = {"PATH": perf_path_env}) print(result.stdout) if result.return_code != 0: print(result.stderr) @@ -98,10 +105,11 @@ filegroup( setup_bolt_data = repository_rule( implementation = _setup_bolt_data, - environ = ["bolt_profile_url", "bolt_binary_url", "bolt_binary_name"], + environ = ["bolt_profile_url", "bolt_binary_url", "bolt_binary_name", "PATH"], attrs = { # There is a bug where the repo rule does not properly evaluate these labels so we have to list the full path to the binaries "_merge_fdata_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt/bin/merge-fdata", executable = True, cfg = "host"), "_perf2bolt_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt/bin/perf2bolt", executable = True, cfg = "host"), + "_perf_binary": attr.label(allow_single_file = True, default = "@bolt_binaries//:bolt/bin/perf", executable = True, cfg = "host"), }, )