blob: 9b4f4eb9abbb9ece1c4b5c490d8cbe30b4af844f [file] [log] [blame]
mbligh548ace82006-10-19 14:36:45 +00001#!/usr/bin/python
mbligha440f4a2008-09-09 21:30:04 +00002import os, re
mbligh9f857922008-06-05 16:19:07 +00003from autotest_lib.client.bin import test, autotest_utils
4from autotest_lib.client.common_lib import utils
mbligh548ace82006-10-19 14:36:45 +00005
mbligh548ace82006-10-19 14:36:45 +00006
7class iozone(test.test):
mbligha440f4a2008-09-09 21:30:04 +00008 version = 2
mbligh548ace82006-10-19 14:36:45 +00009
mblighc5ddfd12008-08-04 17:15:00 +000010 def initialize(self):
11 self.job.require_gcc()
12
13
jadmanski0afbb632008-06-06 21:10:57 +000014 # http://www.iozone.org/src/current/iozone3_283.tar
mbligha440f4a2008-09-09 21:30:04 +000015 def setup(self, tarball='iozone3_283.tar'):
mbligh8b352852008-06-07 01:07:08 +000016 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
jadmanski0afbb632008-06-06 21:10:57 +000017 autotest_utils.extract_tarball_to_dir(tarball, self.srcdir)
18 os.chdir(os.path.join(self.srcdir, 'src/current'))
mbligh548ace82006-10-19 14:36:45 +000019
jadmanski0afbb632008-06-06 21:10:57 +000020 arch = autotest_utils.get_current_kernel_arch()
21 if (arch == 'ppc'):
22 utils.system('make linux-powerpc')
23 elif (arch == 'ppc64'):
24 utils.system('make linux-powerpc64')
25 elif (arch == 'x86_64'):
26 utils.system('make linux-AMD64')
27 else:
28 utils.system('make linux')
mbligh548ace82006-10-19 14:36:45 +000029
mbligh1f337612007-09-30 01:19:47 +000030
mbligha440f4a2008-09-09 21:30:04 +000031 def run_once(self, dir=None, args=None):
jadmanski0afbb632008-06-06 21:10:57 +000032 if not dir:
33 dir = self.tmpdir
34 os.chdir(dir)
35 if not args:
36 args = '-a'
mbligha440f4a2008-09-09 21:30:04 +000037
mbligh9b21efc2008-10-22 21:47:14 +000038 cmd = os.path.join(self.srcdir, 'src', 'current', 'iozone')
39 output = utils.system_output('%s %s' % (cmd, args))
mbligha440f4a2008-09-09 21:30:04 +000040
41 auto_mode = ("-a" in args)
42 self.__format_results(output, auto_mode)
mbligh6303ed62007-07-19 16:19:16 +000043
44
mbligha440f4a2008-09-09 21:30:04 +000045 def __get_section_name(sef, desc):
46 return desc.strip().replace(' ', '_')
47
48
49 def __format_results(self, results, auto_mode):
50 keylist = {}
51
52 if auto_mode:
53 labels = ('write', 'rewrite', 'read', 'reread', 'randread',
54 'randwrite', 'bkwdread', 'recordrewrite',
55 'strideread', 'fwrite', 'frewrite', 'fread', 'freread')
56 for line in results.splitlines():
57 fields = line.split()
58 if len(fields) != 15:
59 continue
60 try:
61 fields = tuple([int(i) for i in fields])
62 except ValueError:
63 continue
64 for l, v in zip(labels, fields[2:]):
65 key_name = "%d-%d-%s" % (fields[0], fields[1], l)
66 keylist[key_name] = v
67 else:
68 child_regexp = re.compile('Children see throughput for[\s]+'
69 '([\d]+)\s+([\w]+[\w\s]*)\=[\s]+([\d\.]*) KB/sec')
70 parent_regexp = re.compile('Parent sees throughput for[\s]+'
71 '([\d]+)\s+([\w]+[\w\s]*)\=[\s]+([\d\.]*) KB/sec')
72
73 KBsec_regexp = re.compile('\=[\s]+([\d\.]*) KB/sec')
74 KBval_regexp = re.compile('\=[\s]+([\d\.]*) KB')
75
76 section = None
77 w_count = 0
78
79 for line in results.splitlines():
80 line = line.strip()
81
82 # Check for the beginning of a new result section
83 match = child_regexp.search(line)
84 if match:
85 # Extract the section name and the worker count
86 w_count = int(match.group(1))
87 section = self.__get_section_name(match.group(2))
88
89 # Output the appropriate keyval pair
90 key_name = '%s-%d-kids' % (section, w_count)
91 keylist[key_name] = match.group(3)
92 continue
93
94 # Check for any other interesting lines
95 if '=' in line:
96 # Is it something we recognize? First check for parent.
97 match = parent_regexp.search(line)
98 if match:
99 # The section name and the worker count better match
100 p_count = int(match.group(1))
101 p_secnt = self.__get_section_name(match.group(2))
102 if p_secnt != section or p_count != w_count:
103 continue
104
105 # Set the base name for the keyval
106 basekey = 'parent'
107 else:
108 # Check for the various 'throughput' values
109 if line[3:26] == ' throughput per thread ':
110 basekey = line[0:3]
111 match_x = KBsec_regexp
112 else:
113 # The only other thing we expect is 'Min xfer'
114 if not line.startswith('Min xfer '):
115 continue
116 basekey = 'MinXfer'
117 match_x = KBval_regexp
118
119 match = match_x.search(line)
120 if match:
121 result = match.group(1)
122 key_name = "%s-%d-%s" % (section, w_count, basekey)
123 keylist[key_name] = result
124
125 self.write_perf_keyval(keylist)
126