@@ -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
383427def full_python (args , env = None ):
384428 """Run python from standalone build (unless kwargs are given). Does not build GraalPython sources automatically."""
0 commit comments