Skip to content

Commit 5e06690

Browse files
committed
Make it very clear if we're automatically using some PGO profile or not
1 parent 8c37b82 commit 5e06690

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,30 @@ def graalpy_standalone_deps():
258258
return deps
259259

260260

261+
def _is_overridden_native_image_arg(prefix):
262+
extras = mx.get_opts().extra_image_builder_argument
263+
return any(arg.startswith(prefix) for arg in extras)
264+
265+
261266
def libpythonvm_build_args():
262267
build_args = []
263268
build_args += bytecode_dsl_build_args()
264-
extras = mx.get_opts().extra_image_builder_argument
269+
265270
if (
266-
mx_sdk_vm_ng.is_nativeimage_ee() and
267-
mx.get_os() == 'linux' and
268-
'NATIVE_IMAGE_AUXILIARY_ENGINE_CACHE' not in os.environ and
269-
not any(arg.startswith("--gc") for arg in extras)
271+
mx_sdk_vm_ng.is_nativeimage_ee()
272+
and mx.is_linux()
273+
and not os.environ.get('NATIVE_IMAGE_AUXILIARY_ENGINE_CACHE')
274+
and not _is_overridden_native_image_arg("--gc")
270275
):
271276
build_args += ['--gc=G1', '-H:-ProtectionKeys']
272-
if not os.environ.get("GRAALPY_PGO_PROFILE") and mx.suite('graalpython-enterprise', fatalIfMissing=False) and mx_sdk_vm_ng.get_bootstrap_graalvm_version() >= mx.VersionSpec("25.0"):
273-
profile = None
277+
278+
profile = None
279+
if (
280+
"GRAALPY_PGO_PROFILE" not in os.environ
281+
and mx.suite('graalpython-enterprise', fatalIfMissing=False)
282+
and mx_sdk_vm_ng.get_bootstrap_graalvm_version() >= mx.VersionSpec("25.0")
283+
and not _is_overridden_native_image_arg("--pgo")
284+
):
274285
vc = SUITE.vc
275286
commit = str(vc.tip(SUITE.dir)).strip()
276287
branch = str(vc.active_branch(SUITE.dir)).strip()
@@ -305,16 +316,16 @@ def libpythonvm_build_args():
305316
mx.warn("PGO profile must exist for benchmarking and release, creating one now...")
306317
profile = graalpy_native_pgo_build_and_test([])
307318

308-
if os.path.isfile(profile or ""):
309-
mx.log(f"Using PGO profile {profile}")
310-
build_args += [
311-
f"--pgo={profile}",
312-
"-H:+UnlockExperimentalVMOptions",
313-
"-H:+PGOPrintProfileQuality",
314-
"-H:-UnlockExperimentalVMOptions",
315-
]
316-
else:
317-
mx.log(f"Not using any PGO profile")
319+
if os.path.isfile(profile or ""):
320+
print(invert(f"Automatically chose PGO profile {profile}. To disable this, set GRAALPY_PGO_PROFILE to an empty string'", blinking=True), file=sys.stderr)
321+
build_args += [
322+
f"--pgo={profile}",
323+
"-H:+UnlockExperimentalVMOptions",
324+
"-H:+PGOPrintProfileQuality",
325+
"-H:-UnlockExperimentalVMOptions",
326+
]
327+
else:
328+
print(invert("Not using an automatically selected PGO profile"), file=sys.stderr)
318329
return build_args
319330

320331

@@ -2504,6 +2515,16 @@ def inner(*args, **kwargs):
25042515
return inner
25052516

25062517

2518+
def invert(msg, blinking=False, file=sys.stderr):
2519+
if getattr(file, "isatty", lambda: False)():
2520+
if blinking:
2521+
extra = "\033[5;7m"
2522+
else:
2523+
extra = "\033[7m"
2524+
return f"{extra}{msg}\033[0m"
2525+
return msg
2526+
2527+
25072528
def run(args, *splat, **kwargs):
25082529
if not mx.get_opts().quiet:
25092530
msg = "Running: "

0 commit comments

Comments
 (0)