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 16:06:36
Message-Id: ec1374ad483c4d7a71df5fdc4e2a983c7471bb0b.spiros@gentoo
1 commit: ec1374ad483c4d7a71df5fdc4e2a983c7471bb0b
2 Author: spiros <andyspiros <AT> gmail <DOT> com>
3 AuthorDate: Fri Jul 1 16:05:49 2011 +0000
4 Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
5 CommitDate: Fri Jul 1 16:05:49 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=ec1374ad
7
8 More logging (almost everything), bugs solved (multiple execution for
9 figures, wrong packages with no revision).
10
11 ---
12 .../autobench/files/python/PortageUtils.py | 16 +++--
13 app-benchmarks/autobench/files/python/btlbase.py | 12 ++--
14 app-benchmarks/autobench/files/python/main.py | 66 ++++++++++++-------
15 3 files changed, 59 insertions(+), 35 deletions(-)
16
17 diff --git a/app-benchmarks/autobench/files/python/PortageUtils.py b/app-benchmarks/autobench/files/python/PortageUtils.py
18 index c162e1d..66d0b80 100644
19 --- a/app-benchmarks/autobench/files/python/PortageUtils.py
20 +++ b/app-benchmarks/autobench/files/python/PortageUtils.py
21 @@ -4,8 +4,9 @@ import portage
22 import os
23
24 class InstallException(Exception):
25 - def __init__(self, command):
26 + def __init__(self, command, logfile):
27 self.command = command
28 + self.logfile = logfile
29
30 def available_packages(pattern):
31 """Returns a list of packages matching the given pattern.
32 @@ -16,6 +17,12 @@ def available_packages(pattern):
33 """
34 return [portage.catpkgsplit(l) \
35 for l in cmd.getoutput('equery -q list -po ' + pattern).split()]
36 +
37 +def normalize_cpv(cpv):
38 + if cpv[-1] != 'r0':
39 + return '%s/%s-%s-%s' % cpv
40 + else:
41 + return '%s/%s-%s' % cpv[:-1]
42
43
44 def install_package(package, env={}, root='/', pkgdir='usr/portage/packages',
45 @@ -40,10 +47,7 @@ def install_package(package, env={}, root='/', pkgdir='usr/portage/packages',
46 """
47
48 # Retrieve package string
49 - if package[-1] != 'r0':
50 - pkg = '%s/%s-%s-%s' % package
51 - else:
52 - pkg = '%s/%s-%s' % package[:-1]
53 + pkg = normalize_cpv(package)
54
55 # Setup command line
56 env['PKGDIR'] = pkgdir
57 @@ -69,7 +73,7 @@ def install_package(package, env={}, root='/', pkgdir='usr/portage/packages',
58 fout.close()
59 if p.returncode != 0:
60 # In case of error, print the whole emerge command
61 - raise InstallException(cl)
62 + raise InstallException(cl, logfile)
63
64 if __name__ == '__main__':
65 # Just a test
66
67 diff --git a/app-benchmarks/autobench/files/python/btlbase.py b/app-benchmarks/autobench/files/python/btlbase.py
68 index a8dc3f4..d9a911a 100644
69 --- a/app-benchmarks/autobench/files/python/btlbase.py
70 +++ b/app-benchmarks/autobench/files/python/btlbase.py
71 @@ -1,6 +1,7 @@
72 import sys, os, shlex
73 import commands as cmd
74 import subprocess as sp
75 +from os.path import join as pjoin
76
77 try:
78 import matplotlib.pyplot as plt
79 @@ -44,7 +45,8 @@ class BTLBase:
80 Print = self.Print
81 libdir = self.libdir
82 name = self.libname
83 - files = ['%s/bench_%s_%s.dat' %(testdir, op, name) for op in self.tests]
84 + files = [pjoin(testdir, 'bench_%s_%s.dat' % (op, name)) \
85 + for op in self.tests]
86
87 # Create dir. If all results already exist use them and do not perform
88 # the tests, otherwise remove every old results.
89 @@ -58,8 +60,8 @@ class BTLBase:
90 if not runtests:
91 Print("Not testing: results exist")
92 results = {}
93 - for i in self.tests:
94 - results[i] = '%s/bench_%s_%s.dat' %(testdir, i, name)
95 + for op in self.tests:
96 + results[op] = pjoin(testdir, 'bench_%s_%s.dat'%(op,name))
97 return results
98
99 for i in files:
100 @@ -125,7 +127,7 @@ class BTLBase:
101 break
102 resfile = errline.split()[-1]
103 testname = resfile[6:-5-len(name)]
104 - results[testname] = resfile
105 + results[testname] = pjoin(testdir, resfile)
106 Print(resfile)
107 Print.down()
108 for i in xrange(100):
109 @@ -190,7 +192,7 @@ class BTLBase:
110 plt.semilogx(x,y, label=impl, hold=True)
111 plt.legend(loc='best')
112 plt.grid(True)
113 - fname = figdir + '/' + test + '.png'
114 + fname = os.path.join(figdir, test+".png")
115 plt.savefig(fname, format='png')
116 self.Print('Figure ' + fname + ' saved')
117
118
119 diff --git a/app-benchmarks/autobench/files/python/main.py b/app-benchmarks/autobench/files/python/main.py
120 index 21e3c34..991d735 100644
121 --- a/app-benchmarks/autobench/files/python/main.py
122 +++ b/app-benchmarks/autobench/files/python/main.py
123 @@ -1,6 +1,7 @@
124 #! /usr/bin/env python2
125
126 import os, sys, shlex
127 +from os.path import join as pjoin
128 from PortageUtils import *
129 import subprocess as sp
130 import time
131 @@ -8,18 +9,34 @@ import time
132 # Retrieve relevant files/directories
133 curdir = os.path.abspath('.')
134 scriptdir = os.path.dirname(os.path.realpath(__file__))
135 +rootsdir = "/var/tmp/benchmarks/roots/"
136 +testsdir = "/var/tmp/benchmarks/tests/"
137 if os.getuid() == 0:
138 pkgsdir = "/var/cache/benchmarks/packages/"
139 - figdir = "/var/cache/benchmarks/results/"
140 + figdirb = "/var/cache/benchmarks/results/"
141 else:
142 pkgsdir = os.environ['HOME'] + "/.benchmarks/packages/"
143 - figdir = os.environ['HOME'] + "/.benchmarks/results/"
144 -figdir += time.strftime('%Y%m%d-%H%M') + '/'
145 -rootsdir = "/var/tmp/benchmarks/roots/"
146 -testsdir = "/var/tmp/benchmarks/tests/"
147 + figdirb = os.environ['HOME'] + "/.benchmarks/results/"
148 +
149 +# Library directory (lib32 vs. lib64)
150 libdir = sp.Popen \
151 ('ABI=$(portageq envvar ABI); echo /usr/`portageq envvar LIBDIR_$ABI`/', \
152 stdout=sp.PIPE, shell=True).communicate()[0].strip()
153 +
154 +# Figures directory
155 +figdir = figdirb + time.strftime('%Y-%m-%d')
156 +if os.path.exists(figdir):
157 + n = 1
158 + while True:
159 + figdir = figdirb + time.strftime('%Y-%m-%d') + "_%i"%n
160 + if not os.path.exists(figdir):
161 + os.makedirs(figdir)
162 + break
163 + n += 1
164 +else:
165 + os.makedirs(figdir)
166 +
167 +# Logs directory
168 logdir = "/var/log/benchmarks/" + time.strftime('%Y-%m-%d')
169 if os.path.exists(logdir):
170 n = 1
171 @@ -145,51 +162,54 @@ input = file(testsfname).read()
172 tests = tests_from_input(input)
173
174 # Write summary
175 -print 60*'='
176 +print 80*'='
177 print "The following tests will be run:"
178 for tname, ttest in tests.items():
179 print "Test: " + tname
180 - print " - Package: " + "%s/%s-%s-%s" % ttest['package']
181 + print " - Package: " + normalize_cpv(ttest['package'])
182 print " - Environment: " + \
183 ' '.join([n+'="'+v+'"' for n,v in ttest['env'].items()])
184 print
185 -print 60*'='
186 +print 80*'='
187 print
188
189 for tn,(name,test) in enumerate(tests.items(),1):
190 Print("BEGIN TEST %i - %s" % (tn, name))
191
192 - pkgdir = "%s/%s/" % (pkgsdir, name)
193 - root = "%s/%s/" % (rootsdir, name)
194 - tlogdir = os.path.join(logdir, name)
195 + pkgdir = pjoin(pkgsdir, name)
196 + root = pjoin(rootsdir, name)
197 + tlogdir = pjoin(logdir, name)
198 os.path.exists(tlogdir) or os.makedirs(tlogdir)
199
200 # Emerge package
201 Print.down()
202 - package = "%s/%s-%s-%s" % test['package']
203 - archive = pkgdir+package+".tbz2"
204 + package = normalize_cpv(test['package'])
205 + archive = pjoin(pkgdir, package+".tbz2")
206 Print("Emerging package %s" % package)
207 if os.path.exists(archive):
208 Print("Package already emerged - skipping")
209 else:
210 try:
211 - logfile = os.path.join(tlogdir, 'emerge.log')
212 + logfile = pjoin(tlogdir, 'emerge.log')
213 + Print("(Run 'tail -f " + logfile + " | less' on another terminal" \
214 + + " to see the progress)")
215 install_package( \
216 test['package'], env=test['env'], root=root, pkgdir=pkgdir, \
217 logfile=logfile
218 )
219 # Unpack the archive onto the given root directory
220 - archive = pkgdir + package + '.tbz2'
221 os.path.exists(root) or os.makedirs(root)
222 - tarcmd = "tar xjf " + archive + " -C " + root
223 - tarp = sp.Popen(tarcmd, stdout=sp.PIPE, stderr=sp.PIPE, shell=True)
224 - tarp.communicate()
225 + tarcmd = ['tar', 'xjf', archive, '-C', root]
226 + logfile = file(pjoin(tlogdir, 'tar.log'), 'w')
227 + tarp = sp.Popen(tarcmd, stdout=logfile, stderr=sp.STDOUT)
228 + tarp.wait()
229 + logfile.close()
230 if tarp.returncode != 0:
231 - raise InstallException(tarcmd)
232 + raise InstallException(tarcmd, logfile.name)
233
234 except InstallException as e:
235 Print("Package %s failed to emerge" % package)
236 - Print("See emerge log: " + logfile)
237 + Print("Error log: " + e.logfile)
238 Print.up()
239 print
240 continue
241 @@ -206,7 +226,7 @@ for tn,(name,test) in enumerate(tests.items(),1):
242 Print.down()
243
244 # Run the test suite
245 - testdir = "%s/%s/%s" % (testsdir, name, impl)
246 + testdir = os.path.join(testsdir, name, impl)
247 test['results'][impl] = \
248 mod.run_test(root, impl, testdir, env=test['env'], logdir=tlogdir)
249 Print.up()
250 @@ -216,9 +236,7 @@ for tn,(name,test) in enumerate(tests.items(),1):
251
252
253 # Reports will be saved in figdir
254 -if not os.path.exists(figdir):
255 - os.makedirs(figdir)
256 -
257 +os.path.exists(figdir) or os.makedirs(figdir)
258 results = {}
259 for (name,test) in tests.items():
260 if test.has_key('implementations'):