blob: b2375ac10378addba4edcd2e36efc2100ed38664 [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)
20 utils.system('cc -lpthread hackbench.c -o hackbench')
21
22
23 def initialize(self):
24 self.job.require_gcc()
lmr65783792010-04-14 23:58:23 +000025 self.results = None
mbligh51fca2c2008-10-10 21:08:59 +000026
27
28 def run_once(self, num_groups=90):
lmr65783792010-04-14 23:58:23 +000029 """
30 Run hackbench, store the output in raw output files per iteration and
31 also in the results list attribute.
32
33 @param num_groups: Number of children processes hackbench will spawn.
34 """
mbligh51fca2c2008-10-10 21:08:59 +000035 hackbench_bin = os.path.join(self.srcdir, 'hackbench')
36 cmd = '%s %s' % (hackbench_bin, num_groups)
lmr65783792010-04-14 23:58:23 +000037 raw_output = utils.system_output(cmd, retain_output=True)
38 self.results = raw_output
39
40 path = os.path.join(self.resultsdir, 'raw_output_%s' % self.iteration)
41 raw_output_file = open(path, 'w')
42 raw_output_file.write(raw_output)
43 raw_output_file.close()
mbligh51fca2c2008-10-10 21:08:59 +000044
45
lmr65783792010-04-14 23:58:23 +000046 def postprocess_iteration(self):
47 """
48 Pick up the results attribute and write it in the performance keyval.
49 """
50 lines = self.results.split('\n')
51 for line in lines:
mbligh51fca2c2008-10-10 21:08:59 +000052 if line.startswith('Time:'):
53 time_val = line.split()[1]
54 self.write_perf_keyval({'time': time_val})