Mercurial > hg > truffle
comparison perf/benchmarktool.py @ 3235:53502e3f3e0d
Changed benchmarktool to python script instead of shell script
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Jul 2011 14:14:53 -0700 |
parents | |
children | 344264424174 |
comparison
equal
deleted
inserted
replaced
3234:28e260179e6f | 3235:53502e3f3e0d |
---|---|
1 import subprocess | |
2 import os | |
3 import re | |
4 import sys | |
5 import argparse | |
6 | |
7 DEFAULT_DACAPO_OPTS = " -XX:MaxPermSize=512m -Xms1g -Xmx2g " | |
8 DEFAULT_SCIMARK_OPTS = " -Xms32m -Xmx100m " | |
9 | |
10 def runBash(cmd): | |
11 p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
12 return p.stdout | |
13 | |
14 def s2msString(floatString): | |
15 return str(round(float(floatString)*1000)) | |
16 | |
17 # Raw String Notation (r"") : \ instead of \\ | |
18 graalTime = re.compile(r"Total compilation time\s+:\s+([0-9]+\.[0-9]+) s") | |
19 graalSubTime = re.compile(r"([a-zA-Z0-9_ ]+)\s+:\s+([0-9]+\.[0-9]+) s \([0-9 ][0-9]\.[0-9]{2}%\)") | |
20 | |
21 def matchGraalTime(string, csvOutput, csvOutputLine, writeHeaderAt): | |
22 match1 = graalTime.search(string) | |
23 match2 = graalSubTime.search(string) | |
24 if match1: | |
25 if csvOutputLine == writeHeaderAt: | |
26 csvOutput[0].append('graal total') | |
27 print('Graal total time: '+ s2msString(match1.group(1))) | |
28 csvOutput[csvOutputLine].append(s2msString(match1.group(1))) | |
29 elif match2: | |
30 if csvOutputLine == writeHeaderAt: | |
31 csvOutput[0].append(match2.group(1).strip()) | |
32 print('Graal specific time: '+match2.group(1)+': '+s2msString(match2.group(2))) | |
33 csvOutput[csvOutputLine].append(s2msString(match2.group(2))) | |
34 else: | |
35 print('# '+string) | |
36 | |
37 def writeout(outputFile, csvOutput): | |
38 for csvLine in csvOutput : | |
39 outputFile.write(';'.join(csvLine)+';'+os.linesep) | |
40 | |
41 def main(): | |
42 # Check for environment variables | |
43 if os.getenv('JDK7') is None: | |
44 print('Environment variable JDK7 is not defined.') | |
45 return 1 | |
46 if os.getenv('DACAPO') is None: | |
47 print('Environment variable DACAPO is not defined. It must point to a directory with the DaCapo benchmark jar.') | |
48 return 1 | |
49 if os.getenv('SCIMARK') is None: | |
50 print('Environment variable SCIMARK is not defined. It must point to a directory with the SciMark benchmark jar.') | |
51 return 1 | |
52 if os.getenv('REFERENCE_JDK') is None: | |
53 print('Environment variable REFERENCE_JDK is not defined.') | |
54 return 1 | |
55 | |
56 # Option parsing | |
57 parser = argparse.ArgumentParser(description='Automated DaCapo and Scimark bechmarks') | |
58 parser.add_argument('-a', '-all', help='run all benchmarks for all compilers', action='store_true') | |
59 parser.add_argument('-c', type=str, help='compiler to use', default='graal', choices=['client', 'server', 'graal'], required=False) | |
60 parser.add_argument('-n', type=int, help='number of DaCapo benchmarks to run', default=10) | |
61 parser.add_argument('-o', type=str, help='graalVM options(quoted!)', default='') | |
62 parser.add_argument('-runonly', type=str, help='run specified benchmark only', default='all') | |
63 options = parser.parse_args() | |
64 compilerFlags = {'graal' : '-client -graal -G:+Time -XX:-GraalBailoutIsFatal -G:QuietBailout ', | |
65 'client' : '-client', | |
66 'server' : '-server'} | |
67 | |
68 if options.a: | |
69 compilers = ['graal', 'client', 'server'] | |
70 else: | |
71 compilers = [options.c] | |
72 | |
73 for compiler in compilers: | |
74 | |
75 outputFile = open(compiler+'.csv', 'w') | |
76 | |
77 # DaCapo Benchmarks | |
78 if compiler == 'graal': | |
79 vm = os.environ['JDK7'] | |
80 else : | |
81 vm = os.environ['REFERENCE_JDK'] | |
82 | |
83 cmd = '"' + vm + '/bin/java" ' + compilerFlags[compiler] + ' -d64 ' + DEFAULT_DACAPO_OPTS + options.o + ' -classpath ' + \ | |
84 os.environ['DACAPO'] + '/dacapo-9.12-bach.jar Harness -n ' + str(options.n) + ' ' | |
85 benchmarks = runBash('java -jar ' + os.environ['DACAPO'] + '/dacapo-9.12-bach.jar -l').read().decode().split(' ') | |
86 | |
87 benchmarkTime = re.compile(r"===== DaCapo 9\.12 ([a-zA-Z0-9_]+) ((PASSED)|(completed warmup [0-9]+)) in ([0-9]+) msec =====") | |
88 | |
89 csvOutput = [['benchmark', 'type', 'time']] | |
90 csvOutputLine = 0 | |
91 for benchmark in benchmarks: | |
92 if options.runonly != 'all' and benchmark != options.runonly: | |
93 continue | |
94 nRuns = 0 | |
95 dcOutput = runBash(cmd + benchmark) | |
96 while True: | |
97 line = dcOutput.readline().decode() | |
98 if not line: | |
99 break | |
100 line = line.strip() | |
101 match = benchmarkTime.search(line) | |
102 if match: | |
103 csvOutputLine = csvOutputLine + 1 | |
104 nRuns = nRuns + 1 | |
105 csvOutput.append(list()) | |
106 csvOutput[csvOutputLine].append(str(nRuns)) | |
107 print('Benchmark type: '+match.group(1)) | |
108 print('Benchmark time: '+match.group(5)) | |
109 csvOutput[csvOutputLine].append(match.group(1)) | |
110 csvOutput[csvOutputLine].append(match.group(5)) | |
111 else: | |
112 matchGraalTime(line, csvOutput, csvOutputLine, options.n) | |
113 | |
114 if nRuns < options.n: | |
115 csvOutputLine = csvOutputLine + (options.n - nRuns) | |
116 for i in range(options.n - nRuns): | |
117 csvOutput.append([str(nRuns + i), benchmark, '0']) | |
118 | |
119 writeout(outputFile, csvOutput) | |
120 | |
121 if options.runonly != 'all' and options.runonly != 'scimark': | |
122 outputFile.close() | |
123 return 0 | |
124 | |
125 # Scimark Benchmarks | |
126 writeout(outputFile, [['']]) | |
127 cmd = '"' + vm + '/bin/java" ' + compilerFlags[compiler] + ' -d64 ' + DEFAULT_SCIMARK_OPTS + options.o + \ | |
128 ' -Xbootclasspath/a:' + os.environ['SCIMARK'] + '/scimark2lib.jar jnt.scimark2.commandline' | |
129 | |
130 benchmarkScore = re.compile(r"([a-zA-Z0-9_\(\),= ]+):\s+([0-9]+\.[0-9]+)$") | |
131 | |
132 csvOutput = [['run'],[]] | |
133 scOutput = runBash(cmd) | |
134 while True: | |
135 line = scOutput.readline().decode() | |
136 if not line: | |
137 break | |
138 line = line.strip() | |
139 match = benchmarkScore.search(line) | |
140 if match: | |
141 print('Scimark '+match.group(1)+' score: '+match.group(2)) | |
142 csvOutput[0].append(match.group(1).strip()) | |
143 csvOutput[1].append(match.group(2)) | |
144 else: | |
145 matchGraalTime(line,csvOutput, 1, 1) | |
146 | |
147 writeout(outputFile, csvOutput) | |
148 outputFile.close() | |
149 | |
150 return 0 | |
151 | |
152 #This idiom means the below code only runs when executed from command line | |
153 if __name__ == '__main__': | |
154 sys.exit(main()) |