blob: 586188866eabf06d34e389c619159db37832f6a0 [file] [log] [blame]
mbligh51fca2c2008-10-10 21:08:59 +00001import os
mbligh53da18e2009-01-05 21:13:26 +00002from autotest_lib.client.bin import test, utils
mbligh51fca2c2008-10-10 21:08:59 +00003
4
5class hackbench(test.test):
lmr65783792010-04-14 23:58:23 +00006 """
7 This module will run the hackbench benchmark. Hackbench is a benchmark for
8 measuring the performance, overhead and scalability of the Linux scheduler.
9 The C program was pick from Ingo Molnar's page.
10
11 @author: Nikhil Rao (ncrao@google.com)
12 @see: http://people.redhat.com/~mingo/cfs-scheduler/tools/hackbench.c
13 """
mbligh51fca2c2008-10-10 21:08:59 +000014 version = 1
15 preserve_srcdir = True
16
17
18 def setup(self):
19 os.chdir(self.srcdir)
lmra17fae72010-06-04 18:53:16 +000020 if 'CC' in os.environ:
21 cc = '$CC'
22 else:
23 cc = 'cc'
24 utils.system('%s -lpthread hackbench.c -o hackbench' % cc)
mbligh51fca2c2008-10-10 21:08:59 +000025
26
27 def initialize(self):
28 self.job.require_gcc()
lmr65783792010-04-14 23:58:23 +000029 self.results = None
mbligh51fca2c2008-10-10 21:08:59 +000030
31
32 def run_once(self, num_groups=90):
lmr65783792010-04-14 23:58:23 +000033 """
34 Run hackbench, store the output in raw output files per iteration and
35 also in the results list attribute.
36
37 @param num_groups: Number of children processes hackbench will spawn.
38 """
mbligh51fca2c2008-10-10 21:08:59 +000039 hackbench_bin = os.path.join(self.srcdir, 'hackbench')
40 cmd = '%s %s' % (hackbench_bin, num_groups)
lmr65783792010-04-14 23:58:23 +000041 raw_output = utils.system_output(cmd, retain_output=True)
42 self.results = raw_output
43
44 path = os.path.join(self.resultsdir, 'raw_output_%s' % self.iteration)
lmra17fae72010-06-04 18:53:16 +000045 utils.open_write_close(path, raw_output)
mbligh51fca2c2008-10-10 21:08:59 +000046
47
lmr65783792010-04-14 23:58:23 +000048 def postprocess_iteration(self):
49 """
50 Pick up the results attribute and write it in the performance keyval.
51 """
52 lines = self.results.split('\n')
53 for line in lines:
mbligh51fca2c2008-10-10 21:08:59 +000054 if line.startswith('Time:'):
55 time_val = line.split()[1]
56 self.write_perf_keyval({'time': time_val})