blob: 152cbc1ca65f3e263d9b7eddd509d916821dff8e [file] [log] [blame]
mblighb8a14e32006-05-06 00:17:35 +00001import test, pickle
mblighf4c35322006-03-13 01:01:10 +00002from autotest_utils import *
mbligh0662b152007-06-20 13:03:19 +00003import re
4
5
6def to_seconds(time_string):
7 elts = time_string.split(':')
8 if len(elts) == 1:
9 return time_string
10 return str(int(elts[0]) * 3600 + float(elts[1]))
11
mblighf4c35322006-03-13 01:01:10 +000012
apw7a0d5782006-04-21 14:21:17 +000013class kernbench(test.test):
mbligh96aee2a2006-05-03 16:28:26 +000014 version = 1
15
mblighb8a14e32006-05-06 00:17:35 +000016 def setup(self):
apw7d5477a2007-03-13 16:24:12 +000017 #
18 # If we have a local copy of the 2.6.14 tarball use that
19 # else let the kernel object use the defined mirrors
20 # to obtain it.
21 #
mbligh4f6243c2006-08-29 06:15:15 +000022 # http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.tar.bz2
apw7d5477a2007-03-13 16:24:12 +000023 #
mbligh14bb0aa2007-06-04 23:19:53 +000024 # On ia64, we default to 2.6.20, as it can't compile 2.6.14.
25
26 if get_current_kernel_arch() == 'ia64':
27 default_ver = '2.6.20'
28 else:
29 default_ver = '2.6.14'
apw7d5477a2007-03-13 16:24:12 +000030 tarball = None
31 for dir in (self.bindir, '/usr/local/src'):
mbligh14bb0aa2007-06-04 23:19:53 +000032 tar = 'linux-%s.tar.bz2' % default_ver
33 path = os.path.join(dir, tar)
apw7d5477a2007-03-13 16:24:12 +000034 if os.path.exists(path):
35 tarball = path
36 break
37 if not tarball:
mbligh14bb0aa2007-06-04 23:19:53 +000038 tarball = default_ver
apw7d5477a2007-03-13 16:24:12 +000039
mbligh931ee5e2006-12-07 19:34:10 +000040 kernel = self.job.kernel(tarball, self.tmpdir, self.srcdir)
apwc30cbd32006-12-05 12:16:24 +000041 kernel.config(defconfig=True)
mblighb8a14e32006-05-06 00:17:35 +000042 # have to save this off, as we might use it in another run
43 kernel.pickle_dump(self.srcdir + '/.pickle')
mblighf4c35322006-03-13 01:01:10 +000044
45
mbligh82641862006-04-23 06:21:36 +000046 def execute(self, iterations = 1, threads = 2 * count_cpus()):
mblighb8a14e32006-05-06 00:17:35 +000047 kernel = pickle.load(open(self.srcdir + '/.pickle', 'r'))
mbligh931ee5e2006-12-07 19:34:10 +000048 kernel.job = self.job
mbligh82641862006-04-23 06:21:36 +000049 print "kernbench x %d: %d threads" % (iterations, threads)
50
mblighb8a14e32006-05-06 00:17:35 +000051 kernel.build_timed(threads) # warmup run
mblighca07e4d2006-11-26 04:31:29 +000052 for i in range(iterations):
mblighb8a14e32006-05-06 00:17:35 +000053 logfile = self.resultsdir+'/time.%d' % i
54 kernel.build_timed(threads, logfile)
mblighf4c35322006-03-13 01:01:10 +000055
mbligh72905562006-05-25 01:30:49 +000056 # Do a profiling run if necessary
57 profilers = self.job.profilers
58 if profilers.present():
59 profilers.start(self)
60 logfile = self.resultsdir+'/time.profile'
61 kernel.build_timed(threads, logfile)
62 profilers.stop(self)
63 profilers.report(self)
64
mblighb8a14e32006-05-06 00:17:35 +000065 kernel.clean() # Don't leave litter lying around
66 os.chdir(self.resultsdir)
mbligh39aa03c2006-11-25 23:11:22 +000067 system("grep -h elapsed time.* > time")
mbligh0662b152007-06-20 13:03:19 +000068
69 self.__format_results(open('time').read())
70
71
72 def __format_results(self, results):
73 out = open('keyval', 'w')
74 pattern = re.compile(r"(.*?)user (.*?)system (.*?)elapsed")
75 for result in pattern.findall(results):
76 result = tuple([to_seconds(elt) for elt in result])
77 print >> out, "user=%s\nsystem=%s\nelapsed=%s\n" % result
78 out.close()