FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
graalpython/mx.graalpython/mx_graalpython_benchmark.py at master · oracle/graalpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
oracle
/
graalpython
Public
Notifications
You must be signed in to change notification settings
Fork
154
Star
1.6k
Code
Issues
53
Pull requests
4
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
graalpython
/
mx.graalpython
/
mx_graalpython_benchmark.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
1642 lines (1418 loc) · 71.6 KB
Breadcrumbs
graalpython
/
mx.graalpython
/
mx_graalpython_benchmark.py
Copy path
File metadata and controls
1642 lines (1418 loc) · 71.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2018, 2026, Oracle and/or its affiliates.
# Copyright (c) 2013, Regents of the University of California
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
from
__future__
import
print_function
import
functools
import
shutil
import
statistics
import
sys
import
os
import
re
import
shlex
import
subprocess
from
abc
import
ABC
,
abstractproperty
from
contextlib
import
contextmanager
from
os
.
path
import
join
from
datetime
import
datetime
from
pathlib
import
Path
import
mx
import
mx_benchmark
import
mx_polybench
import
mx_sdk_benchmark
from
mx_benchmark
import
StdOutRule
,
java_vm_registry
,
OutputCapturingVm
,
GuestVm
,
VmBenchmarkSuite
,
AveragingBenchmarkMixin
,
bm_exec_context
from
mx_graalpython_bench_param
import
HARNESS_PATH
from
mx_util
import
StageName
# ----------------------------------------------------------------------------------------------------------------------
#
# the graalpython suite
#
# ----------------------------------------------------------------------------------------------------------------------
SUITE
=
mx
.
suite
(
"graalpython"
)
DIR
=
Path
(
__file__
).
parent
.
resolve
()
# ----------------------------------------------------------------------------------------------------------------------
#
# constants
#
# ----------------------------------------------------------------------------------------------------------------------
VM_NAME_GRAALPYTHON
=
"graalpython"
VM_NAME_GRAALPYTHON_SVM
=
"graalpython-svm"
GROUP_GRAAL
=
"Graal"
SUBGROUP_GRAAL_PYTHON
=
"graalpython"
PYTHON_VM_REGISTRY_NAME
=
"Python"
CONFIGURATION_DEFAULT
=
"default"
CONFIGURATION_CUSTOM
=
"custom"
CONFIGURATION_INTERPRETER
=
"interpreter"
CONFIGURATION_NATIVE_INTERPRETER
=
"native-interpreter"
CONFIGURATION_DEFAULT_MULTI
=
"default-multi"
CONFIGURATION_INTERPRETER_MULTI
=
"interpreter-multi"
CONFIGURATION_NATIVE_INTERPRETER_MULTI
=
"native-interpreter-multi"
CONFIGURATION_NATIVE
=
"native"
CONFIGURATION_NATIVE_JIT2
=
"native-jit2"
CONFIGURATION_UNCACHED
=
"interpreter-uncached"
CONFIGURATION_NATIVE_MULTI
=
"native-multi"
CONFIGURATION_SANDBOXED
=
"sandboxed"
CONFIGURATION_SANDBOXED_MULTI
=
"sandboxed-multi"
PYTHON_JAVA_EMBEDDING_VM_REGISTRY_NAME
=
"PythonJavaDriver"
CONFIGURATION_JAVA_EMBEDDING_MULTI
=
"java-driver-multi-default"
CONFIGURATION_JAVA_EMBEDDING_MULTI_SHARED
=
"java-driver-multi-shared"
CONFIGURATION_JAVA_EMBEDDING_INTERPRETER_MULTI
=
"java-driver-interpreter-multi"
CONFIGURATION_JAVA_EMBEDDING_INTERPRETER_MULTI_SHARED
=
"java-driver-interpreter-multi-shared"
DEFAULT_ITERATIONS
=
10
BENCH_BGV
=
'benchmarks-bgv'
BENCHMARK_DEBUG_ARGS
=
(
# These first two are not /too/ bad for runtime
# '--python.PoisonNativeMemoryOnFree=true',
# '--python.SampleNativeMemoryAllocSites=true',
# These below can be *extremely* heavy
# '--python.TraceNativeMemory=true',
# '--python.TraceNativeMemoryCalls=true',
# '--log.python.level=FINER',
)
# ----------------------------------------------------------------------------------------------------------------------
#
# utils
#
# ----------------------------------------------------------------------------------------------------------------------
def
is_sandboxed_configuration
(
conf
):
return
conf
in
(
CONFIGURATION_SANDBOXED
,
CONFIGURATION_SANDBOXED_MULTI
)
@
contextmanager
def
environ
(
env
):
def
_handle_var
(
key_value
):
(
k
,
v
)
=
key_value
if
v
is
None
:
del
os
.
environ
[
k
]
else
:
os
.
environ
[
k
]
=
str
(
v
)
if
env
:
prev_env
=
{
v
:
os
.
getenv
(
v
)
for
v
in
env
}
list
(
map
(
_handle_var
,
list
(
env
.
items
())))
else
:
prev_env
=
None
try
:
yield
finally
:
if
prev_env
:
list
(
map
(
_handle_var
,
list
(
prev_env
.
items
())))
# ----------------------------------------------------------------------------------------------------------------------
#
# the vm definitions
#
# ----------------------------------------------------------------------------------------------------------------------
class
AbstractPythonVm
(
OutputCapturingVm
,
ABC
):
def
__init__
(
self
,
name
,
config_name
,
options
=
None
):
super
().
__init__
()
self
.
_name
=
name
self
.
_config_name
=
config_name
self
.
_options
=
options
@
property
def
options
(
self
):
return
self
.
_options
def
name
(
self
):
return
self
.
_name
def
config_name
(
self
):
return
self
.
_config_name
@
abstractproperty
def
interpreter
(
self
):
return
None
def
post_process_command_line_args
(
self
,
args
):
return
args
def
run_vm
(
self
,
args
,
out
=
None
,
err
=
None
,
cwd
=
None
,
nonZeroIsFatal
=
False
,
env
=
None
):
cmd
=
[
self
.
interpreter
]
+
args
cmd
=
mx
.
apply_command_mapper_hooks
(
cmd
,
self
.
command_mapper_hooks
)
mx
.
logv
(
shlex
.
join
(
cmd
))
return
mx
.
run
(
cmd
,
out
=
out
,
err
=
err
,
cwd
=
cwd
,
nonZeroIsFatal
=
nonZeroIsFatal
,
env
=
env
,
)
class
AbstractPythonIterationsControlVm
(
AbstractPythonVm
):
def
__init__
(
self
,
name
,
config_name
,
options
=
None
,
iterations
=
None
):
super
().
__init__
(
name
,
config_name
,
options
=
options
)
try
:
self
.
_iterations
=
int
(
iterations
)
except
:
self
.
_iterations
=
None
def
override_iterations
(
self
,
requested_iterations
):
return
self
.
_iterations
if
self
.
_iterations
is
not
None
else
requested_iterations
def
_override_iterations_args
(
self
,
args
):
_args
=
[]
i
=
0
while
i
<
len
(
args
):
arg
=
args
[
i
]
_args
.
append
(
arg
)
if
arg
==
'-i'
:
_args
.
append
(
str
(
self
.
override_iterations
(
int
(
args
[
i
+
1
]))))
i
+=
1
i
+=
1
return
_args
def
run_vm
(
self
,
args
,
*
splat
,
**
kwargs
):
args
=
self
.
_override_iterations_args
(
args
)
return
super
().
run_vm
(
args
,
*
splat
,
**
kwargs
)
class
CPythonVm
(
AbstractPythonIterationsControlVm
):
def
__init__
(
self
,
config_name
,
options
=
None
,
virtualenv
=
None
,
iterations
=
0
):
super
().
__init__
(
"cpython"
,
config_name
,
options
=
options
,
iterations
=
iterations
)
self
.
_virtualenv
=
virtualenv
def
override_iterations
(
self
,
requested_iterations
):
# CPython has no JIT right now, just a quickening interpreter
return
min
(
requested_iterations
,
3
)
@
property
def
interpreter
(
self
):
if
venv
:=
self
.
_virtualenv
:
path
=
os
.
path
.
join
(
venv
,
'bin'
,
'python'
)
mx
.
log
(
f"Using CPython from virtualenv:
{
path
}
"
)
elif
python3_home
:=
mx
.
get_env
(
'PYTHON3_HOME'
):
path
=
os
.
path
.
join
(
python3_home
,
'python'
)
mx
.
log
(
f"Using CPython from PYTHON3_HOME:
{
path
}
"
)
elif
path
:=
shutil
.
which
(
'python'
):
mx
.
log
(
f"Using CPython from PATH:
{
path
}
"
)
else
:
assert
sys
.
implementation
.
name
==
'cpython'
,
"Cannot find CPython"
path
=
sys
.
executable
mx
.
log
(
f"Using CPython from sys.executable:
{
path
}
"
)
return
path
def
run_vm
(
self
,
args
,
*
splat
,
**
kwargs
):
for
idx
,
arg
in
enumerate
(
args
):
if
"--vm.Xmx"
in
arg
:
mx
.
warn
(
f"Ignoring
{
arg
}
, cannot restrict memory on CPython."
)
args
=
args
[:
idx
]
+
args
[
idx
+
1
:]
break
return
super
().
run_vm
(
args
,
*
splat
,
**
kwargs
)
class
PyPyVm
(
AbstractPythonIterationsControlVm
):
def
__init__
(
self
,
config_name
,
options
=
None
,
virtualenv
=
None
,
iterations
=
0
):
super
().
__init__
(
"pypy"
,
config_name
,
options
=
options
,
iterations
=
iterations
)
def
override_iterations
(
self
,
requested_iterations
):
# PyPy warms up much faster, half should be enough
return
int
(
requested_iterations
/
2
)
@
property
def
interpreter
(
self
):
if
home
:=
mx
.
get_env
(
"PYPY_HOME"
):
exe
=
join
(
home
,
"bin"
,
"pypy3"
)
else
:
try
:
exe
=
subprocess
.
check_output
(
"which pypy3"
,
shell
=
True
).
decode
().
strip
()
except
OSError
:
mx
.
abort
(
"PYPY_HOME is not set!"
)
mx
.
log
(
f"PyPy
{
exe
=
}
"
)
return
exe
def
run_vm
(
self
,
args
,
*
splat
,
env
=
None
,
**
kwargs
):
env
=
env
or
os
.
environ
.
copy
()
xmxArg
=
re
.
compile
(
"--vm.Xmx([0-9]+)([kKgGmM])"
)
pypyGcMax
=
"8GB"
for
idx
,
arg
in
enumerate
(
args
):
if
m
:=
xmxArg
.
search
(
arg
):
args
=
args
[:
idx
]
+
args
[
idx
+
1
:]
pypyGcMax
=
f"
{
m
.
group
(
1
)
}
{
m
.
group
(
2
).
upper
()
}
B"
mx
.
log
(
f"Setting PYPY_GC_MAX=
{
pypyGcMax
}
via
{
arg
}
"
)
break
else
:
mx
.
log
(
f"Setting PYPY_GC_MAX=
{
pypyGcMax
}
, use --vm.Xmx argument to override it"
)
env
[
"PYPY_GC_MAX"
]
=
pypyGcMax
return
super
().
run_vm
(
args
,
*
splat
,
env
=
env
,
**
kwargs
)
class
GraalPythonVm
(
AbstractPythonIterationsControlVm
):
def
__init__
(
self
,
config_name
,
options
=
None
,
virtualenv
=
None
,
iterations
=
None
,
extra_polyglot_args
=
None
):
super
().
__init__
(
VM_NAME_GRAALPYTHON
,
config_name
,
options
=
options
,
iterations
=
iterations
)
self
.
_extra_polyglot_args
=
extra_polyglot_args
or
[]
def
override_iterations
(
self
,
requested_iterations
):
# If we are native and without JIT, half as many iterations should be enough
if
self
.
launcher_type
==
"native"
and
"interpreter"
in
self
.
config_name
():
return
int
(
requested_iterations
/
2
)
else
:
return
requested_iterations
@
property
@
functools
.
lru_cache
def
launcher_type
(
self
):
if
mx
.
dependency
(
"GRAALPY_NATIVE_STANDALONE"
,
fatalIfMissing
=
False
):
return
"native"
else
:
return
"jvm"
@
property
@
functools
.
lru_cache
def
interpreter
(
self
):
if
self
.
config_name
().
startswith
(
CONFIGURATION_CUSTOM
):
home
=
mx
.
get_env
(
"GRAALPY_HOME"
)
if
not
home
:
mx
.
abort
(
"The custom benchmark config for graalpy is to run with a custom GRAALPY_HOME locally"
)
launcher
=
join
(
home
,
"bin"
,
"graalpy"
)
mx
.
log
(
f"Using
{
launcher
}
based on GRAALPY_HOME environment for custom config."
)
return
launcher
from
mx_graalpython
import
graalpy_standalone
launcher
=
graalpy_standalone
(
self
.
launcher_type
,
build
=
False
)
mx
.
log
(
f"Using
{
launcher
}
based on enabled/excluded GraalPy standalone build targets."
)
return
launcher
def
post_process_command_line_args
(
self
,
args
):
return
self
.
get_extra_polyglot_args
()
+
args
def
extract_vm_info
(
self
,
args
=
None
):
out_version
=
subprocess
.
check_output
([
self
.
interpreter
,
'--version'
],
universal_newlines
=
True
)
# The benchmark data goes back a ways, we modify the reported dims for
# continuity with the historical queries
graalvm_version_match
=
re
.
search
(
r"\(([^\)]+ ((?:\d+\.?)+)).*\)"
,
out_version
)
if
not
graalvm_version_match
:
mx
.
log
(
f"Using
{
out_version
}
as platform version string input"
)
graalvm_version_match
=
[
out_version
,
out_version
,
out_version
]
dims
=
{
'guest-vm'
:
self
.
name
(),
'guest-vm-config'
:
self
.
config_name
(),
'host-vm'
:
'graalvm-'
+
(
'ee'
if
'Oracle GraalVM'
in
out_version
else
'ce'
),
'host-vm-config'
:
self
.
launcher_type
,
"platform.graalvm-edition"
:
'EE'
if
'Oracle GraalVM'
in
out_version
else
'CE'
,
"platform.graalvm-version"
:
graalvm_version_match
[
2
],
"platform.graalvm-version-string"
:
graalvm_version_match
[
1
],
}
self
.
_dims
=
dims
def
run
(
self
,
*
args
,
**
kwargs
):
code
,
out
,
dims
=
super
().
run
(
*
args
,
**
kwargs
)
dims
.
update
(
self
.
_dims
)
is_uncached_config
=
self
.
config_name
().
startswith
(
CONFIGURATION_UNCACHED
)
if
(
"forced uncached interpreter: True"
not
in
out
)
==
is_uncached_config
:
mx
.
abort
(
f"ERROR: benchmark config '
{
CONFIGURATION_UNCACHED
}
' not consistent with what runtime reported."
)
return
code
,
out
,
dims
def
get_extra_polyglot_args
(
self
):
return
[
"--experimental-options"
,
"-snapshot-startup"
,
"--python.MaxNativeMemory=%s"
%
(
2
**
34
),
*
self
.
_extra_polyglot_args
]
class
GraalPythonJavaDriverVm
(
GuestVm
):
def
__init__
(
self
,
config_name
=
CONFIGURATION_DEFAULT
,
cp_suffix
=
None
,
distributions
=
None
,
cp_prefix
=
None
,
host_vm
=
None
,
extra_vm_args
=
None
,
extra_polyglot_args
=
None
):
super
().
__init__
(
host_vm
=
host_vm
)
self
.
_config_name
=
config_name
self
.
_distributions
=
distributions
or
[
'GRAALPYTHON_BENCH'
]
self
.
_cp_suffix
=
cp_suffix
self
.
_cp_prefix
=
cp_prefix
self
.
_extra_vm_args
=
extra_vm_args
self
.
_extra_polyglot_args
=
extra_polyglot_args
if
isinstance
(
extra_polyglot_args
,
list
)
else
[]
def
name
(
self
):
return
VM_NAME_GRAALPYTHON
def
config_name
(
self
):
return
self
.
_config_name
def
hosting_registry
(
self
):
return
java_vm_registry
def
get_classpath
(
self
):
cp
=
[]
if
self
.
_cp_prefix
:
cp
.
append
(
self
.
_cp_prefix
)
if
self
.
_cp_suffix
:
cp
.
append
(
self
.
_cp_suffix
)
return
cp
def
with_host_vm
(
self
,
host_vm
):
return
self
.
__class__
(
config_name
=
self
.
_config_name
,
distributions
=
self
.
_distributions
,
cp_suffix
=
self
.
_cp_suffix
,
cp_prefix
=
self
.
_cp_prefix
,
host_vm
=
host_vm
,
extra_vm_args
=
self
.
_extra_vm_args
,
extra_polyglot_args
=
self
.
_extra_polyglot_args
)
def
launcher_class
(
self
):
return
'com.oracle.graal.python.benchmarks.JavaBenchmarkDriver'
def
run
(
self
,
cwd
,
args
):
extra_polyglot_args
=
self
.
get_extra_polyglot_args
()
host_vm
=
self
.
host_vm
()
cp
=
self
.
get_classpath
()
jhm
=
mx
.
dependency
(
"mx:JMH_1_21"
)
cp_deps
=
mx
.
classpath_entries
(
filter
(
None
, [
mx
.
distribution
(
'GRAALPYTHON_BENCH'
,
fatalIfMissing
=
True
),
mx
.
distribution
(
'TRUFFLE_RUNTIME'
,
fatalIfMissing
=
True
),
mx
.
distribution
(
'TRUFFLE_ENTERPRISE'
,
fatalIfMissing
=
False
),
jhm
,
mx
.
dependency
(
"sdk:LAUNCHER_COMMON"
)
]
+
jhm
.
deps
))
cp
+=
[
x
.
classpath_repr
()
for
x
in
cp_deps
]
java_args
=
[
'-cp'
,
':'
.
join
(
cp
)]
+
[
self
.
launcher_class
()]
out
=
mx
.
TeeOutputCapture
(
mx
.
OutputCapture
())
code
=
host_vm
.
run_java
(
java_args
+
extra_polyglot_args
+
args
,
cwd
=
cwd
,
out
=
out
,
err
=
out
)
out
=
out
.
underlying
.
data
dims
=
host_vm
.
dimensions
(
cwd
,
args
,
code
,
out
)
return
code
,
out
,
dims
def
get_extra_polyglot_args
(
self
):
return
[
"--experimental-options"
,
"--python.MaxNativeMemory=%s"
%
(
2
**
34
),
*
self
.
_extra_polyglot_args
]
class
GraalPythonPolyBenchVm
(
GuestVm
):
HOSTED_INSTANCE
=
"GraalPythonPolyBenchVm.hosted="
STAGED_PROGRAM
=
"staged-benchmark.py"
# Staging rewrites a benchmark into STAGED_PROGRAM. Benchmarks listed here also need data files copied from
# GRAALPYTHON_POLYBENCH_BENCHMARKS to keep their original sibling-file lookups working.
STAGED_SIBLING_RESOURCES
=
{
"warmup/pyflate-fast.py"
: (
"graalpython-pyflate-benchmark-resource.tar.gz"
,),
}
JAVA_MODULE_ARGS_WITH_VALUE
=
(
"--add-exports"
,
"--add-modules"
,
"--add-opens"
,
"--add-reads"
,
"--enable-native-access"
,
)
LAUNCHER_ARG_PREFIXES
=
(
"--python."
,
"--engine."
,
"--vm."
,
"--inspect"
,
"--log."
,
"--experimental-options"
,
)
PYTHONPATH_LAUNCHER_ARG
=
"--python.PythonPath"
STAGING_INCOMPATIBLE_ARG_PREFIXES
=
(
"--vm."
,
"--inspect"
,
)
def
__init__
(
self
,
config_name
=
CONFIGURATION_DEFAULT
,
host_vm
=
None
,
extra_launcher_args
=
None
):
super
().
__init__
(
host_vm
=
host_vm
)
self
.
_config_name
=
self
.
canonical_config_name
(
config_name
)
self
.
_extra_launcher_args
=
list
(
extra_launcher_args
or
[])
self
.
_guest_run_on_java_home_value
=
None
self
.
_guest_run_on_java_home_set
=
False
def
name
(
self
):
return
VM_NAME_GRAALPYTHON
def
config_name
(
self
):
return
self
.
_config_name
@
staticmethod
def
canonical_config_name
(
config_name
):
return
config_name
if
config_name
else
CONFIGURATION_DEFAULT
def
hosting_registry
(
self
):
return
java_vm_registry
def
with_host_vm
(
self
,
host_vm
):
hosted_name
=
(
f"
{
self
.
HOSTED_INSTANCE
}
{
self
.
name
()
}
:
{
self
.
config_name
()
}
@
{
host_vm
.
name
()
}
:
{
host_vm
.
config_name
()
}
"
)
if
not
bm_exec_context
().
has
(
hosted_name
):
hosted_instance
=
self
.
__class__
(
self
.
config_name
(),
host_vm
=
host_vm
,
extra_launcher_args
=
self
.
_extra_launcher_args
)
bm_exec_context
().
add_context_value
(
hosted_name
,
mx_benchmark
.
ConstantContextValue
(
hosted_instance
))
hosted_instance
=
bm_exec_context
().
get
(
hosted_name
)
if
self
.
_guest_run_on_java_home_set
:
hosted_instance
.
set_run_on_java_home
(
self
.
_guest_run_on_java_home_value
)
return
hosted_instance
def
set_run_on_java_home
(
self
,
value
):
self
.
_guest_run_on_java_home_value
=
value
self
.
_guest_run_on_java_home_set
=
True
host
=
self
.
host_vm
()
if
host
is
not
None
and
hasattr
(
host
,
"set_run_on_java_home"
):
host
.
set_run_on_java_home
(
value
)
def
run_on_java_home
(
self
):
if
self
.
_guest_run_on_java_home_set
:
return
self
.
_guest_run_on_java_home_value
host
=
self
.
host_vm
()
if
host
is
not
None
and
hasattr
(
host
,
"run_on_java_home"
):
return
host
.
run_on_java_home
()
return
None
def
extract_vm_info
(
self
,
args
=
None
):
self
.
_host_vm_for_execution
().
extract_vm_info
(
args
)
def
polybench_staging_run_args
(
self
,
run_args
):
return
[
arg
for
arg
in
run_args
if
not
self
.
_is_staging_incompatible_arg
(
arg
)]
@
classmethod
def
_is_launcher_arg
(
cls
,
arg
):
return
arg
.
startswith
(
cls
.
LAUNCHER_ARG_PREFIXES
)
@
classmethod
def
_is_staging_incompatible_arg
(
cls
,
arg
):
return
arg
.
startswith
(
cls
.
STAGING_INCOMPATIBLE_ARG_PREFIXES
)
def
_launcher_args
(
self
):
run_args
=
bm_exec_context
().
get
(
"bm_suite_args"
)
launcher_args
=
list
(
self
.
_extra_launcher_args
)
launcher_args
+=
[
arg
for
arg
in
self
.
bmSuite
.
runArgs
(
run_args
)
if
self
.
_is_launcher_arg
(
arg
)]
return
launcher_args
def
_host_vm_for_execution
(
self
):
host
=
self
.
host_vm
()
if
host
is
None
:
mx
.
abort
(
"GraalPy PolyBench guest VM requires a host VM; none was provided."
)
if
not
isinstance
(
host
,
mx_sdk_benchmark
.
NativeImageVM
):
mx
.
abort
(
f"GraalPy PolyBench guest VM requires NativeImageVM host; got
{
host
.
__class__
.
__name__
}
."
)
if
host
.
pgo_sampler_only
or
host
.
pgo_use_perf
:
mx
.
abort
(
"GraalPy PolyBench native launcher staging supports instrumentation PGO, but not PGO sampling."
)
return
host
def
prepare_stages
(
self
,
bm_suite
,
bm_suite_args
):
return
self
.
_host_vm_for_execution
().
prepare_stages
(
bm_suite
,
bm_suite_args
)
def
run
(
self
,
cwd
,
args
):
host
=
self
.
_host_vm_for_execution
()
self
.
extract_vm_info
(
args
)
args
=
host
.
post_process_command_line_args
(
args
)
host
.
bmSuite
=
self
.
bmSuite
host
.
stages_info
=
self
.
bmSuite
.
stages_info
out
=
mx
.
TeeOutputCapture
(
mx
.
OutputCapture
())
host
.
config
=
mx_sdk_benchmark
.
NativeImageBenchmarkConfig
(
host
,
self
.
bmSuite
,
args
)
host
.
stages
=
mx_sdk_benchmark
.
StagesContext
(
host
,
out
,
out
,
False
,
os
.
path
.
abspath
(
cwd
if
cwd
else
os
.
getcwd
())
)
host
.
config
.
output_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
host
.
config
.
config_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
host
.
config
.
image_build_reports_directory
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
code
=
self
.
_run_single_stage
(
host
)
output
=
out
.
underlying
.
data
return
code
,
output
,
host
.
dimensions
(
cwd
,
args
,
code
,
output
)
def
_run_single_stage
(
self
,
host
):
stage
=
host
.
stages_info
.
current_stage
.
stage_name
if
stage
==
StageName
.
INSTRUMENT_IMAGE
:
return
self
.
_run_stage_instrument_image
(
host
)
if
stage
==
StageName
.
INSTRUMENT_RUN
:
return
self
.
_run_stage_instrument_run
(
host
)
if
stage
==
StageName
.
IMAGE
:
return
self
.
_run_stage_image
(
host
)
if
stage
==
StageName
.
RUN
:
return
self
.
_run_stage_run
(
host
)
mx
.
abort
(
f"Unknown stage
{
stage
}
"
)
def
_run_stage_instrument_image
(
self
,
host
):
with
host
.
get_stage_runner
()
as
runner
:
exit_code
=
self
.
_build_standalone
(
host
,
runner
,
instrumented
=
True
)
if
exit_code
==
0
:
self
.
_move_image_build_stats_file
(
host
,
StageName
.
INSTRUMENT_IMAGE
)
return
exit_code
def
_run_stage_image
(
self
,
host
):
with
host
.
get_stage_runner
()
as
runner
:
exit_code
=
self
.
_build_standalone
(
host
,
runner
,
instrumented
=
False
)
if
exit_code
==
0
:
self
.
_move_image_build_stats_file
(
host
,
StageName
.
IMAGE
)
return
exit_code
def
_run_stage_instrument_run
(
self
,
host
):
launcher
=
self
.
_launcher
(
host
,
instrumented
=
True
)
profile_vm_args
=
[
f"--vm.XX:ProfilesDumpFile=
{
host
.
config
.
profile_path
}
"
,
f"--vm.XX:ProfilesLCOVFile=
{
host
.
config
.
output_dir
/
'graalpy.info'
}
"
,
]
with
host
.
get_stage_runner
()
as
runner
:
exit_code
=
self
.
_stage_harness
(
host
,
runner
)
if
exit_code
!=
0
:
return
exit_code
with
self
.
_graal_python_vm_args
(
*
profile_vm_args
):
with
self
.
_graalpy_launcher_env
():
return
runner
.
execute_command
(
host
, [
str
(
launcher
)]
+
self
.
_profile_launcher_args
(
host
)
+
[
str
(
self
.
_staged_program
(
host
))]
)
def
_run_stage_run
(
self
,
host
):
with
host
.
get_stage_runner
()
as
runner
:
exit_code
=
self
.
_stage_harness
(
host
,
runner
)
if
exit_code
!=
0
:
return
exit_code
with
self
.
_graalpy_launcher_env
():
return
runner
.
execute_command
(
host
,
[
str
(
self
.
_launcher
(
host
,
instrumented
=
False
))]
+
self
.
_run_launcher_args
(
host
)
+
[
str
(
self
.
_staged_program
(
host
))],
)
def
_stage_harness
(
self
,
host
,
runner
):
# Native stable PolyBench shares image stages across benchmarks, but the staged harness is benchmark-specific.
staging_args
=
[
"--stage-to-language"
,
"Python"
,
"--stage-to-file"
,
str
(
self
.
_staged_program
(
host
)),
"--log-staged-program"
,
"True"
,
]
self
.
_staged_program
(
host
).
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
image_run_args
=
self
.
_polybench_staging_run_args
(
host
,
runner
.
config
.
image_run_args
)
java_args
=
(
runner
.
config
.
classpath_arguments
+
runner
.
config
.
modulepath_arguments
+
runner
.
config
.
system_properties
+
self
.
_java_staging_vm_args
(
runner
.
config
.
image_vm_args
or
[])
+
runner
.
config
.
executable
+
image_run_args
+
staging_args
)
exit_code
=
self
.
_execute_setup_command
(
host
,
runner
,
host
.
generate_java_command
(
java_args
))
if
exit_code
==
0
:
self
.
_copy_staged_sibling_resources
(
host
)
return
exit_code
def
_copy_staged_sibling_resources
(
self
,
host
):
# A few staged Python benchmarks load data files relative to __file__. Keep this targeted so the staging
# directory only grows for benchmarks that are known to need sibling resources.
benchmark
=
bm_exec_context
().
get
(
"benchmark"
)
resources
=
self
.
STAGED_SIBLING_RESOURCES
.
get
(
benchmark
, ())
if
not
resources
:
return
source_dir
=
Path
(
mx
.
dependency
(
"GRAALPYTHON_POLYBENCH_BENCHMARKS"
).
get_output
())
/
Path
(
benchmark
).
parent
destination_dir
=
self
.
_staged_program
(
host
).
parent
for
resource
in
resources
:
source
=
source_dir
/
resource
if
not
source
.
is_file
():
mx
.
abort
(
f"Required staged benchmark resource does not exist:
{
source
}
"
)
shutil
.
copy2
(
source
,
destination_dir
/
resource
)
@
staticmethod
def
_java_staging_vm_args
(
image_vm_args
):
return
[
arg
for
arg
in
image_vm_args
if
not
arg
.
startswith
(
"-H"
)]
@
staticmethod
def
_execute_setup_command
(
host
,
runner
,
command
):
mx
.
log
(
"Running: "
)
mx
.
log
(
" "
.
join
(
command
))
write_output
=
False
runner
.
exit_code
=
mx
.
run
(
command
,
out
=
runner
.
stdout
(
write_output
),
err
=
runner
.
stderr
(
write_output
),
cwd
=
host
.
stages
.
cwd
,
nonZeroIsFatal
=
False
,
env
=
host
.
config
.
bm_suite
.
get_stage_env
(),
)
return
runner
.
exit_code
def
_build_standalone
(
self
,
host
,
runner
,
instrumented
):
enterprise
=
host
.
graalvm_edition
==
"ee"
use_product_profile
=
getattr
(
host
,
"product_profile"
,
False
)
and
enterprise
if
instrumented
:
pgo_profile
=
""
elif
host
.
pgo_instrumentation
:
pgo_profile
=
host
.
config
.
bm_suite
.
get_pgo_profile_for_image_build
(
host
.
config
.
profile_path
)
else
:
pgo_profile
=
None
if
pgo_profile
is
not
None
:
pgo_profile
=
str
(
pgo_profile
)
# GRAALPY_PGO_PROFILE is a GraalPy build switch:
# unset: let libpythonvm_build_args auto-select the CI generated PGO profile;
# "": suppress auto-selection and, for benchmark-local PGO, build an instrumented image instead;
# path: build the final image with that explicit profile.
# GRAALPY_REQUIRE_PGO_PROFILE is separate: product-ee sets it to fail if the CI profile cannot be downloaded.
env_pgo_profile
=
pgo_profile
if
pgo_profile
is
not
None
else
(
None
if
use_product_profile
else
""
)
env_require_pgo_profile
=
"true"
if
use_product_profile
else
None
from
mx_graalpython
import
(
BUILD_NATIVE_IMAGE_WITH_ASSERTIONS
,
GITHUB_CI
,
_graalpy_launcher
,
run_mx
,
set_env
,
)
standalone_dist
=
"GRAALPY_NATIVE_STANDALONE"
mx_args
=
[
"-p"
,
SUITE
.
dir
,
"--env"
,
"native-ee"
if
enterprise
else
"native-ce"
]
mx_args
.
append
(
"--extra-image-builder-argument=-Ob"
if
GITHUB_CI
else
"--extra-image-builder-argument=-g"
)
if
pgo_profile
is
not
None
:
if
not
enterprise
:
mx
.
abort
(
"PGO is only supported on enterprise NI"
)
if
pgo_profile
:
mx_args
.
append
(
f"--extra-image-builder-argument=--pgo=
{
pgo_profile
}
"
)
mx_args
.
append
(
"--extra-image-builder-argument=-H:+UnlockExperimentalVMOptions"
)
mx_args
.
append
(
"--extra-image-builder-argument=-H:+PGOPrintProfileQuality"
)
else
:
mx_args
.
append
(
"--extra-image-builder-argument=--pgo-instrument"
)
mx_args
.
append
(
"--extra-image-builder-argument=-H:+UnlockExperimentalVMOptions"
)
mx_args
.
append
(
"--extra-image-builder-argument=-H:+ProfilingLCOV"
)
elif
BUILD_NATIVE_IMAGE_WITH_ASSERTIONS
and
not
use_product_profile
:
mx_args
.
append
(
"--extra-image-builder-argument=-ea"
)
mx_args
.
append
(
"--extra-image-builder-argument=-J-ea"
)
for
arg
in
self
.
_mx_extra_image_builder_args
(
self
.
_image_build_args
(
host
)):
mx_args
.
append
(
f"--extra-image-builder-argument=
{
arg
}
"
)
with
set_env
(
GRAALPY_PGO_PROFILE
=
env_pgo_profile
,
GRAALPY_REQUIRE_PGO_PROFILE
=
env_require_pgo_profile
):
write_output
=
host
.
stages_info
.
should_produce_datapoints
()
exit_code
=
run_mx
(
mx_args
+
[
"build"
,
"-f"
,
"--only"
,
f"libpythonvm,
{
standalone_dist
}
"
],
nonZeroIsFatal
=
False
,
out
=
runner
.
stdout
(
write_output
),
err
=
runner
.
stderr
(
write_output
),
)
runner
.
exit_code
=
exit_code
if
exit_code
!=
0
:
return
exit_code
standalone_home
=
self
.
_platform_mxbuild_output
(
standalone_dist
)
libpythonvm_home
=
self
.
_platform_mxbuild_output
(
"libpythonvm"
)
debug_info
=
libpythonvm_home
/
"libpythonvm.so.debug"
if
debug_info
.
exists
():
shutil
.
copy
(
debug_info
,
standalone_home
/
"lib"
)
destination
=
self
.
_standalone_home
(
host
,
instrumented
=
instrumented
)
if
destination
.
exists
():
shutil
.
rmtree
(
destination
)
shutil
.
copytree
(
standalone_home
,
destination
,
symlinks
=
True
)
launcher
=
destination
/
"bin"
/
_graalpy_launcher
()
if
not
launcher
.
is_file
():
mx
.
abort
(
f"GraalPy launcher was not built at expected path:
{
launcher
}
"
)
self
.
_copy_native_image_artifact
(
host
,
destination
,
instrumented
=
instrumented
)
return
exit_code
def
_copy_native_image_artifact
(
self
,
host
,
standalone_home
,
instrumented
):
libpythonvm
=
standalone_home
/
"lib"
/
mx
.
add_lib_suffix
(
mx
.
add_lib_prefix
(
"pythonvm"
))
if
not
libpythonvm
.
is_file
():
mx
.
abort
(
f"GraalPy native image artifact was not built at expected path:
{
libpythonvm
}
"
)
destination
=
host
.
config
.
instrumented_image_path
if
instrumented
else
host
.
config
.
image_path
if
destination
.
exists
():
destination
.
unlink
()
shutil
.
copy2
(
libpythonvm
,
destination
)
def
_image_build_args
(
self
,
host
):
stage_name
=
host
.
stages_info
.
current_stage
.
stage_name
args
=
[
f"-H:BuildOutputJSONFile=
{
host
.
config
.
get_build_output_json_file
(
stage_name
)
}
"
,
"-H:+CollectImageBuildStatistics"
,
]
args
+=
host
.
config
.
system_properties
args
+=
self
.
_standalone_image_vm_args
(
host
.
config
.
image_vm_args
or
[])
if
host
.
gc
:
args
+=
[
"--gc="
+
host
.
gc
,
"-H:+SpawnIsolates"
]
if
host
.
native_architecture
:
args
.
append
(
"-march=native"
)
if
host
.
future_defaults_all
:
args
.
append
(
"--future-defaults=all"
)
if
host
.
optimization_level
:
args
.
append
(
"-"
+
host
.
optimization_level
)
if
host
.
is_quickbuild
:
args
.
append
(
"-Ob"
)
args
+=
host
.
config
.
extra_image_build_arguments
return
mx_sdk_benchmark
.
svm_experimental_options
(
args
)
@
classmethod
def
_mx_extra_image_builder_args
(
cls
,
args
):
# GraalPy standalone builds receive these through mx --extra-image-builder-argument, whose suite-side
# filtering keeps option-like args and drops bare operands. Use the equivalent --option=value form for
# Java module options that NativeImageVM keeps as space-separated pairs.
normalized_args
=
[]
i
=
0
while
i
<
len
(
args
):
arg
=
args
[
i
]
if
arg
in
cls
.
JAVA_MODULE_ARGS_WITH_VALUE
:
if
i
+
1
>=
len
(
args
):
mx
.
abort
(
f"Missing value for native-image argument
{
arg
}
"
)
normalized_args
.
append
(
f"
{
arg
}
=
{
args
[
i
+
1
]
}
"
)
i
+=
2
else
:
normalized_args
.
append
(
arg
)
i
+=
1
return
normalized_args
@
classmethod
def
_standalone_image_vm_args
(
cls
,
args
):
# These module-access arguments come from the Java PolyBench launcher command. They are valid for building
# that launcher image, but not for the separate GraalPy standalone/libpythonvm image build.
standalone_args
=
[]
i
=
0
while
i
<
len
(
args
):
arg
=
args
[
i
]
if
arg
in
cls
.
JAVA_MODULE_ARGS_WITH_VALUE
:
i
+=
2
elif
any
(
arg
.
startswith
(
f"
{
prefix
}
="
)
for
prefix
in
cls
.
JAVA_MODULE_ARGS_WITH_VALUE
):
i
+=
1
else
:
standalone_args
.
append
(
arg
)
i
+=
1
return
standalone_args
def
_move_image_build_stats_file
(
self
,
host
,
stage
):
stats_file
=
self
.
_platform_mxbuild_output
(
"libpythonvm"
)
/
"reports"
/
"image_build_statistics.json"
destination
=
host
.
config
.
get_image_build_stats_file
(
stage
)
if
not
stats_file
.
is_file
():
# Stable PolyBench may revisit an image stage after the shared GraalPy image was already built.
if
destination
.
is_file
():
mx
.
log
(
f"Reusing image build statistics file from earlier stage execution:
{
destination
}
"
)
return
mx
.
abort
(
f"Could not find image build statistics file at expected path:
{
stats_file
}
"
)
if
destination
.
exists
():
destination
.
unlink
()
mx
.
move
(
stats_file
,
destination
)
def
_extra_native_run_args
(
self
,
_host
,
prefix
):
vm_args
=
self
.
bmSuite
.
vmArgs
(
bm_exec_context
().
get
(
"bm_suite_args"
))
return
mx_sdk_benchmark
.
parse_prefixed_args
(
prefix
,
vm_args
)
@
staticmethod
def
_platform_mxbuild_output
(
name
):
# The native standalone may be removed from mx's active dependency graph after build; its artifacts still
# live in the platform-dependent mxbuild output directory.
return
Path
(
SUITE
.
dir
)
/
"mxbuild"
/
f"
{
mx
.
get_os
()
}
-
{
mx
.
get_arch
()
}
"
/
name
def
_polybench_staging_run_args
(
self
,
host
,
image_run_args
):
extra_run_args
=
self
.
_extra_native_run_args
(
host
,
"-Dnative-image.benchmark.extra-run-arg="
)
if
extra_run_args
and
image_run_args
[
-
len
(
extra_run_args
):]
==
extra_run_args
:
return
image_run_args
[:
-
len
(
extra_run_args
)]
return
image_run_args
def
_profile_launcher_args
(
self
,
host
):
extra_profile_args
=
self
.
_extra_native_run_args
(
host
,
"-Dnative-image.benchmark.extra-profile-run-arg="
)
if
not
extra_profile_args
:
extra_profile_args
=
self
.
_extra_native_run_args
(
host
,
"-Dnative-image.benchmark.extra-run-arg="
)
return
self
.
_launcher_args
()
+
host
.
config
.
extra_jvm_args
+
extra_profile_args
def
_run_launcher_args
(
self
,
host
):
return
self
.
_launcher_args
()
+
host
.
config
.
extra_jvm_args
+
self
.
_extra_native_run_args
(
host
,
"-Dnative-image.benchmark.extra-run-arg="
)
def
_launcher_pythonpath
(
self
):
prefix
=
f"
{
self
.
PYTHONPATH_LAUNCHER_ARG
}
="
for
arg
in
reversed
(
self
.
_launcher_args
()):
if
arg
.
startswith
(
prefix
):
return
arg
[
len
(
prefix
):]
return
None
@
contextmanager
def
_graalpy_launcher_env
(
self
):
pythonpath
=
self
.
_launcher_pythonpath
()
if
pythonpath
is
None
:
yield
return
from
mx_graalpython
import
set_env
# GraalPy launcher reads PYTHONPATH after generic launcher option parsing, so keep it aligned
# with the explicit PolyBench launcher option while running the staged native standalone.
with
set_env
(
PYTHONPATH
=
pythonpath
):
yield
@
contextmanager
def
_graal_python_vm_args
(
self
,
*
new_args
):
from
mx_graalpython
import
set_env
existing
=
os
.
environ
.
get
(
"GRAAL_PYTHON_VM_ARGS"
)
value
=
"
\v
"
.
join
(([
existing
]
if
existing
else
[])
+
list
(
new_args
))
with
set_env
(
GRAAL_PYTHON_VM_ARGS
=
value
):
yield
def
_staged_program
(
self
,
host
):
return
host
.
config
.
output_dir
/
"graalpython"
/
self
.
STAGED_PROGRAM
def
_standalone_home
(
self
,
host
,
instrumented
):
return
host
.
config
.
output_dir
/
(
"graalpy-instrumented"
if
instrumented
else
"graalpy"
)
def
_launcher
(
self
,
host
,
instrumented
):
from
mx_graalpython
import
_graalpy_launcher
return
self
.
_standalone_home
(
host
,
instrumented
=
instrumented
)
/
"bin"
/
_graalpy_launcher
()
# ----------------------------------------------------------------------------------------------------------------------
#
# the benchmark definition
#
# ----------------------------------------------------------------------------------------------------------------------
python_vm_registry
=
mx_benchmark
.
VmRegistry
(
PYTHON_VM_REGISTRY_NAME
,
known_host_registries
=
[
java_vm_registry
])
python_java_embedding_vm_registry
=
mx_benchmark
.
VmRegistry
(
PYTHON_JAVA_EMBEDDING_VM_REGISTRY_NAME
,
known_host_registries
=
[
java_vm_registry
])
class
PythonBaseBenchmarkSuite
(
VmBenchmarkSuite
,
AveragingBenchmarkMixin
):
def
__init__
(
self
,
name
,
benchmarks
):
super
().
__init__
()
self
.
_checkup
=
'GRAALPYTHON_BENCHMARKS_CHECKUP'
in
os
.
environ
self
.
_name
=
name
self
.
_benchmarks
=
benchmarks
self
.
_graph_dump_time
=
None
self
.
_benchmarks_graphs
=
{}
def
has_graph_tags
(
self
,
benchmark
):
has_tag
=
False
self
.
_benchmarks_graphs
[
benchmark
]
=
set
()
benchmark_path
=
join
(
self
.
_bench_path
,
"{}.py"
.
format
(
benchmark
))
with
open
(
benchmark_path
,
'r'
)
as
fp
:
text
=
fp
.
read
()
for
l
in
text
.
split
(
'
\n
'
):
if
'# igv:'
in
l
:
s
=
l
.
replace
(
'# igv:'
,
''
).
strip
()
if
s
:
self
.
_benchmarks_graphs
[
benchmark
].
add
(
s
)
has_tag
=
True
return
benchmark
if
has_tag
else
None
def
has_graph_option
(
self
,
bmSuiteArgs
):
if
"--graph"
in
bmSuiteArgs
:
import
time
self
.
_graph_dump_time
=
time
.
time
()
os
.
mkdir
(
join
(
BENCH_BGV
,
'%d'
%
self
.
_graph_dump_time
))
bmSuiteArgs
.
remove
(
'--graph'
)
return
True
return
False
def
add_graph_dump_option
(
self
,
bmSuiteArgs
,
benchmark
):
if
self
.
_graph_dump_time
and
self
.
_benchmarks_graphs
.
get
(
benchmark
):
dump_opt
=
'-Dgraal.Dump='
dump_path
=
join
(
BENCH_BGV
,
'%d'
%
self
.
_graph_dump_time
,
'run'
)
dump_path_opt
=
'-Dgraal.DumpPath='
+
dump_path
if
dump_opt
not
in
bmSuiteArgs
:
return
[
dump_opt
,
dump_path_opt
]
return
[
dump_path_opt
]
return
[]
def
post_run_graph
(
self
,
benchmark
,
host_vm_config
,
guest_vm_config
):
graph_tags
=
self
.
_benchmarks_graphs
.
get
(
benchmark
)
if
self
.
_graph_dump_time
and
graph_tags
:
repo_hash
=
SUITE
.
vc
.
tip
(
SUITE
.
dir
,
'master'
).
strip
()[:
7
]
name_format
=
'{h}.{g_vm}.{h_vm}.{s}.{b}.{t}.bgv'
dump_path
=
join
(
BENCH_BGV
,
'%d'
%
self
.
_graph_dump_time
,
'run'
)
selected_bgv
=
{}
num_tags
=
len
(
graph_tags
)
for
f
in
sorted
(
os
.
listdir
(
dump_path
),
reverse
=
True
):
selected
=
False
if
num_tags
==
0
or
not
f
.
endswith
(
'.bgv'
):
os
.
remove
(
join
(
dump_path
,
f
))
continue
for
t
in
graph_tags
:
if
t
in
selected_bgv
:
continue
if
t
in
f
:
graph_tags
.
remove
(
t
)
selected
=
True
num_tags
-=
1
selected_bgv
[
t
]
=
f
break
if
not
selected
:
os
.
remove
(
join
(
dump_path
,
f
))
bench_bgv_dir
=
join
(
BENCH_BGV
,
'%d'
%
self
.
_graph_dump_time
)
for
t
in
selected_bgv
:
old_name
=
selected_bgv
[
t
]
new_name
=
name_format
.
format
(
h
=
repo_hash
,
g_vm
=
guest_vm_config
,
h_vm
=
host_vm_config
,
s
=
self
.
_name
,
b
=
benchmark
,
t
=
t
)
print
(
'rename: %s to %s'
%
(
old_name
,
new_name
))
os
.
rename
(
join
(
dump_path
,
old_name
),
join
(
bench_bgv_dir
,
new_name
))
if
graph_tags
:
print
(
'The following tags did not correspond to any bgv file:'
)
print
(
'
\n
'
.
join
(
graph_tags
))
raise
FileNotFoundError
def
benchmarkList
(
self
,
bmSuiteArgs
):
if
self
.
has_graph_option
(
bmSuiteArgs
):
return
[
b
for
b
in
self
.
_benchmarks
.
keys
()
if
self
.
has_graph_tags
(
b
)]
return
list
(
self
.
_benchmarks
.
keys
())
def
benchmarks
(
self
):
raise
FutureWarning
(
'the benchmarks method has been deprecated for VmBenchmarkSuite instances, '
'use the benchmarkList method instead'
)
def
successPatterns
(
self
):
return
[
re
.
compile
(
r"^### iteration=(?P<iteration>[0-9]+), name=(?P<benchmark>[a-zA-Z0-9.\-_]+), duration=(?P<time>[0-9]+(\.[0-9]+)?$)"
,
re
.
MULTILINE
),
# pylint: disable=line-too-long
re
.
compile
(
r"^@@@ name=(?P<benchmark>[a-zA-Z0-9.\-_]+), duration=(?P<time>[0-9]+(\.[0-9]+)?$)"
,
re
.
MULTILINE
),
# pylint: disable=line-too-long
]
def
failurePatterns
(
self
):
return
[
# lookahead pattern for when truffle compilation details are enabled in the log
re
.
compile
(
r"^(?!(\[truffle\])).*Exception"
)
]
def
group
(
self
):
return
GROUP_GRAAL
def
name
(
self
):
return
self
.
_name
def
subgroup
(
self
):
return
SUBGROUP_GRAAL_PYTHON
@
staticmethod
def
with_branch_and_commit_dict
(
d
):
"""
We run our benchmark from the graalpython directories, but with other
suites as primary suites in the CI, so we potentially want to update
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL