@@ -277,7 +277,7 @@ def libpythonvm_build_args():
277
277
return build_args
278
278
279
279
280
- def graalpy_native_pgo_build_and_test (args ):
280
+ def graalpy_native_pgo_build_and_test (_ ):
281
281
"""
282
282
Builds a PGO-instrumented GraalPy native standalone, runs the unittests to generate a profile,
283
283
then builds a PGO-optimized GraalPy native standalone with the collected profile.
@@ -287,20 +287,31 @@ def graalpy_native_pgo_build_and_test(args):
287
287
288
288
with set_env (GRAALPY_PGO_PROFILE = "" ):
289
289
mx .log (mx .colorize ("[PGO] Building PGO-instrumented native image" , color = "yellow" ))
290
- native_bin = graalpy_standalone ('native' , enterprise = True , build = True )
290
+ build_home = graalpy_standalone_home ('native' , enterprise = True , build = True )
291
+ instrumented_home = build_home + "_PGO_INSTRUMENTED"
292
+ shutil .rmtree (instrumented_home , ignore_errors = True )
293
+ shutil .copytree (build_home , instrumented_home , symlinks = True , ignore_dangling_symlinks = True )
294
+ instrumented_launcher = os .path .join (instrumented_home , 'bin' , _graalpy_launcher ())
291
295
292
- mx .log (mx .colorize ("[PGO] Instrumented build complete. " , color = "yellow" ))
296
+ mx .log (mx .colorize (f "[PGO] Instrumented build complete: { instrumented_home } " , color = "yellow" ))
293
297
294
- mx .log (mx .colorize (f"[PGO] Running graalpytest with instrumented binary: { native_bin } " , color = "yellow" ))
298
+ mx .log (mx .colorize (f"[PGO] Running graalpytest with instrumented binary: { instrumented_launcher } " , color = "yellow" ))
295
299
with tempfile .TemporaryDirectory () as d :
296
300
with set_env (
297
301
GRAALPYTEST_ALLOW_NO_JAVA_ASSERTIONS = "true" ,
298
- GRAAL_PYTHON_VM_ARGS = f"--vm.XX:ProfilesDumpFile={ os .path .join (d , '$UUID$.iprof' )} "
302
+ GRAAL_PYTHON_VM_ARGS = "\v " .join ([
303
+ f"--vm.XX:ProfilesDumpFile={ os .path .join (d , '$UUID$.iprof' )} " ,
304
+ f"--vm.XX:ProfilesLCOVFile={ os .path .join (d , '$UUID$.info' )} " ,
305
+ ]),
306
+ GRAALPY_HOME = instrumented_home ,
299
307
):
300
- graalpytest (["--python" , native_bin , ". " ])
301
- iprof_path = os . path . join ( SUITE . dir , 'default.iprof' )
308
+ graalpytest (["--python" , instrumented_launcher , "test_venv.py " ])
309
+ mx . command_function ( 'benchmark' )([ "meso-small:*" ] )
302
310
303
- mx .run ([
311
+ iprof_path = Path (SUITE .dir ) / 'default.iprof'
312
+ lcov_path = Path (SUITE .dir ) / 'default.lcov'
313
+
314
+ run ([
304
315
os .path .join (
305
316
graalvm_jdk (enterprise = True ),
306
317
"bin" ,
@@ -310,11 +321,30 @@ def graalpy_native_pgo_build_and_test(args):
310
321
f"--input-dir={ d } " ,
311
322
f"--output-file={ iprof_path } "
312
323
])
324
+ run ([
325
+ "/usr/bin/env" ,
326
+ "lcov" ,
327
+ "-o" , str (lcov_path ),
328
+ * itertools .chain .from_iterable ([
329
+ ["-a" , f .absolute ().as_posix ()] for f in Path (d ).glob ("*.info" )
330
+ ])
331
+ ], nonZeroIsFatal = False )
332
+ run ([
333
+ "/usr/bin/env" ,
334
+ "genhtml" ,
335
+ "--source-directory" , str (Path (SUITE .dir ) / "com.oracle.graal.python" / "src" ),
336
+ "--source-directory" , str (Path (SUITE .dir ) / "com.oracle.graal.python.pegparser" / "src" ),
337
+ "--source-directory" , str (Path (SUITE .get_output_root ()) / "com.oracle.graal.python" / "src_gen" ),
338
+ "--include" , "com/oracle/graal/python" ,
339
+ "--keep-going" ,
340
+ "-o" , "lcov_html" ,
341
+ str (lcov_path ),
342
+ ], nonZeroIsFatal = False )
313
343
314
344
if not os .path .isfile (iprof_path ):
315
345
mx .abort (f"[PGO] Could not find profile file at expected location: { iprof_path } " )
316
346
317
- with set_env (GRAALPY_PGO_PROFILE = iprof_path ):
347
+ with set_env (GRAALPY_PGO_PROFILE = str ( iprof_path ) ):
318
348
mx .log (mx .colorize ("[PGO] Building optimized native image with collected profile" , color = "yellow" ))
319
349
native_bin = graalpy_standalone ('native' , enterprise = True , build = True )
320
350
@@ -717,9 +747,12 @@ def graalpy_standalone_home(standalone_type, enterprise=False, dev=False, build=
717
747
mx .abort ("PGO is only supported on enterprise NI" )
718
748
if pgo_profile :
719
749
mx_args .append (f"--extra-image-builder-argument=--pgo={ pgo_profile } " )
750
+ mx_args .append (f"--extra-image-builder-argument=-H:+UnlockExperimentalVMOptions" )
720
751
mx_args .append (f"--extra-image-builder-argument=-H:+PGOPrintProfileQuality" )
721
752
else :
722
753
mx_args .append (f"--extra-image-builder-argument=--pgo-instrument" )
754
+ mx_args .append (f"--extra-image-builder-argument=-H:+UnlockExperimentalVMOptions" )
755
+ mx_args .append (f"--extra-image-builder-argument=-H:+ProfilingLCOV" )
723
756
724
757
if mx_gate .get_jacoco_agent_args () or (build and not DISABLE_REBUILD ):
725
758
mx_build_args = mx_args
0 commit comments