Skip to content

Commit 255db1e

Browse files
rjogradycopybara-github
authored andcommitted
Remove RUNFILES_MANIFEST_FILE from the environment when launching subprocesses.
The subprocess (e.g. fleetbench binary) may also need runfiles, and its runfiles path will not be that of the parallel script. PiperOrigin-RevId: 677869352 Change-Id: If83324bcf51dd76ee8964d26c8f58c256e0d4e41
1 parent 7f48085 commit 255db1e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

fleetbench/parallel/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ py_library(
4242
py_library(
4343
name = "benchmark",
4444
srcs = ["benchmark.py"],
45-
deps = ["@com_google_absl_py//absl/flags"],
45+
deps = [
46+
"@com_google_absl_py//absl/flags",
47+
"@com_google_absl_py//absl/logging",
48+
],
4649
)
4750

4851
py_library(

fleetbench/parallel/benchmark.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import subprocess
2020

2121
from absl import flags
22+
from absl import logging
23+
2224

2325
_BENCHMARK_DIR = flags.DEFINE_string(
2426
"benchmark_dir",
@@ -27,6 +29,14 @@
2729
)
2830

2931

32+
def CleanEnv() -> dict[str, str]:
33+
"""Returns a copy of the current environment suitable for subprocesses."""
34+
env = os.environ.copy()
35+
# Subprocesses don't share the same runfiles as this script.
36+
env.pop("RUNFILES_MANIFEST_FILE", None)
37+
return env
38+
39+
3040
def _FindBenchmarkPath(benchmark: str) -> str:
3141
"""Find the path to the benchmark binary."""
3242
if os.path.exists(benchmark):
@@ -59,7 +69,13 @@ def GetSubBenchmarks(benchmark_path: str, workload: str = "") -> list[str]:
5969
cmd += [
6070
f"--benchmark_filter=BM_{workload.upper()}",
6171
]
62-
p = subprocess.run(cmd, capture_output=True, text=True, check=True)
72+
try:
73+
p = subprocess.run(
74+
cmd, capture_output=True, text=True, check=True, env=CleanEnv()
75+
)
76+
except subprocess.CalledProcessError as e:
77+
logging.exception("Failed to get sub-benchmarks: %s (%s)", cmd, e.stderr)
78+
raise
6379
return p.stdout.split("\n")[:-1]
6480

6581

fleetbench/parallel/benchmark_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def testGetSubBenchmarksWorkloadWithUnmatchedBM(self, mock_run):
144144
capture_output=True,
145145
text=True,
146146
check=True,
147+
env=mock.ANY,
147148
)
148149

149150

fleetbench/parallel/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def Execute(self) -> result.Result:
3737
logging.debug("running %s", command)
3838
try:
3939
start = time.time()
40-
proc = subprocess.run(command, capture_output=True, check=True, text=True)
40+
proc = subprocess.run(
41+
command, capture_output=True, check=True, text=True, env=bm.CleanEnv()
42+
)
4143
end = time.time()
4244
except subprocess.CalledProcessError as e:
4345
logging.exception("Run failed: %s (%s)", command, e.stderr)

0 commit comments

Comments
 (0)