comparison perf/benchmarktool.sh @ 3185:4ccb3d5e4da1

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