• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os, re
2from autotest_lib.client.bin import test, os_dep, utils
3
4
5def convert_size(values):
6    values = values.split(':')
7    size = values[0]
8    if len(values) > 1:
9        chunk = values[1]
10    else:
11        chunk = 0
12    if size.endswith('G') or size.endswith('g'):
13        size = int(size[:-1]) * 2**30
14    else:
15        if size.endswith('M') or size.endswith('m'):
16            size = int(size[:-1])
17        size = int(size) * 2**20
18    if chunk:
19        if chunk.endswith('K') or chunk.endswith('k'):
20            chunk = int(chunk[:-1]) * 2**10
21        else:
22            chunk = int(chunk)
23    return [size, chunk]
24
25
26class bonnie(test.test):
27    version = 1
28
29    def initialize(self):
30        self.job.require_gcc()
31        self.results = []
32
33    # http://www.coker.com.au/bonnie++/bonnie++-1.03a.tgz
34    def setup(self, tarball = 'bonnie++-1.03a.tgz'):
35        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
36        utils.extract_tarball_to_dir(tarball, self.srcdir)
37        os.chdir(self.srcdir)
38
39        os_dep.command('g++')
40        utils.system('patch -p1 < ../bonnie++-1.03a-gcc43.patch')
41        utils.configure()
42        utils.make()
43
44
45    def run_once(self, dir=None, extra_args='', user='root'):
46        if not dir:
47            dir = self.tmpdir
48
49        # if the user specified a -n we will use that
50        if '-n' not in extra_args:
51            extra_args += ' -n 2048'
52        args = '-d ' + dir + ' -u ' + user + ' ' + extra_args
53        cmd = self.srcdir + '/bonnie++ ' + args
54
55        self.results.append(utils.system_output(cmd, retain_output=True))
56
57
58    def postprocess(self):
59        strip_plus = lambda s: re.sub(r"^\++$", "0", s)
60
61        keys = ('size', 'chnk', 'seqout_perchr_ksec',
62                'seqout_perchr_pctcp', 'seqout_perblk_ksec',
63                'seqout_perblk_pctcp', 'seqout_rewrite_ksec',
64                'seqout_rewrite_pctcp', 'seqin_perchr_ksec',
65                'seqin_perchr_pctcp', 'seqin_perblk_ksec',
66                'seqin_perblk_pctcp', 'rand_ksec', 'rand_pctcp', 'files',
67                'seqcreate_create_ksec', 'seqcreate_create_pctcp',
68                'seqcreate_read_ksec', 'seqcreate_read_pctcp',
69                'seqcreate_delete_ksec', 'seqcreate_delete_pctcp',
70                'randreate_create_ksec', 'randcreate_create_pctcp',
71                'randcreate_read_ksec', 'randcreate_read_pctcp',
72                'randcreate_delete_ksec', 'randcreate_delete_pctcp')
73
74        for line in self.results:
75            if line.count(',') != 26:
76                continue
77            fields = line.split(',')
78            fields = [strip_plus(f) for f in fields]
79            fields = convert_size(fields[1]) + fields[2:]
80
81            self.write_perf_keyval(dict(zip(keys,fields)))
82