1import time, os, signal, re
2from autotest_lib.client.bin import test, utils
3
4
5class tbench(test.test):
6    version = 2
7
8    def initialize(self):
9        self.job.require_gcc()
10
11
12    # http://samba.org/ftp/tridge/dbench/dbench-3.04.tar.gz
13    def setup(self, tarball = 'dbench-3.04.tar.gz'):
14        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
15        utils.extract_tarball_to_dir(tarball, self.srcdir)
16        os.chdir(self.srcdir)
17
18        utils.configure()
19        utils.make()
20
21
22    def run_once(self, nprocs = None, args = ''):
23        # only supports combined server+client model at the moment
24        # should support separate I suppose, but nobody uses it
25        if not nprocs:
26            nprocs = self.job.cpu_count()
27        args = args + ' %s' % nprocs
28
29        pid = os.fork()
30        if pid:                         # parent
31            time.sleep(1)
32            client = self.srcdir + '/client.txt'
33            args = '-c ' + client + ' ' + '%s' % args
34            cmd = os.path.join(self.srcdir, "tbench") + " " + args
35            # Standard output is verbose and merely makes our debug logs huge
36            # so we don't retain it.  It gets parsed for the results.
37            self.results = utils.run(cmd, stderr_tee=utils.TEE_TO_LOGS).stdout
38            os.kill(pid, signal.SIGTERM)    # clean up the server
39        else:                           # child
40            server = self.srcdir + '/tbench_srv'
41            os.execlp(server, server)
42
43
44    def postprocess_iteration(self):
45        pattern = re.compile(r"Throughput (.*?) MB/sec (.*?) procs")
46        (throughput, procs) = pattern.findall(self.results)[0]
47        self.write_perf_keyval({'throughput':throughput, 'procs':procs})
48