1import os 2from autotest_lib.client.bin import test, utils 3 4 5class hackbench(test.test): 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 """ 14 version = 1 15 preserve_srcdir = True 16 17 18 def setup(self): 19 os.chdir(self.srcdir) 20 if 'CC' in os.environ: 21 cc = '$CC' 22 else: 23 cc = 'cc' 24 utils.system('%s -lpthread hackbench.c -o hackbench' % cc) 25 26 27 def initialize(self): 28 self.job.require_gcc() 29 self.results = None 30 31 32 def run_once(self, num_groups=90): 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 """ 39 hackbench_bin = os.path.join(self.srcdir, 'hackbench') 40 cmd = '%s %s' % (hackbench_bin, num_groups) 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) 45 utils.open_write_close(path, raw_output) 46 47 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: 54 if line.startswith('Time:'): 55 time_val = line.split()[1] 56 self.write_perf_keyval({'time': time_val}) 57