Skip to content

Commit 8f36619

Browse files
committed
[GR-68661] Use artifacts and ensure we get PGO profiles for the right commit.
1 parent d17801c commit 8f36619

File tree

2 files changed

+62
-18
lines changed

2 files changed

+62
-18
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"linux:amd64:jdk-latest" : tier2 + provide(GPY_NATIVE_STANDALONE),
202202
}),
203203
"python-pgo-profile": gpgate_ee + platform_spec(no_jobs) + platform_spec({
204-
"linux:amd64:jdk-latest" : weekly + t("01:30:00") + task_spec({
204+
"linux:amd64:jdk-latest" : post_merge + t("01:30:00") + task_spec({
205205
run: [["mx", "python-native-pgo"]],
206206
logs+: [
207207
"default.iprof.gz",

mx.graalpython/mx_graalpython.py

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,23 +280,53 @@ def libpythonvm_build_args():
280280
):
281281
build_args += ['--gc=G1', '-H:-ProtectionKeys']
282282
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"):
283-
cmd = mx.command_function('python-get-latest-profile', fatalIfMissing=False)
284-
if cmd:
285-
profile = None
286-
try:
287-
profile = cmd([])
288-
except BaseException:
289-
pass
290-
if profile and os.path.exists(profile):
291-
mx.log(f"Using PGO profile {profile}")
292-
build_args += [
293-
f"--pgo={profile}",
294-
"-H:+UnlockExperimentalVMOptions",
295-
"-H:+PGOPrintProfileQuality",
296-
"-H:-UnlockExperimentalVMOptions",
297-
]
298-
else:
299-
mx.log(f"Not using any PGO profile")
283+
profile = None
284+
vc = mx.VC.get_vc(SUITE.dir)
285+
commit = str(vc.tip(SUITE.dir)).strip()
286+
branch = str(vc.active_branch(SUITE.dir)).strip()
287+
if shutil.which("artifact_download"):
288+
# This is always available in the GraalPy CI
289+
profile = "cached_profile.iprof.gz"
290+
run(
291+
[
292+
"artifact_download",
293+
f"graalpy/{commit}",
294+
profile,
295+
],
296+
nonZeroIsFatal=False
297+
)
298+
else:
299+
# Locally, we try to get a reasonable profile
300+
get_profile = mx.command_function('python-get-latest-profile', fatalIfMissing=False)
301+
if get_profile:
302+
for b in set([branch, "master"]):
303+
if not profile:
304+
try:
305+
profile = get_profile(["--branch", b])
306+
except BaseException:
307+
pass
308+
if (not profile or not os.path.exists(profile)) and (
309+
# When running on a release branch, make sure use a PGO profile
310+
branch.startswith("release/")
311+
# When attempting to merge into a release branch, make sure we
312+
# can produce a PGO profile before merging
313+
or os.environ.get("TO_BRANCH", "").startswith("release/")
314+
# When running in the CI on a bench runner, use a PGO profile
315+
or (os.environ.get("CI") == "true" and ",bench," in os.environ.get("LABELS", ""))
316+
):
317+
mx.warn("PGO profile must exist for benchmarking and release, creating one now...")
318+
profile = graalpy_native_pgo_build_and_test([])
319+
320+
if profile and os.path.exists(profile):
321+
mx.log(f"Using PGO profile {profile}")
322+
build_args += [
323+
f"--pgo={profile}",
324+
"-H:+UnlockExperimentalVMOptions",
325+
"-H:+PGOPrintProfileQuality",
326+
"-H:-UnlockExperimentalVMOptions",
327+
]
328+
else:
329+
mx.log(f"Not using any PGO profile")
300330
return build_args
301331

302332

@@ -379,6 +409,20 @@ def graalpy_native_pgo_build_and_test(_):
379409
shutil.copyfileobj(f_in, f_out)
380410
mx.log(mx.colorize(f"[PGO] Gzipped profile at: {iprof_gz_path}", color="yellow"))
381411

412+
if shutil.which("artifact_uploader"):
413+
run([
414+
"artifact_uploader",
415+
iprof_gz_path,
416+
str(mx.VC.get_vc(SUITE.dir).tip(SUITE.dir)).strip(),
417+
"graalpy",
418+
"--lifecycle",
419+
"cache",
420+
"--artifact-repo-key",
421+
os.environ.get("ARTIFACT_REPO_KEY_LOCATION"),
422+
])
423+
424+
return iprof_gz_path
425+
382426

383427
def full_python(args, env=None):
384428
"""Run python from standalone build (unless kwargs are given). Does not build GraalPython sources automatically."""

0 commit comments

Comments
 (0)