Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
logs+: [
"default.iprof.gz",
"default.lcov",
"host-inlining.txt.gz",
],
}),
}),
Expand Down
25 changes: 24 additions & 1 deletion mx.graalpython/mx_graalpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ def graalpy_native_pgo_build_and_test(args=None):
if mx_sdk_vm_ng.get_bootstrap_graalvm_version() < mx.VersionSpec("25.0"):
mx.abort("python-native-pgo not supported on GraalVM < 25")

host_inlining_log = Path(SUITE.dir) / "host-inlining.txt"
host_inlining_log_gz = Path(str(host_inlining_log) + ".gz")
if host_inlining_log.exists():
host_inlining_log.unlink()
if host_inlining_log_gz.exists():
host_inlining_log_gz.unlink()

with set_env(GRAALPY_PGO_PROFILE=""):
mx.log(mx.colorize("[PGO] Building PGO-instrumented native image", color="yellow"))
build_home = graalpy_standalone_home('native', enterprise=True, build=True)
Expand Down Expand Up @@ -469,11 +476,19 @@ def graalpy_native_pgo_build_and_test(args=None):
if not os.path.isfile(iprof_path):
mx.abort(f"[PGO] Could not find profile file at expected location: {iprof_path}")

with set_env(GRAALPY_PGO_PROFILE=str(iprof_path)):
with set_env(GRAALPY_PGO_PROFILE=str(iprof_path), GRAALPY_HOST_INLINING_LOG=str(host_inlining_log)):
mx.log(mx.colorize("[PGO] Building optimized native image with collected profile", color="yellow"))
native_bin = graalpy_standalone('native', enterprise=True, build=True)

mx.log(mx.colorize(f"[PGO] Optimized PGO build complete: {native_bin}", color="yellow"))
if host_inlining_log.exists():
mx.log(mx.colorize(f"[PGO] Host inlining log at: {host_inlining_log}", color="yellow"))
with open(host_inlining_log, 'rb') as f_in, gzip.open(host_inlining_log_gz, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
host_inlining_log.unlink()
mx.log(mx.colorize(f"[PGO] Gzipped host inlining log at: {host_inlining_log_gz}", color="yellow"))
else:
mx.warn(f"[PGO] Host inlining log was not produced at expected location: {host_inlining_log}")

iprof_gz_path = str(iprof_path) + '.gz'
with open(iprof_path, 'rb') as f_in, gzip.open(iprof_gz_path, 'wb') as f_out:
Expand Down Expand Up @@ -948,6 +963,14 @@ def graalpy_standalone_home(standalone_type, enterprise=False, dev=False, build=
mx_args.append(f"--extra-image-builder-argument=--pgo={pgo_profile}")
mx_args.append(f"--extra-image-builder-argument=-H:+UnlockExperimentalVMOptions")
mx_args.append(f"--extra-image-builder-argument=-H:+PGOPrintProfileQuality")
if host_inlining_log := os.environ.get("GRAALPY_HOST_INLINING_LOG"):
mx_args.extend([
f"--extra-image-builder-argument=-H:Log=HostInliningPhase,~CanonicalizerPhase,~GraphBuilderPhase",
f"--extra-image-builder-argument=-H:+TruffleHostInliningPrintExplored",
f"--extra-image-builder-argument=-H:MethodFilter=com.oracle.graal.python.*.*",
f"--extra-image-builder-argument=-H:-UnlockExperimentalVMOptions",
f"--extra-image-builder-argument=-Dgraal.LogFile={host_inlining_log}",
])
else:
mx_args.append(f"--extra-image-builder-argument=--pgo-instrument")
mx_args.append(f"--extra-image-builder-argument=-H:+UnlockExperimentalVMOptions")
Expand Down
Loading