blob: 543d6c67369c8d8ddaca18acdf2c566a03fb4f5b [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
mblighf11dc932007-06-28 22:36:22 +000010 return str(int(elts[0]) * 60 + float(elts[1]))
mbligh0662b152007-06-20 13:03:19 +000011
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
mbligh9f5113d2007-06-25 23:41:10 +000052 profilers = self.job.profilers
53 if not profilers.only():
54 for i in range(iterations):
55 logfile = self.resultsdir+'/time.%d' % i
56 kernel.build_timed(threads, logfile)
mblighf4c35322006-03-13 01:01:10 +000057
mbligh72905562006-05-25 01:30:49 +000058 # Do a profiling run if necessary
mbligh72905562006-05-25 01:30:49 +000059 if profilers.present():
60 profilers.start(self)
61 logfile = self.resultsdir+'/time.profile'
62 kernel.build_timed(threads, logfile)
63 profilers.stop(self)
64 profilers.report(self)
65
mblighb8a14e32006-05-06 00:17:35 +000066 kernel.clean() # Don't leave litter lying around
67 os.chdir(self.resultsdir)
mbligh39aa03c2006-11-25 23:11:22 +000068 system("grep -h elapsed time.* > time")
mbligh0662b152007-06-20 13:03:19 +000069
70 self.__format_results(open('time').read())
71
72
73 def __format_results(self, results):
74 out = open('keyval', 'w')
75 pattern = re.compile(r"(.*?)user (.*?)system (.*?)elapsed")
76 for result in pattern.findall(results):
77 result = tuple([to_seconds(elt) for elt in result])
78 print >> out, "user=%s\nsystem=%s\nelapsed=%s\n" % result
79 out.close()