mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 1 | import os |
mbligh | 53da18e | 2009-01-05 21:13:26 +0000 | [diff] [blame] | 2 | from autotest_lib.client.bin import test, utils |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 3 | |
| 4 | |
| 5 | class hackbench(test.test): |
lmr | 6578379 | 2010-04-14 23:58:23 +0000 | [diff] [blame] | 6 | """ |
| 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 | """ |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 14 | version = 1 |
| 15 | preserve_srcdir = True |
| 16 | |
| 17 | |
| 18 | def setup(self): |
| 19 | os.chdir(self.srcdir) |
lmr | a17fae7 | 2010-06-04 18:53:16 +0000 | [diff] [blame] | 20 | if 'CC' in os.environ: |
Eric Li | 7edb304 | 2011-01-06 17:57:17 -0800 | [diff] [blame^] | 21 | cc = '$CC' |
lmr | a17fae7 | 2010-06-04 18:53:16 +0000 | [diff] [blame] | 22 | else: |
Eric Li | 7edb304 | 2011-01-06 17:57:17 -0800 | [diff] [blame^] | 23 | cc = 'cc' |
lmr | a17fae7 | 2010-06-04 18:53:16 +0000 | [diff] [blame] | 24 | utils.system('%s -lpthread hackbench.c -o hackbench' % cc) |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def initialize(self): |
| 28 | self.job.require_gcc() |
lmr | 6578379 | 2010-04-14 23:58:23 +0000 | [diff] [blame] | 29 | self.results = None |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def run_once(self, num_groups=90): |
lmr | 6578379 | 2010-04-14 23:58:23 +0000 | [diff] [blame] | 33 | """ |
| 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 | """ |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 39 | hackbench_bin = os.path.join(self.srcdir, 'hackbench') |
| 40 | cmd = '%s %s' % (hackbench_bin, num_groups) |
lmr | 6578379 | 2010-04-14 23:58:23 +0000 | [diff] [blame] | 41 | 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) |
lmr | a17fae7 | 2010-06-04 18:53:16 +0000 | [diff] [blame] | 45 | utils.open_write_close(path, raw_output) |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 46 | |
| 47 | |
lmr | 6578379 | 2010-04-14 23:58:23 +0000 | [diff] [blame] | 48 | 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: |
mbligh | 51fca2c | 2008-10-10 21:08:59 +0000 | [diff] [blame] | 54 | if line.startswith('Time:'): |
| 55 | time_val = line.split()[1] |
| 56 | self.write_perf_keyval({'time': time_val}) |