1import os, re
2
3from autotest_lib.client.bin import utils, test
4
5class dbench(test.test):
6    version = 3
7
8    # http://samba.org/ftp/tridge/dbench/dbench-3.04.tar.gz
9    def setup(self, tarball='dbench-3.04.tar.gz'):
10        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
11        utils.extract_tarball_to_dir(tarball, self.srcdir)
12        os.chdir(self.srcdir)
13
14        utils.system('patch -p1 < ../dbench_startup.patch')
15        utils.configure()
16        utils.make()
17
18
19    def initialize(self):
20        self.job.require_gcc()
21        self.results = []
22        self.dbench = os.path.join(self.srcdir, 'dbench')
23
24
25    def run_once(self, dir='.', nprocs=None, seconds=600, args=''):
26        if not nprocs:
27            nprocs = self.job.cpu_count()
28        loadfile = os.path.join(self.srcdir, 'client.txt')
29        cmd = '%s %s %s -D %s -c %s -t %d' % (self.dbench, nprocs, args,
30                                              dir, loadfile, seconds)
31        self.results = utils.system_output(cmd, retain_output=True)
32
33
34    def postprocess_iteration(self):
35        pattern = re.compile(r"Throughput (.*?) MB/sec (.*?) procs")
36        (throughput, procs) = pattern.findall(self.results)[0]
37        self.write_perf_keyval({'throughput':throughput, 'procs':procs})
38