Mercurial > hg > graal-compiler
comparison mx/mx_graal.py @ 15178:0c53453c4d5e
mx: improved jmh command to (a) look for JMH benchmarks in ../java-benchmarks, (b) omit building benchmarks if they are up to date and (c) offer better message with 'mx help jmh'
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 17 Apr 2014 01:36:49 +0200 |
parents | 2082889fc8f6 |
children | 06bfcf5f941d |
comparison
equal
deleted
inserted
replaced
15177:66e3af78ea96 | 15178:0c53453c4d5e |
---|---|
1402 if resultFile: | 1402 if resultFile: |
1403 with open(resultFile, 'w') as f: | 1403 with open(resultFile, 'w') as f: |
1404 f.write(json.dumps(results)) | 1404 f.write(json.dumps(results)) |
1405 | 1405 |
1406 def jmh(args): | 1406 def jmh(args): |
1407 """run the JMH_BENCHMARKS""" | 1407 """run the JMH_BENCHMARKS |
1408 | |
1409 The benchmarks are running with the default VM. | |
1410 You can override this with an explicit option. | |
1411 For example: | |
1412 | |
1413 mx jmh -server ... | |
1414 | |
1415 Will force the benchmarks to be run with the server VM. | |
1416 """ | |
1408 | 1417 |
1409 # TODO: add option for `mvn clean package' | 1418 # TODO: add option for `mvn clean package' |
1410 | 1419 |
1411 vmArgs, benchmarksAndJsons = _extract_VM_args(args) | 1420 vmArgs, benchmarksAndJsons = _extract_VM_args(args) |
1412 | 1421 |
1413 benchmarks = [b for b in benchmarksAndJsons if not b.startswith('{')] | 1422 benchmarks = [b for b in benchmarksAndJsons if not b.startswith('{')] |
1414 jmhArgJsons = [b for b in benchmarksAndJsons if b.startswith('{')] | 1423 jmhArgJsons = [b for b in benchmarksAndJsons if b.startswith('{')] |
1415 | 1424 |
1416 jmhArgs = {'-v' : 'EXTRA' if mx._opts.verbose else 'NORMAL'} | 1425 jmhArgs = {'-rff' : join(_graal_home, 'mx', 'jmh', 'jmh.out'), '-v' : 'EXTRA' if mx._opts.verbose else 'NORMAL'} |
1417 | 1426 |
1418 # e.g. '{"-wi" : 20}' | 1427 # e.g. '{"-wi" : 20}' |
1419 for j in jmhArgJsons: | 1428 for j in jmhArgJsons: |
1420 try: | 1429 try: |
1421 for n, v in json.loads(j).iteritems(): | 1430 for n, v in json.loads(j).iteritems(): |
1425 jmhArgs[n] = v | 1434 jmhArgs[n] = v |
1426 except ValueError as e: | 1435 except ValueError as e: |
1427 mx.abort('error parsing JSON input: {}"\n{}'.format(j, e)) | 1436 mx.abort('error parsing JSON input: {}"\n{}'.format(j, e)) |
1428 | 1437 |
1429 jmhPath = mx.get_env('JMH_BENCHMARKS', None) | 1438 jmhPath = mx.get_env('JMH_BENCHMARKS', None) |
1430 if not jmhPath or not exists(jmhPath): | 1439 if not jmhPath: |
1431 mx.abort("$JMH_BENCHMARKS not properly defined: " + str(jmhPath)) | 1440 probe = join(dirname(_graal_home), 'java-benchmarks') |
1432 | 1441 if exists(probe): |
1433 def _blackhole(x): | 1442 jmhPath = probe |
1434 mx.logv(x[:-1]) | 1443 |
1435 | 1444 if not jmhPath: |
1436 | 1445 mx.abort("Please set the JMH_BENCHMARKS environment variable to point to the java-benchmarks workspace") |
1437 env = os.environ.copy() | 1446 if not exists(jmhPath): |
1438 env['JAVA_HOME'] = _jdk(vmToCheck='graal') | 1447 mx.abort("The directory denoted by the JMH_BENCHMARKS environment variable does not exist: " + jmhPath) |
1439 env['MAVEN_OPTS'] = '-graal' | 1448 mx.log('Using benchmarks in ' + jmhPath) |
1440 mx.log("Building benchmarks...") | 1449 |
1441 mx.run(['mvn', 'package'], cwd=jmhPath, out=_blackhole, env=env) | 1450 timestamp = mx.TimeStampFile(join(_graal_home, 'mx', 'jmh', jmhPath.replace(os.sep, '_') + '.timestamp')) |
1451 buildJmh = False | |
1452 jmhTree = [] | |
1453 for root, dirnames, filenames in os.walk(jmhPath): | |
1454 if root == jmhPath: | |
1455 for n in ['.hg', '.metadata']: | |
1456 if n in dirnames: | |
1457 dirnames.remove(n) | |
1458 jmhTree.append(os.path.relpath(root, jmhPath) + ':') | |
1459 jmhTree = jmhTree + filenames | |
1460 jmhTree.append('') | |
1461 | |
1462 files = [join(root, f) for f in filenames] | |
1463 if timestamp.isOlderThan(files): | |
1464 buildJmh = True | |
1465 | |
1466 if not buildJmh: | |
1467 with open(timestamp.path) as fp: | |
1468 oldJmhTree = fp.read().split('\n') | |
1469 if oldJmhTree != jmhTree: | |
1470 import difflib | |
1471 diff = difflib.unified_diff(oldJmhTree, jmhTree) | |
1472 mx.log("Need to rebuild JMH due to change in JMH directory tree indicated by this diff:") | |
1473 mx.log('\n'.join(diff)) | |
1474 buildJmh = True | |
1475 | |
1476 if buildJmh: | |
1477 def _blackhole(x): | |
1478 mx.logv(x[:-1]) | |
1479 env = os.environ.copy() | |
1480 env['JAVA_HOME'] = _jdk(vmToCheck='graal') | |
1481 env['MAVEN_OPTS'] = '-graal' | |
1482 mx.log("Building benchmarks...") | |
1483 mx.run(['mvn', 'package'], cwd=jmhPath, out=_blackhole, env=env) | |
1484 timestamp.touch() | |
1485 with open(timestamp.path, 'w') as fp: | |
1486 fp.write('\n'.join(jmhTree)) | |
1442 | 1487 |
1443 matchedSuites = set() | 1488 matchedSuites = set() |
1444 numBench = [0] | 1489 numBench = [0] |
1445 for micros in os.listdir(jmhPath): | 1490 for micros in os.listdir(jmhPath): |
1446 absoluteMicro = os.path.join(jmhPath, micros) | 1491 absoluteMicro = os.path.join(jmhPath, micros) |