Mercurial > hg > graal-jvmci-8
comparison mx/commands.py @ 11367:39b86b83ddeb
normalized the command line interface for the dacapo, scaladacapo, specjvm2008, specjbb2005 and specjbb2013 commands
specjbb*: mx <command> [VM options] ["--" [<benchmark options>]]
others: mx <command> [VM options] benchmarks...|"all" [<benchmark options>]
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 20 Aug 2013 00:04:44 +0200 |
parents | 51b0b1104114 |
children | c64d90e962ed |
comparison
equal
deleted
inserted
replaced
11366:d335c16d2fe7 | 11367:39b86b83ddeb |
---|---|
29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing | 29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing |
30 from os.path import join, exists, dirname, basename, getmtime | 30 from os.path import join, exists, dirname, basename, getmtime |
31 from argparse import ArgumentParser, REMAINDER | 31 from argparse import ArgumentParser, REMAINDER |
32 import mx | 32 import mx |
33 import sanitycheck | 33 import sanitycheck |
34 import itertools | |
34 import json, textwrap | 35 import json, textwrap |
35 | 36 |
36 # This works because when mx loads this file, it makes sure __file__ gets an absolute path | 37 # This works because when mx loads this file, it makes sure __file__ gets an absolute path |
37 _graal_home = dirname(dirname(__file__)) | 38 _graal_home = dirname(dirname(__file__)) |
38 | 39 |
189 mx.log('Cleaning up...') | 190 mx.log('Cleaning up...') |
190 shutil.rmtree(tmp) | 191 shutil.rmtree(tmp) |
191 | 192 |
192 mx.log('Created distribution in ' + zfName) | 193 mx.log('Created distribution in ' + zfName) |
193 | 194 |
195 def _run_benchmark(args, availableBenchmarks, runBenchmark): | |
196 | |
197 vmOpts, benchmarksAndOptions = _extract_VM_args(args, useDoubleDash=availableBenchmarks is None) | |
198 | |
199 if availableBenchmarks is None: | |
200 harnessArgs = benchmarksAndOptions | |
201 return runBenchmark(None, harnessArgs, vmOpts) | |
202 | |
203 if len(benchmarksAndOptions) == 0: | |
204 mx.abort('at least one benchmark name or "all" must be specified') | |
205 benchmarks = list(itertools.takewhile(lambda x: not x.startswith('-'), benchmarksAndOptions)) | |
206 harnessArgs = benchmarksAndOptions[len(benchmarks):] | |
207 | |
208 if 'all' in benchmarks: | |
209 benchmarks = availableBenchmarks | |
210 else: | |
211 for bm in benchmarks: | |
212 if bm not in availableBenchmarks: | |
213 mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(availableBenchmarks)) | |
214 | |
215 failed = [] | |
216 for bm in benchmarks: | |
217 if not runBenchmark(bm, harnessArgs, vmOpts): | |
218 failed.append(bm) | |
219 | |
220 if len(failed) != 0: | |
221 mx.abort('Benchmark failures: ' + str(failed)) | |
222 | |
194 def dacapo(args): | 223 def dacapo(args): |
195 """run one or all DaCapo benchmarks | 224 """run one or more DaCapo benchmarks""" |
196 | 225 |
197 DaCapo options are distinguished from VM options by a '@' prefix. | 226 def launcher(bm, harnessArgs, extraVmOpts): |
198 For example, '@-n @5' will pass '-n 5' to the | 227 return sanitycheck.getDacapo(bm, harnessArgs).test(_get_vm(), extraVmOpts=extraVmOpts) |
199 DaCapo harness.""" | 228 |
200 | 229 _run_benchmark(args, sanitycheck.dacapoSanityWarmup.keys(), launcher) |
201 numTests = {} | |
202 if len(args) > 0: | |
203 level = getattr(sanitycheck.SanityCheckLevel, args[0], None) | |
204 if level is not None: | |
205 del args[0] | |
206 for (bench, ns) in sanitycheck.dacapoSanityWarmup.items(): | |
207 if ns[level] > 0: | |
208 numTests[bench] = ns[level] | |
209 else: | |
210 while len(args) != 0 and args[0][0] not in ['-', '@']: | |
211 n = 1 | |
212 if args[0].isdigit(): | |
213 n = int(args[0]) | |
214 assert len(args) > 1 and args[1][0] not in ['-', '@'] and not args[1].isdigit() | |
215 bm = args[1] | |
216 del args[0] | |
217 else: | |
218 bm = args[0] | |
219 | |
220 del args[0] | |
221 if bm not in sanitycheck.dacapoSanityWarmup.keys(): | |
222 mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(sanitycheck.dacapoSanityWarmup.keys())) | |
223 numTests[bm] = n | |
224 | |
225 if len(numTests) is 0: | |
226 for bench in sanitycheck.dacapoSanityWarmup.keys(): | |
227 numTests[bench] = 1 | |
228 | |
229 # Extract DaCapo options | |
230 dacapoArgs = [(arg[1:]) for arg in args if arg.startswith('@')] | |
231 | |
232 # The remainder are VM options | |
233 vmOpts = [arg for arg in args if not arg.startswith('@')] | |
234 vm = _get_vm() | |
235 | |
236 failed = [] | |
237 for (test, n) in numTests.items(): | |
238 if not sanitycheck.getDacapo(test, n, dacapoArgs).test(vm, opts=vmOpts): | |
239 failed.append(test) | |
240 | |
241 if len(failed) != 0: | |
242 mx.abort('DaCapo failures: ' + str(failed)) | |
243 | 230 |
244 def scaladacapo(args): | 231 def scaladacapo(args): |
245 """run one or all Scala DaCapo benchmarks | 232 """run one or more Scala DaCapo benchmarks""" |
246 | 233 |
247 Scala DaCapo options are distinguished from VM options by a '@' prefix. | 234 def launcher(bm, harnessArgs, extraVmOpts): |
248 For example, '@--iterations @5' will pass '--iterations 5' to the | 235 return sanitycheck.getScalaDacapo(bm, harnessArgs).test(_get_vm(), extraVmOpts=extraVmOpts) |
249 DaCapo harness.""" | 236 |
250 | 237 _run_benchmark(args, sanitycheck.dacapoScalaSanityWarmup.keys(), launcher) |
251 numTests = {} | |
252 | |
253 if len(args) > 0: | |
254 level = getattr(sanitycheck.SanityCheckLevel, args[0], None) | |
255 if level is not None: | |
256 del args[0] | |
257 for (bench, ns) in sanitycheck.dacapoScalaSanityWarmup.items(): | |
258 if ns[level] > 0: | |
259 numTests[bench] = ns[level] | |
260 else: | |
261 while len(args) != 0 and args[0][0] not in ['-', '@']: | |
262 n = 1 | |
263 if args[0].isdigit(): | |
264 n = int(args[0]) | |
265 assert len(args) > 1 and args[1][0] not in ['-', '@'] and not args[1].isdigit() | |
266 bm = args[1] | |
267 del args[0] | |
268 else: | |
269 bm = args[0] | |
270 | |
271 del args[0] | |
272 if bm not in sanitycheck.dacapoScalaSanityWarmup.keys(): | |
273 mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(sanitycheck.dacapoScalaSanityWarmup.keys())) | |
274 numTests[bm] = n | |
275 | |
276 if len(numTests) is 0: | |
277 for bench in sanitycheck.dacapoScalaSanityWarmup.keys(): | |
278 numTests[bench] = 1 | |
279 | |
280 # Extract DaCapo options | |
281 dacapoArgs = [(arg[1:]) for arg in args if arg.startswith('@')] | |
282 | |
283 # The remainder are VM options | |
284 vmOpts = [arg for arg in args if not arg.startswith('@')] | |
285 vm = _get_vm() | |
286 | |
287 failed = [] | |
288 for (test, n) in numTests.items(): | |
289 if not sanitycheck.getScalaDacapo(test, n, dacapoArgs).test(vm, opts=vmOpts): | |
290 failed.append(test) | |
291 | |
292 if len(failed) != 0: | |
293 mx.abort('Scala DaCapo failures: ' + str(failed)) | |
294 | 238 |
295 def _arch(): | 239 def _arch(): |
296 machine = platform.uname()[4] | 240 machine = platform.uname()[4] |
297 if machine in ['amd64', 'AMD64', 'x86_64', 'i86pc']: | 241 if machine in ['amd64', 'AMD64', 'x86_64', 'i86pc']: |
298 return 'amd64' | 242 return 'amd64' |
769 """ | 713 """ |
770 | 714 |
771 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0 | 715 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0 |
772 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses) | 716 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses) |
773 | 717 |
774 def _extract_VM_args(args, allowClasspath=False): | 718 def _extract_VM_args(args, allowClasspath=False, useDoubleDash=False): |
775 """ | 719 """ |
776 Partitions a command line into a leading sequence of HotSpot VM options and the rest. | 720 Partitions a command line into a leading sequence of HotSpot VM options and the rest. |
777 """ | 721 """ |
778 for i in range(0, len(args)): | 722 for i in range(0, len(args)): |
779 if not args[i].startswith('-'): | 723 if useDoubleDash: |
780 if i != 0 and (args[i - 1] == '-cp' or args[i - 1] == '-classpath'): | 724 if args[i] == '--': |
781 if not allowClasspath: | 725 vmArgs = args[:i] |
782 mx.abort('Cannot supply explicit class path option') | 726 remainder = args[i + 1:] |
783 else: | 727 return vmArgs, remainder |
784 continue | 728 else: |
785 vmArgs = args[:i] | 729 if not args[i].startswith('-'): |
786 remainder = args[i:] | 730 if i != 0 and (args[i - 1] == '-cp' or args[i - 1] == '-classpath'): |
787 return vmArgs, remainder | 731 if not allowClasspath: |
732 mx.abort('Cannot supply explicit class path option') | |
733 else: | |
734 continue | |
735 vmArgs = args[:i] | |
736 remainder = args[i:] | |
737 return vmArgs, remainder | |
738 | |
788 return args, [] | 739 return args, [] |
789 | 740 |
790 def _run_tests(args, harness, annotations, testfile): | 741 def _run_tests(args, harness, annotations, testfile): |
791 | 742 |
792 | 743 |
866 If filters are supplied, only tests whose fully qualified name | 817 If filters are supplied, only tests whose fully qualified name |
867 includes a filter as a substring are run. | 818 includes a filter as a substring are run. |
868 | 819 |
869 For example, this command line: | 820 For example, this command line: |
870 | 821 |
871 mx unittest -G:Dump= -G:MethodFilter=BC_aload.* -G:+PrintCFG BC_aload @ | 822 mx unittest -G:Dump= -G:MethodFilter=BC_aload.* -G:+PrintCFG BC_aload |
872 | 823 |
873 will run all JUnit test classes that contain 'BC_aload' in their | 824 will run all JUnit test classes that contain 'BC_aload' in their |
874 fully qualified name and will pass these options to the VM: | 825 fully qualified name and will pass these options to the VM: |
875 | 826 |
876 -G:Dump= -G:MethodFilter=BC_aload.* -G:+PrintCFG | 827 -G:Dump= -G:MethodFilter=BC_aload.* -G:+PrintCFG |
1191 for scaladacapo in scaladacapos: | 1142 for scaladacapo in scaladacapos: |
1192 if scaladacapo not in sanitycheck.dacapoScalaSanityWarmup.keys(): | 1143 if scaladacapo not in sanitycheck.dacapoScalaSanityWarmup.keys(): |
1193 mx.abort('Unknown Scala DaCapo : ' + scaladacapo) | 1144 mx.abort('Unknown Scala DaCapo : ' + scaladacapo) |
1194 iterations = sanitycheck.dacapoScalaSanityWarmup[scaladacapo][sanitycheck.SanityCheckLevel.Benchmark] | 1145 iterations = sanitycheck.dacapoScalaSanityWarmup[scaladacapo][sanitycheck.SanityCheckLevel.Benchmark] |
1195 if (iterations > 0): | 1146 if (iterations > 0): |
1196 benchmarks += [sanitycheck.getScalaDacapo(scaladacapo, iterations)] | 1147 benchmarks += [sanitycheck.getScalaDacapo(scaladacapo, ['-n', str(iterations)])] |
1197 | 1148 |
1198 #Bootstrap | 1149 #Bootstrap |
1199 if ('bootstrap' in args or 'all' in args): | 1150 if ('bootstrap' in args or 'all' in args): |
1200 benchmarks += sanitycheck.getBootstraps() | 1151 benchmarks += sanitycheck.getBootstraps() |
1201 #SPECjvm2008 | 1152 #SPECjvm2008 |
1218 benchmarks.append(sanitycheck.getCTW(vm, sanitycheck.CTWMode.NoInline)) | 1169 benchmarks.append(sanitycheck.getCTW(vm, sanitycheck.CTWMode.NoInline)) |
1219 if ('ctw-nocomplex' in args): | 1170 if ('ctw-nocomplex' in args): |
1220 benchmarks.append(sanitycheck.getCTW(vm, sanitycheck.CTWMode.NoComplex)) | 1171 benchmarks.append(sanitycheck.getCTW(vm, sanitycheck.CTWMode.NoComplex)) |
1221 | 1172 |
1222 for test in benchmarks: | 1173 for test in benchmarks: |
1223 for (groupName, res) in test.bench(vm, opts=vmArgs).items(): | 1174 for (groupName, res) in test.bench(vm, extraVmOpts=vmArgs).items(): |
1224 group = results.setdefault(groupName, {}) | 1175 group = results.setdefault(groupName, {}) |
1225 group.update(res) | 1176 group.update(res) |
1226 mx.log(json.dumps(results)) | 1177 mx.log(json.dumps(results)) |
1227 if resultFile: | 1178 if resultFile: |
1228 with open(resultFile, 'w') as f: | 1179 with open(resultFile, 'w') as f: |
1229 f.write(json.dumps(results)) | 1180 f.write(json.dumps(results)) |
1230 | 1181 |
1231 def specjvm2008(args): | 1182 def specjvm2008(args): |
1232 """run one or all SPECjvm2008 benchmarks | 1183 """run one or more SPECjvm2008 benchmarks""" |
1233 | 1184 |
1234 All options begining with - will be passed to the vm except for -ikv -ict -wt and -it. | 1185 def launcher(bm, harnessArgs, extraVmOpts): |
1235 Other options are supposed to be benchmark names and will be passed to SPECjvm2008.""" | 1186 return sanitycheck.getSPECjvm2008(harnessArgs + [bm]).bench(_get_vm(), extraVmOpts=extraVmOpts) |
1236 benchArgs = [a for a in args if a[0] != '-'] | 1187 |
1237 vmArgs = [a for a in args if a[0] == '-'] | 1188 _run_benchmark(args, sanitycheck.specjvm2008Names, launcher) |
1238 wt = None | |
1239 it = None | |
1240 skipValid = False | |
1241 skipCheck = False | |
1242 if '-v' in vmArgs: | |
1243 vmArgs.remove('-v') | |
1244 benchArgs.append('-v') | |
1245 if '-ict' in vmArgs: | |
1246 skipCheck = True | |
1247 vmArgs.remove('-ict') | |
1248 if '-ikv' in vmArgs: | |
1249 skipValid = True | |
1250 vmArgs.remove('-ikv') | |
1251 if '-wt' in vmArgs: | |
1252 wtIdx = args.index('-wt') | |
1253 try: | |
1254 wt = int(args[wtIdx+1]) | |
1255 except: | |
1256 mx.abort('-wt (Warmup time) needs a numeric value (seconds)') | |
1257 vmArgs.remove('-wt') | |
1258 benchArgs.remove(args[wtIdx+1]) | |
1259 if '-it' in vmArgs: | |
1260 itIdx = args.index('-it') | |
1261 try: | |
1262 it = int(args[itIdx+1]) | |
1263 except: | |
1264 mx.abort('-it (Iteration time) needs a numeric value (seconds)') | |
1265 vmArgs.remove('-it') | |
1266 benchArgs.remove(args[itIdx+1]) | |
1267 vm = _get_vm(); | |
1268 sanitycheck.getSPECjvm2008(benchArgs, skipCheck, skipValid, wt, it).bench(vm, opts=vmArgs) | |
1269 | 1189 |
1270 def specjbb2013(args): | 1190 def specjbb2013(args): |
1271 """runs the composite SPECjbb2013 benchmark | 1191 """runs the composite SPECjbb2013 benchmark""" |
1272 | 1192 |
1273 All options begining with - will be passed to the vm""" | 1193 def launcher(bm, harnessArgs, extraVmOpts): |
1274 benchArgs = [a for a in args if a[0] != '-'] | 1194 assert bm is None |
1275 vmArgs = [a for a in args if a[0] == '-'] | 1195 return sanitycheck.getSPECjbb2013(harnessArgs).bench(_get_vm(), extraVmOpts=extraVmOpts) |
1276 vm = _get_vm(); | 1196 |
1277 sanitycheck.getSPECjbb2013(benchArgs).bench(vm, opts=vmArgs) | 1197 _run_benchmark(args, None, launcher) |
1278 | 1198 |
1279 def specjbb2005(args): | 1199 def specjbb2005(args): |
1280 """runs the composite SPECjbb2005 benchmark | 1200 """runs the composite SPECjbb2005 benchmark""" |
1281 | 1201 |
1282 All options begining with - will be passed to the vm""" | 1202 def launcher(bm, harnessArgs, extraVmOpts): |
1283 benchArgs = [a for a in args if a[0] != '-'] | 1203 assert bm is None |
1284 vmArgs = [a for a in args if a[0] == '-'] | 1204 return sanitycheck.getSPECjbb2005(harnessArgs).bench(_get_vm(), extraVmOpts=extraVmOpts) |
1285 vm = _get_vm(); | 1205 |
1286 sanitycheck.getSPECjbb2005(benchArgs).bench(vm, opts=vmArgs) | 1206 _run_benchmark(args, None, launcher) |
1287 | 1207 |
1288 def hsdis(args, copyToDir=None): | 1208 def hsdis(args, copyToDir=None): |
1289 """download the hsdis library | 1209 """download the hsdis library |
1290 | 1210 |
1291 This is needed to support HotSpot's assembly dumping features. | 1211 This is needed to support HotSpot's assembly dumping features. |
1386 'clean': [clean, ''], | 1306 'clean': [clean, ''], |
1387 'hsdis': [hsdis, '[att]'], | 1307 'hsdis': [hsdis, '[att]'], |
1388 'hcfdis': [hcfdis, ''], | 1308 'hcfdis': [hcfdis, ''], |
1389 'igv' : [igv, ''], | 1309 'igv' : [igv, ''], |
1390 'jdkhome': [jdkhome, ''], | 1310 'jdkhome': [jdkhome, ''], |
1391 'dacapo': [dacapo, '[[n] benchmark] [VM options|@DaCapo options]'], | 1311 'dacapo': [dacapo, '[VM options] benchmarks...|"all" [DaCapo options]'], |
1392 'scaladacapo': [scaladacapo, '[[n] benchmark] [VM options|@Scala DaCapo options]'], | 1312 'scaladacapo': [scaladacapo, '[VM options] benchmarks...|"all" [Scala DaCapo options]'], |
1393 'specjvm2008': [specjvm2008, '[VM options|specjvm2008 options (-v, -ikv, -ict, -wt, -it)]'], | 1313 'specjvm2008': [specjvm2008, '[VM options] benchmarks...|"all" [SPECjvm2008 options]'], |
1394 'specjbb2013': [specjbb2013, '[VM options]'], | 1314 'specjbb2013': [specjbb2013, '[VM options] [-- [SPECjbb2013 options]]'], |
1395 'specjbb2005': [specjbb2005, '[VM options]'], | 1315 'specjbb2005': [specjbb2005, '[VM options] [-- [SPECjbb2005 options]]'], |
1396 'gate' : [gate, '[-options]'], | 1316 'gate' : [gate, '[-options]'], |
1397 'gv' : [gv, ''], | 1317 'gv' : [gv, ''], |
1398 'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'], | 1318 'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'], |
1399 'unittest' : [unittest, '[VM options] [filters...]', _unittestHelpSuffix], | 1319 'unittest' : [unittest, '[VM options] [filters...]', _unittestHelpSuffix], |
1400 'longunittest' : [longunittest, '[VM options] [filters...]', _unittestHelpSuffix], | 1320 'longunittest' : [longunittest, '[VM options] [filters...]', _unittestHelpSuffix], |