Skip to content

Commit e026ca2

Browse files
committed
[GR-50357] Remove iterated instrumentation
PullRequest: graal/16327
2 parents fa7f6af + a79c196 commit e026ca2

File tree

2 files changed

+16
-47
lines changed

2 files changed

+16
-47
lines changed

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,6 @@ def benchmark_output_dir(self, _, args):
250250
else:
251251
return None
252252

253-
def pgo_iteration_num(self, _, args):
254-
parsed_args = parse_prefixed_args('-Dnative-image.benchmark.pgo-iteration-num=', args)
255-
if parsed_args:
256-
return int(parsed_args[0])
257-
else:
258-
return None
259-
260253
def stages(self, args):
261254
parsed_arg = parse_prefixed_arg('-Dnative-image.benchmark.stages=', args, 'Native Image benchmark stages should only be specified once.')
262255
return parsed_arg.split(',') if parsed_arg else ['agent', 'instrument-image', 'instrument-run', 'image', 'run']

vm/mx.vm/mx_vm_benchmark.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def __init__(self, vm, bm_suite, args):
148148
self.extra_profile_run_args = bm_suite.extra_profile_run_arg(self.benchmark_name, args, list(image_run_args), not vm.safepoint_sampler)
149149
self.extra_agent_profile_run_args = bm_suite.extra_agent_profile_run_arg(self.benchmark_name, args, list(image_run_args))
150150
self.benchmark_output_dir = bm_suite.benchmark_output_dir(self.benchmark_name, args)
151-
self.pgo_iteration_num = bm_suite.pgo_iteration_num(self.benchmark_name, args)
152151
self.params = ['extra-image-build-argument', 'extra-jvm-arg', 'extra-run-arg', 'extra-agent-run-arg', 'extra-profile-run-arg',
153152
'extra-agent-profile-run-arg', 'benchmark-output-dir', 'stages', 'skip-agent-assertions']
154153

@@ -265,7 +264,7 @@ def __init__(self, name, config_name, extra_java_args=None, extra_launcher_args=
265264
mx.warn(f"Ignoring: {kwargs}")
266265

267266
self.vm_args = None
268-
self.pgo_instrumented_iterations = 0
267+
self.pgo_instrumentation = False
269268
self.pgo_context_sensitive = True
270269
self.is_gate = False
271270
self.is_quickbuild = False
@@ -302,7 +301,7 @@ def _configure_from_name(self, config_name):
302301
return
303302

304303
# This defines the allowed config names for NativeImageVM. The ones registered will be available via --jvm-config
305-
rule = r'^(?P<native_architecture>native-architecture-)?(?P<string_inlining>string-inlining-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<gc>g1gc-)?(?P<llvm>llvm-)?(?P<pgo>pgo-|pgo-ctx-insens-)?(?P<inliner>inline-|iterative-|inline-explored-)?' \
304+
rule = r'^(?P<native_architecture>native-architecture-)?(?P<string_inlining>string-inlining-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<gc>g1gc-)?(?P<llvm>llvm-)?(?P<pgo>pgo-|pgo-ctx-insens-)?(?P<inliner>inline-)?' \
306305
r'(?P<analysis_context_sensitivity>insens-|allocsens-|1obj-|2obj1h-|3obj2h-|4obj3h-)?(?P<no_inlining_before_analysis>no-inline-)?(?P<jdk_profiles>jdk-profiles-collect-|adopted-jdk-pgo-)?' \
307306
r'(?P<profile_inference>profile-inference-feature-extraction-)?(?P<sampler>safepoint-sampler-|async-sampler-)?(?P<optimization_level>O0-|O1-|O2-|O3-)?(?P<edition>ce-|ee-)?$'
308307

@@ -348,32 +347,19 @@ def _configure_from_name(self, config_name):
348347
pgo_mode = matching.group("pgo")[:-1]
349348
if pgo_mode == "pgo":
350349
mx.logv(f"'pgo' is enabled for {config_name}")
351-
self.pgo_instrumented_iterations = 1
350+
self.pgo_instrumentation = True
352351
elif pgo_mode == "pgo-ctx-insens":
353352
mx.logv(f"'pgo-ctx-insens' is enabled for {config_name}")
354-
self.pgo_instrumented_iterations = 1
353+
self.pgo_instrumentation = True
355354
self.pgo_context_sensitive = False
356355
else:
357356
mx.abort(f"Unknown pgo mode: {pgo_mode}")
358357

359-
if matching.group("inliner") is not None:
360-
inliner = matching.group("inliner")[:-1]
361-
if self.pgo_instrumented_iterations < 1:
362-
mx.abort(f"The selected inliner require PGO! Invalid configuration: {config_name}")
363-
elif inliner == "iterative":
364-
mx.logv(f"'iterative' inliner is enabled for {config_name}")
365-
self.pgo_instrumented_iterations = 3
366-
elif inliner == "inline-explored":
367-
mx.logv(f"'inline-explored' is enabled for {config_name}")
368-
self.pgo_instrumented_iterations = 3
369-
else:
370-
mx.abort(f"Unknown inliner configuration: {inliner}")
371-
372358
if matching.group("jdk_profiles") is not None:
373359
config = matching.group("jdk_profiles")[:-1]
374360
if config == 'jdk-profiles-collect':
375361
self.jdk_profiles_collect = True
376-
self.pgo_instrumented_iterations = 1
362+
self.pgo_instrumentation = True
377363

378364
def generate_profiling_package_prefixes():
379365
# run the native-image-configure tool to gather the jdk package prefixes
@@ -407,15 +393,15 @@ def generate_profiling_package_prefixes():
407393
profile_inference_config = matching.group("profile_inference")[:-1]
408394
if profile_inference_config == 'profile-inference-feature-extraction':
409395
self.profile_inference_feature_extraction = True
410-
self.pgo_instrumented_iterations = 1 # extract code features
396+
self.pgo_instrumentation = True # extract code features
411397
else:
412398
mx.abort('Unknown profile inference configuration: {}.'.format(profile_inference_config))
413399

414400
if matching.group("sampler") is not None:
415401
config = matching.group("sampler")[:-1]
416402
if config == 'safepoint-sampler':
417403
self.safepoint_sampler = True
418-
self.pgo_instrumented_iterations = 1
404+
self.pgo_instrumentation = True
419405
elif config == 'async-sampler':
420406
self.async_sampler = True
421407
else:
@@ -933,11 +919,9 @@ def run_stage_agent(self, config, stages):
933919
if file.endswith(".json"):
934920
zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(path, '..')))
935921

936-
def run_stage_instrument_image(self, config, stages, out, i, instrumentation_image_name, image_path, image_path_latest, instrumented_iterations, profile_path):
922+
def run_stage_instrument_image(self, config, stages, out, instrumentation_image_name, image_path, profile_path):
937923
executable_name_args = ['-o', instrumentation_image_name]
938-
pgo_args = ['--pgo=' + config.latest_profile_path]
939-
pgo_args += svm_experimental_options(['-H:' + ('+' if self.pgo_context_sensitive else '-') + 'PGOContextSensitivityEnabled'])
940-
instrument_args = ['--pgo-instrument', '-R:ProfilesDumpFile=' + profile_path] + ([] if i == 0 else pgo_args)
924+
instrument_args = ['--pgo-instrument', '-R:ProfilesDumpFile=' + profile_path]
941925
if self.jdk_profiles_collect:
942926
instrument_args += svm_experimental_options(['-H:+AOTPriorityInline', '-H:-SamplingCollect', f'-H:ProfilingPackagePrefixes={self.generate_profiling_package_prefixes()}'])
943927

@@ -946,8 +930,6 @@ def run_stage_instrument_image(self, config, stages, out, i, instrumentation_ima
946930
if config.bundle_path is not None:
947931
NativeImageVM.copy_bundle_output(config)
948932
if s.exit_code == 0:
949-
mx.copyfile(image_path, image_path_latest)
950-
if i + 1 == instrumented_iterations and s.exit_code == 0:
951933
image_size = os.stat(image_path).st_size
952934
out('Instrumented image size: ' + str(image_size) + ' B')
953935

@@ -992,7 +974,6 @@ def run_stage_image(self, config, stages, out):
992974
executable_name_args = ['-o', config.final_image_name]
993975
pgo_args = ['--pgo=' + config.latest_profile_path]
994976
pgo_args += svm_experimental_options(['-H:' + ('+' if self.pgo_context_sensitive else '-') + 'PGOContextSensitivityEnabled'])
995-
instrumented_iterations = self.pgo_instrumented_iterations if config.pgo_iteration_num is None else int(config.pgo_iteration_num)
996977
if self.adopted_jdk_pgo:
997978
# choose appropriate profiles
998979
jdk_version = mx.get_jdk().javaCompliance
@@ -1014,7 +995,7 @@ def run_stage_image(self, config, stages, out):
1014995
mx.warn("To dump the profile inference features to a specific location, please set the '{}' flag.".format(dump_file_flag))
1015996
else:
1016997
ml_args = []
1017-
final_image_command = config.base_image_build_args + executable_name_args + (pgo_args if instrumented_iterations > 0 else []) + jdk_profiles_args + ml_args
998+
final_image_command = config.base_image_build_args + executable_name_args + (pgo_args if self.pgo_instrumentation else []) + jdk_profiles_args + ml_args
1018999
with stages.set_command(final_image_command) as s:
10191000
s.execute_command()
10201001
if config.bundle_path is not None:
@@ -1060,7 +1041,6 @@ def run_java(self, args, out=None, err=None, cwd=None, nonZeroIsFatal=False):
10601041
self.config = config
10611042
stages = NativeImageVM.Stages(config, out, err, self.is_gate, True if self.is_gate else nonZeroIsFatal, os.path.abspath(cwd if cwd else os.getcwd()))
10621043
self.stages = stages
1063-
instrumented_iterations = self.pgo_instrumented_iterations if config.pgo_iteration_num is None else int(config.pgo_iteration_num)
10641044

10651045
if not os.path.exists(config.output_dir):
10661046
os.makedirs(config.output_dir)
@@ -1069,22 +1049,18 @@ def run_java(self, args, out=None, err=None, cwd=None, nonZeroIsFatal=False):
10691049
os.makedirs(config.config_dir)
10701050

10711051
if stages.change_stage('agent'):
1072-
if instrumented_iterations == 0 and config.last_stage.startswith('instrument-'):
1073-
config.last_stage = 'agent'
10741052
self.run_stage_agent(config, stages)
10751053

10761054
# Native Image profile collection
1077-
for i in range(instrumented_iterations):
1078-
profile_path = config.profile_path_no_extension + '-' + str(i) + config.profile_file_extension
1079-
instrumentation_image_name = config.executable_name + '-instrument-' + str(i)
1080-
instrumentation_image_latest = config.executable_name + '-instrument-latest'
1055+
profile_path = config.profile_path_no_extension + config.profile_file_extension
1056+
instrumentation_image_name = config.executable_name + '-instrument'
10811057

1058+
if self.pgo_instrumentation:
10821059
image_path = os.path.join(config.output_dir, instrumentation_image_name)
1083-
image_path_latest = os.path.join(config.output_dir, instrumentation_image_latest)
1084-
if stages.change_stage('instrument-image', str(i)):
1085-
self.run_stage_instrument_image(config, stages, out, i, instrumentation_image_name, image_path, image_path_latest, instrumented_iterations, profile_path)
1060+
if stages.change_stage('instrument-image'):
1061+
self.run_stage_instrument_image(config, stages, out, instrumentation_image_name, image_path, profile_path)
10861062

1087-
if stages.change_stage('instrument-run', str(i)):
1063+
if stages.change_stage('instrument-run'):
10881064
self.run_stage_instrument_run(config, stages, image_path, profile_path)
10891065

10901066
# Build the final image

0 commit comments

Comments
 (0)