Gentoo Archives: gentoo-commits

From: Andrea Arteaga <andyspiros@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/auto-numerical-bench:master commit in: app-benchmarks/autobench/files/python/
Date: Fri, 01 Jul 2011 12:28:44
Message-Id: 1599222a06e321570be756d36e03132bd8359d3b.spiros@gentoo
1 commit: 1599222a06e321570be756d36e03132bd8359d3b
2 Author: spiros <andyspiros <AT> gmail <DOT> com>
3 AuthorDate: Fri Jul 1 12:27:51 2011 +0000
4 Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
5 CommitDate: Fri Jul 1 12:27:51 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=1599222a
7
8 Emerge, compilation and run are logged. More readable output.
9
10 ---
11 .../autobench/files/python/PortageUtils.py | 23 +++++++++++++++---
12 app-benchmarks/autobench/files/python/btlbase.py | 22 ++++++++++++-----
13 app-benchmarks/autobench/files/python/btlutils.py | 14 +++++++++-
14 app-benchmarks/autobench/files/python/main.py | 25 ++++++++++++++++---
15 4 files changed, 67 insertions(+), 17 deletions(-)
16
17 diff --git a/app-benchmarks/autobench/files/python/PortageUtils.py b/app-benchmarks/autobench/files/python/PortageUtils.py
18 index 4877cbd..c162e1d 100644
19 --- a/app-benchmarks/autobench/files/python/PortageUtils.py
20 +++ b/app-benchmarks/autobench/files/python/PortageUtils.py
21 @@ -1,4 +1,5 @@
22 import commands as cmd
23 +import subprocess as sp
24 import portage
25 import os
26
27 @@ -17,7 +18,8 @@ def available_packages(pattern):
28 for l in cmd.getoutput('equery -q list -po ' + pattern).split()]
29
30
31 -def install_package(package, env={}, root='/', pkgdir='usr/portage/packages'):
32 +def install_package(package, env={}, root='/', pkgdir='usr/portage/packages',
33 + logfile=None):
34 """Emerge a package in the given root.
35
36 package is the package to be emerged. It has to be a tuple
37 @@ -50,9 +52,22 @@ def install_package(package, env={}, root='/', pkgdir='usr/portage/packages'):
38 envl += i + '="' + env[i] + '" '
39 cl = envl + 'emerge --ignore-default-opts -OB "=' + pkg + '"'
40
41 - # Execute emerge command
42 - so = cmd.getstatusoutput(cl)
43 - if so[0] != 0:
44 + # Execute emerge command and log the results
45 + if logfile is not None:
46 + fout = file(logfile, 'w')
47 + fout.write(cl+'\n'+80*'-'+'\n')
48 + fout.flush()
49 + else:
50 + fout = sp.PIPE
51 + p = sp.Popen( \
52 + ['emerge', '--ignore-default-opts', '-OB', '=' + pkg], \
53 + env = env, \
54 + stdout = fout, stderr = fout \
55 + )
56 + p.wait()
57 + if logfile is not None:
58 + fout.close()
59 + if p.returncode != 0:
60 # In case of error, print the whole emerge command
61 raise InstallException(cl)
62
63
64 diff --git a/app-benchmarks/autobench/files/python/btlbase.py b/app-benchmarks/autobench/files/python/btlbase.py
65 index a8d8c1e..a8dc3f4 100644
66 --- a/app-benchmarks/autobench/files/python/btlbase.py
67 +++ b/app-benchmarks/autobench/files/python/btlbase.py
68 @@ -39,7 +39,7 @@ class BTLBase:
69 self._parse_args(passargs)
70
71
72 - def run_test(self, root, impl, testdir, env):
73 + def run_test(self, root, impl, testdir, env, logdir):
74 # Convenient renames and definition of report files
75 Print = self.Print
76 libdir = self.libdir
77 @@ -94,6 +94,7 @@ class BTLBase:
78 # Compile
79 # TODO: use CXX instead of g++
80 btldir = 'btl/'
81 + logfile = os.path.join(logdir, name+"_comp.log")
82 returncode, compilecl = btl.btlcompile(
83 exe = testdir + "/test",
84 source = btldir + self._btl_source(),
85 @@ -102,19 +103,24 @@ class BTLBase:
86 defines = self._btl_defines(),
87 libs = [],
88 libdirs = [root+libdir],
89 - other = self._get_flags(root, impl, libdir)
90 + other = self._get_flags(root, impl, libdir),
91 + logfile = logfile
92 )
93 if returncode != 0:
94 - raise Exception("Compilation failed: " + compilecl)
95 - Print("Compilation successful: " + compilecl)
96 + Print("Compilation failed")
97 + Print("See log: " + logfile)
98 + return
99 + Print("Compilation successful")
100
101 # Run test
102 - args = [testdir + "/test"] + self.tests
103 + logfile = file(os.path.join(logdir, name+"_run.log"), 'w')
104 + args = [os.path.join(testdir,"test")] + self.tests
105 proc = sp.Popen(args, bufsize=1, stdout=sp.PIPE, stderr=sp.PIPE,
106 cwd = testdir)
107 results = {}
108 while True:
109 errline = proc.stderr.readline()
110 + logfile.write(errline)
111 if not errline:
112 break
113 resfile = errline.split()[-1]
114 @@ -123,11 +129,13 @@ class BTLBase:
115 Print(resfile)
116 Print.down()
117 for i in xrange(100):
118 - outline = proc.stdout.readline().rstrip()
119 - Print(outline)
120 + outline = proc.stdout.readline()
121 + logfile.write(outline)
122 + Print(outline.rstrip())
123 Print.up()
124 Print.up()
125 proc.wait()
126 + logfile.close()
127 if proc.returncode != 0:
128 Print('Test failed')
129 else:
130
131 diff --git a/app-benchmarks/autobench/files/python/btlutils.py b/app-benchmarks/autobench/files/python/btlutils.py
132 index 752096e..d2207cd 100644
133 --- a/app-benchmarks/autobench/files/python/btlutils.py
134 +++ b/app-benchmarks/autobench/files/python/btlutils.py
135 @@ -3,7 +3,8 @@ import shlex
136
137 run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0]
138
139 -def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other):
140 +def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other, \
141 + logfile=None):
142 incs = (
143 "%s/actions" % btldir,
144 "%s/generic_bench" % btldir,
145 @@ -25,7 +26,16 @@ def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other):
146 # TODO: use CXX instead of g++
147 cl = "g++ -o %s %s %s %s %s %s %s %s" \
148 % (exe, source, incs, defs, libs, libdirs, cxxflags, otherflags)
149 +
150 + if logfile is None:
151 + fout = sp.PIPE
152 + else:
153 + fout = file(logfile, 'w')
154 + fout.write(cl + "\n" + 80*'-' + "\n")
155 + fout.flush()
156 cl = shlex.split(cl)
157 - cp = sp.Popen(cl, stdout=sp.PIPE, stderr=sp.PIPE)
158 + cp = sp.Popen(cl, stdout=fout, stderr=sp.STDOUT)
159 cp.communicate()
160 + if logfile is not None:
161 + fout.close()
162 return (cp.returncode, ' '.join(cl))
163
164 diff --git a/app-benchmarks/autobench/files/python/main.py b/app-benchmarks/autobench/files/python/main.py
165 index 474f9bd..21e3c34 100644
166 --- a/app-benchmarks/autobench/files/python/main.py
167 +++ b/app-benchmarks/autobench/files/python/main.py
168 @@ -20,6 +20,17 @@ testsdir = "/var/tmp/benchmarks/tests/"
169 libdir = sp.Popen \
170 ('ABI=$(portageq envvar ABI); echo /usr/`portageq envvar LIBDIR_$ABI`/', \
171 stdout=sp.PIPE, shell=True).communicate()[0].strip()
172 +logdir = "/var/log/benchmarks/" + time.strftime('%Y-%m-%d')
173 +if os.path.exists(logdir):
174 + n = 1
175 + while True:
176 + logdir = "/var/log/benchmarks/" + time.strftime('%Y-%m-%d') + "_%i"%n
177 + if not os.path.exists(logdir):
178 + os.makedirs(logdir)
179 + break
180 + n += 1
181 +else:
182 + os.makedirs(logdir)
183
184 def print_usage():
185 print "Usage: benchmarks [blas|cblas|lapack] file args"
186 @@ -150,6 +161,8 @@ for tn,(name,test) in enumerate(tests.items(),1):
187
188 pkgdir = "%s/%s/" % (pkgsdir, name)
189 root = "%s/%s/" % (rootsdir, name)
190 + tlogdir = os.path.join(logdir, name)
191 + os.path.exists(tlogdir) or os.makedirs(tlogdir)
192
193 # Emerge package
194 Print.down()
195 @@ -160,8 +173,11 @@ for tn,(name,test) in enumerate(tests.items(),1):
196 Print("Package already emerged - skipping")
197 else:
198 try:
199 + logfile = os.path.join(tlogdir, 'emerge.log')
200 install_package( \
201 - test['package'], env=test['env'], root=root, pkgdir=pkgdir)
202 + test['package'], env=test['env'], root=root, pkgdir=pkgdir, \
203 + logfile=logfile
204 + )
205 # Unpack the archive onto the given root directory
206 archive = pkgdir + package + '.tbz2'
207 os.path.exists(root) or os.makedirs(root)
208 @@ -172,7 +188,8 @@ for tn,(name,test) in enumerate(tests.items(),1):
209 raise InstallException(tarcmd)
210
211 except InstallException as e:
212 - Print("Package %s failed to emerge: %s" % (package, e.command))
213 + Print("Package %s failed to emerge" % package)
214 + Print("See emerge log: " + logfile)
215 Print.up()
216 print
217 continue
218 @@ -181,7 +198,7 @@ for tn,(name,test) in enumerate(tests.items(),1):
219 # Find implementations
220 impls = mod.get_impls(root)
221 test['implementations'] = impls
222 -
223 +
224 # Test every implementation
225 test['results'] = {}
226 for impl in impls:
227 @@ -191,7 +208,7 @@ for tn,(name,test) in enumerate(tests.items(),1):
228 # Run the test suite
229 testdir = "%s/%s/%s" % (testsdir, name, impl)
230 test['results'][impl] = \
231 - mod.run_test(root=root, impl=impl, testdir=testdir, env=test['env'])
232 + mod.run_test(root, impl, testdir, env=test['env'], logdir=tlogdir)
233 Print.up()
234
235 Print.up()