1 |
commit: ad64b45944c791e851d724a75ed4d5da87440af8 |
2 |
Author: spiros <andyspiros <AT> gmail <DOT> com> |
3 |
AuthorDate: Fri Jul 1 19:00:44 2011 +0000 |
4 |
Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com> |
5 |
CommitDate: Fri Jul 1 19:00:44 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=ad64b459 |
7 |
|
8 |
Added html report. |
9 |
|
10 |
--- |
11 |
.gitignore | 2 - |
12 |
app-benchmarks/autobench/files/python/btlbase.py | 86 ++++++++++++++++++-- |
13 |
app-benchmarks/autobench/files/python/btlutils.py | 41 --------- |
14 |
.../autobench/files/python/htmlreport.py | 57 +++++++++++++ |
15 |
4 files changed, 136 insertions(+), 50 deletions(-) |
16 |
|
17 |
diff --git a/.gitignore b/.gitignore |
18 |
deleted file mode 100644 |
19 |
index 38ab2bd..0000000 |
20 |
--- a/.gitignore |
21 |
+++ /dev/null |
22 |
@@ -1,2 +0,0 @@ |
23 |
-/.project |
24 |
-/.pydevproject |
25 |
\ No newline at end of file |
26 |
|
27 |
diff --git a/app-benchmarks/autobench/files/python/btlbase.py b/app-benchmarks/autobench/files/python/btlbase.py |
28 |
index d9a911a..d71650e 100644 |
29 |
--- a/app-benchmarks/autobench/files/python/btlbase.py |
30 |
+++ b/app-benchmarks/autobench/files/python/btlbase.py |
31 |
@@ -2,6 +2,7 @@ import sys, os, shlex |
32 |
import commands as cmd |
33 |
import subprocess as sp |
34 |
from os.path import join as pjoin |
35 |
+from htmlreport import HTMLreport |
36 |
|
37 |
try: |
38 |
import matplotlib.pyplot as plt |
39 |
@@ -12,11 +13,75 @@ except ImportError: |
40 |
'in order to generate the reports!\n') |
41 |
sys.stderr.write('Continue anyway.\n\n') |
42 |
with_images = False |
43 |
- |
44 |
-import btlutils as btl |
45 |
|
46 |
run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0] |
47 |
|
48 |
+def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other, \ |
49 |
+ logfile=None): |
50 |
+ """ |
51 |
+ Helper function that compiles a C++ source based on btl. The function |
52 |
+ sets the compiler flags that are needed by btl (include directives, link |
53 |
+ with rt,...). More options are accepted as arguments: |
54 |
+ |
55 |
+ exe: the generated executable |
56 |
+ |
57 |
+ source: the C++ source |
58 |
+ |
59 |
+ btldir: the base directory of the btl sources |
60 |
+ |
61 |
+ includes: an iterable containing the include directories (without -I) |
62 |
+ |
63 |
+ defines: an iterable of strings with define directives (without -D). In case |
64 |
+ of key-value pairs, the equal sign and the value have to be in the same |
65 |
+ string as the key: ['NDEBUG', 'FOO=BAR'] is transormed to |
66 |
+ '-DNDEBUD -DFOO=BAR' |
67 |
+ |
68 |
+ libs: the libraries to link against (without -l) |
69 |
+ |
70 |
+ libdirs: the directories where the libraries are seeked (without -L) |
71 |
+ |
72 |
+ other: an iterable with compiler flags |
73 |
+ |
74 |
+ logfile: the path of the file where the log is saved. The directory must |
75 |
+ exist. If None, no log is generated. |
76 |
+ """ |
77 |
+ |
78 |
+ incs = ( |
79 |
+ "%s/actions" % btldir, |
80 |
+ "%s/generic_bench" % btldir, |
81 |
+ "%s/generic_bench/utils" % btldir, |
82 |
+ "%s/libs/STL" % btldir |
83 |
+ ) + tuple(includes) |
84 |
+ incs = ' '.join(['-I'+i for i in incs]) |
85 |
+ |
86 |
+ defs = ' '.join(['-D'+d for d in ["NDEBUG"] + defines]) |
87 |
+ |
88 |
+ libs = ' '.join(['-l'+l for l in ["rt"] + libs]) |
89 |
+ |
90 |
+ libdirs = ' '.join(['-L'+L for L in libdirs]) |
91 |
+ |
92 |
+ cxxflags = run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip() |
93 |
+ |
94 |
+ otherflags = ' '.join(other) |
95 |
+ |
96 |
+ # TODO: use CXX instead of g++ |
97 |
+ cl = "g++ -o %s %s %s %s %s %s %s %s" \ |
98 |
+ % (exe, source, incs, defs, libs, libdirs, cxxflags, otherflags) |
99 |
+ |
100 |
+ if logfile is None: |
101 |
+ fout = sp.PIPE |
102 |
+ else: |
103 |
+ fout = file(logfile, 'w') |
104 |
+ fout.write(cl + "\n" + 80*'-' + "\n") |
105 |
+ fout.flush() |
106 |
+ cl = shlex.split(cl) |
107 |
+ cp = sp.Popen(cl, stdout=fout, stderr=sp.STDOUT) |
108 |
+ cp.communicate() |
109 |
+ if logfile is not None: |
110 |
+ fout.close() |
111 |
+ return (cp.returncode, ' '.join(cl)) |
112 |
+ |
113 |
+ |
114 |
class BTLBase: |
115 |
def __init__(self, Print, libdir, args): |
116 |
self.Print = Print |
117 |
@@ -97,7 +162,7 @@ class BTLBase: |
118 |
# TODO: use CXX instead of g++ |
119 |
btldir = 'btl/' |
120 |
logfile = os.path.join(logdir, name+"_comp.log") |
121 |
- returncode, compilecl = btl.btlcompile( |
122 |
+ returncode, compilecl = btlcompile( |
123 |
exe = testdir + "/test", |
124 |
source = btldir + self._btl_source(), |
125 |
btldir = btldir, |
126 |
@@ -163,7 +228,11 @@ class BTLBase: |
127 |
for nameimpl in results: |
128 |
nameimplstr = "%s/%s" % nameimpl |
129 |
resdat = results[nameimpl][test] |
130 |
- newresults[test][nameimplstr] = resdat |
131 |
+ newresults[test][nameimplstr] = resdat |
132 |
+ |
133 |
+ # Begin the HTML report |
134 |
+ htmlfname = pjoin(figdir, 'index.html') |
135 |
+ html = HTMLreport(htmlfname) |
136 |
|
137 |
# Generate summary - a single image with all plots |
138 |
if self.summary or self.summary_only: |
139 |
@@ -178,22 +247,25 @@ class BTLBase: |
140 |
plt.semilogx(x,y, label=impl, hold=True) |
141 |
plt.legend(loc='best') |
142 |
plt.grid(True) |
143 |
- fname = figdir+ '/summary.png' |
144 |
+ fname = pjoin(figdir, 'summary.png') |
145 |
plt.savefig(fname, format='png') |
146 |
+ html.addFig("Summary", image=os.path.basename(fname), width='95%') |
147 |
self.Print('Summary figure saved: ' + fname) |
148 |
|
149 |
# Generate plots |
150 |
if not self.summary_only: |
151 |
for test in self.tests: |
152 |
plt.figure(figsize=(12,9), dpi=300) |
153 |
- plt.title(test) |
154 |
for impl in newresults[test]: |
155 |
x,y = np.loadtxt(newresults[test][impl], unpack=True) |
156 |
plt.semilogx(x,y, label=impl, hold=True) |
157 |
plt.legend(loc='best') |
158 |
plt.grid(True) |
159 |
- fname = os.path.join(figdir, test+".png") |
160 |
+ fname = pjoin(figdir, test+".png") |
161 |
plt.savefig(fname, format='png') |
162 |
+ html.addFig(test, image=os.path.basename(fname)) |
163 |
self.Print('Figure ' + fname + ' saved') |
164 |
+ |
165 |
+ html.close() |
166 |
|
167 |
|
168 |
|
169 |
diff --git a/app-benchmarks/autobench/files/python/btlutils.py b/app-benchmarks/autobench/files/python/btlutils.py |
170 |
deleted file mode 100644 |
171 |
index d2207cd..0000000 |
172 |
--- a/app-benchmarks/autobench/files/python/btlutils.py |
173 |
+++ /dev/null |
174 |
@@ -1,41 +0,0 @@ |
175 |
-import subprocess as sp |
176 |
-import shlex |
177 |
- |
178 |
-run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0] |
179 |
- |
180 |
-def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other, \ |
181 |
- logfile=None): |
182 |
- incs = ( |
183 |
- "%s/actions" % btldir, |
184 |
- "%s/generic_bench" % btldir, |
185 |
- "%s/generic_bench/utils" % btldir, |
186 |
- "%s/libs/STL" % btldir |
187 |
- ) + tuple(includes) |
188 |
- incs = ' '.join(['-I'+i for i in incs]) |
189 |
- |
190 |
- defs = ' '.join(['-D'+d for d in ["NDEBUG"] + defines]) |
191 |
- |
192 |
- libs = ' '.join(['-l'+l for l in ["rt"] + libs]) |
193 |
- |
194 |
- libdirs = ' '.join(['-L'+L for L in libdirs]) |
195 |
- |
196 |
- cxxflags = run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip() |
197 |
- |
198 |
- otherflags = ' '.join(other) |
199 |
- |
200 |
- # TODO: use CXX instead of g++ |
201 |
- cl = "g++ -o %s %s %s %s %s %s %s %s" \ |
202 |
- % (exe, source, incs, defs, libs, libdirs, cxxflags, otherflags) |
203 |
- |
204 |
- if logfile is None: |
205 |
- fout = sp.PIPE |
206 |
- else: |
207 |
- fout = file(logfile, 'w') |
208 |
- fout.write(cl + "\n" + 80*'-' + "\n") |
209 |
- fout.flush() |
210 |
- cl = shlex.split(cl) |
211 |
- cp = sp.Popen(cl, stdout=fout, stderr=sp.STDOUT) |
212 |
- cp.communicate() |
213 |
- if logfile is not None: |
214 |
- fout.close() |
215 |
- return (cp.returncode, ' '.join(cl)) |
216 |
|
217 |
diff --git a/app-benchmarks/autobench/files/python/htmlreport.py b/app-benchmarks/autobench/files/python/htmlreport.py |
218 |
new file mode 100644 |
219 |
index 0000000..8241bdc |
220 |
--- /dev/null |
221 |
+++ b/app-benchmarks/autobench/files/python/htmlreport.py |
222 |
@@ -0,0 +1,57 @@ |
223 |
+import time |
224 |
+ |
225 |
+class HTMLreport: |
226 |
+ def __init__(self, fname, title="Benchmarks report"): |
227 |
+ self.fname = fname |
228 |
+ self.content = """ |
229 |
+<html> |
230 |
+<head> |
231 |
+<title>Benchmarks report</title> |
232 |
+<style type="text/css"> |
233 |
+body { |
234 |
+ background-color: #FFFFFF; |
235 |
+} |
236 |
+ |
237 |
+img { |
238 |
+ width:80%; |
239 |
+} |
240 |
+ |
241 |
+h1, h2, .plot, .descr, .date { |
242 |
+ text-align: center; |
243 |
+} |
244 |
+ |
245 |
+.fig { |
246 |
+ background-color: #CCCCCC; |
247 |
+ margin-bottom: 50px; |
248 |
+ padding-top: 20px; |
249 |
+ padding-bottom: 20px; |
250 |
+} |
251 |
+</style> |
252 |
+</head> |
253 |
+<body> |
254 |
+<h1> |
255 |
+""" |
256 |
+ self.content += title + "</h1>" |
257 |
+ date = time.strftime('%Y-%m-%d, %I:%M %p') |
258 |
+ self.content += '<p class="date">Generated on ' + date + '</p>' |
259 |
+ |
260 |
+ |
261 |
+ def addFig(self, title, image, descr='', alt='', width=None): |
262 |
+ self.content += '<div class="fig">' |
263 |
+ self.content += '<h2>' + title + '</h2>' |
264 |
+ if descr.strip() != '': |
265 |
+ self.content += '<p class="descr">' + descr + '</p>' |
266 |
+ self.content += '<div class="plot">' |
267 |
+ self.content += '<img src="' + image + '" alt="' + alt + '"' |
268 |
+ if width is not None: |
269 |
+ self.content += ' style="width:' + str(width) + '"' |
270 |
+ self.content += ' />' |
271 |
+ self.content += '</div>' |
272 |
+ self.content += '</div>' |
273 |
+ |
274 |
+ def close(self): |
275 |
+ self.content += "</body></html>" |
276 |
+ f = file(self.fname, 'w') |
277 |
+ f.write(self.content) |
278 |
+ f.close() |
279 |
+ self.content = '' |