2015-08-10 13:13:17 -07:00
|
|
|
# Copyright 2012-2015 ARM Limited
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2015-10-08 09:10:08 +01:00
|
|
|
# pylint: disable=attribute-defined-outside-init
|
2015-10-01 11:52:51 -07:00
|
|
|
from collections import OrderedDict
|
|
|
|
from itertools import izip_longest
|
2015-08-10 13:13:17 -07:00
|
|
|
import os
|
|
|
|
import re
|
2015-09-13 20:50:17 -07:00
|
|
|
import csv
|
2015-08-10 13:13:17 -07:00
|
|
|
|
2015-12-09 15:43:35 +00:00
|
|
|
|
|
|
|
from wlauto import Workload, Parameter, Executable
|
|
|
|
from wlauto.exceptions import ConfigError
|
|
|
|
from wlauto.utils.types import list_of_ints
|
|
|
|
|
|
|
|
|
2015-08-10 13:13:17 -07:00
|
|
|
iozone_results_txt = 'iozone_results.txt'
|
|
|
|
|
|
|
|
|
|
|
|
class Iozone(Workload):
|
|
|
|
name = 'iozone'
|
|
|
|
description = """
|
2015-09-13 20:50:17 -07:00
|
|
|
Iozone is a filesystem benchmark that runs a series of disk
|
|
|
|
I/O performance tests.
|
2015-08-10 13:13:17 -07:00
|
|
|
|
2015-10-08 09:10:08 +01:00
|
|
|
Here is a list of tests that you can run in the iozone
|
|
|
|
workload. The descriptions are from the official iozone
|
2015-10-01 11:37:05 -07:00
|
|
|
document.
|
|
|
|
|
|
|
|
0 - Write Test
|
2015-10-08 09:16:32 +01:00
|
|
|
Measure performance of writing a new file. Other
|
|
|
|
tests rely on the file written by this, so it must
|
|
|
|
always be enabled (WA will automatically neable this
|
|
|
|
if not specified).
|
2015-10-01 11:37:05 -07:00
|
|
|
|
|
|
|
1 - Rewrite Test
|
|
|
|
Measure performance of writing an existing file.
|
|
|
|
|
|
|
|
2 - Read Test
|
|
|
|
Measure performance of reading an existing file.
|
|
|
|
|
|
|
|
3 - Reread Test
|
|
|
|
Measure performance of rereading an existing file.
|
|
|
|
|
|
|
|
4 - Random Read Test
|
|
|
|
Measure performance of reading a file by accessing
|
|
|
|
random locations within the file.
|
2015-10-01 11:52:51 -07:00
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
5 - Random Write Test
|
|
|
|
Measure performance of writing a file by accessing
|
|
|
|
random locations within the file.
|
|
|
|
|
|
|
|
6 - Backwards Read Test
|
|
|
|
Measure performance of reading a file backwards.
|
|
|
|
|
|
|
|
7 - Record Rewrite Test
|
|
|
|
Measure performance of writing and rewriting a
|
2015-10-08 09:10:08 +01:00
|
|
|
particular spot within the file.
|
2015-10-01 11:52:51 -07:00
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
8 - Strided Read Test
|
|
|
|
Measure performance of reading a file with strided
|
|
|
|
access behavior.
|
|
|
|
|
|
|
|
9 - Fwrite Test
|
2015-10-01 11:52:51 -07:00
|
|
|
Measure performance of writing a file using the
|
2015-10-01 11:37:05 -07:00
|
|
|
library function fwrite() that performances
|
|
|
|
buffered write operations.
|
|
|
|
|
|
|
|
10 - Frewrite Test
|
2015-10-01 11:52:51 -07:00
|
|
|
Measure performance of writing a file using the
|
|
|
|
the library function fwrite() that performs
|
2015-10-01 11:37:05 -07:00
|
|
|
buffered and blocked write operations.
|
2015-10-01 11:52:51 -07:00
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
11 - Fread Test
|
|
|
|
Measure performance of reading a file using the
|
2015-10-01 11:52:51 -07:00
|
|
|
library function fread() that performs buffered
|
2015-10-01 11:37:05 -07:00
|
|
|
and blocked read operations.
|
2015-10-01 11:52:51 -07:00
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
12 - Freread Test
|
2015-10-01 11:52:51 -07:00
|
|
|
Same as the Fread Test except the current file
|
2015-10-01 11:37:05 -07:00
|
|
|
being read was read previously sometime in the
|
2015-10-01 11:52:51 -07:00
|
|
|
past.
|
2015-10-01 11:37:05 -07:00
|
|
|
|
2015-09-13 20:50:17 -07:00
|
|
|
By default, iozone will run all tests in auto mode. To run
|
|
|
|
specific tests, they must be written in the form of:
|
2015-08-10 13:13:17 -07:00
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
[0,1,4,5]
|
2015-08-10 13:13:17 -07:00
|
|
|
|
2015-10-08 09:10:08 +01:00
|
|
|
Please enable classifiers in your agenda or config file
|
2015-10-01 14:47:45 -07:00
|
|
|
in order to display the results properly in the results.csv
|
|
|
|
file.
|
|
|
|
|
2015-08-10 13:13:17 -07:00
|
|
|
The official website for iozone is at www.iozone.org.
|
|
|
|
"""
|
|
|
|
|
|
|
|
parameters = [
|
2015-10-01 11:37:05 -07:00
|
|
|
Parameter('tests', kind=list_of_ints, allowed_values=range(13),
|
2015-08-10 13:13:17 -07:00
|
|
|
description='List of performance tests to run.'),
|
|
|
|
Parameter('auto_mode', kind=bool, default=True,
|
|
|
|
description='Run tests in auto mode.'),
|
|
|
|
Parameter('timeout', kind=int, default=14400,
|
|
|
|
description='Timeout for the workload.'),
|
2015-10-01 11:37:05 -07:00
|
|
|
Parameter('file_size', kind=int,
|
2015-09-13 20:50:17 -07:00
|
|
|
description='Fixed file size.'),
|
2015-10-01 11:37:05 -07:00
|
|
|
Parameter('record_length', kind=int,
|
2015-08-10 13:13:17 -07:00
|
|
|
description='Fixed record length.'),
|
2015-10-01 11:37:05 -07:00
|
|
|
Parameter('threads', kind=int,
|
2015-08-10 13:13:17 -07:00
|
|
|
description='Number of threads'),
|
|
|
|
Parameter('other_params', kind=str, default='',
|
|
|
|
description='Other parameter. Run iozone -h to see'
|
|
|
|
' list of options.')
|
|
|
|
]
|
|
|
|
|
|
|
|
def initialize(self, context):
|
|
|
|
Iozone.host_binary = context.resolver.get(Executable(self,
|
|
|
|
self.device.abi,
|
|
|
|
'iozone'))
|
|
|
|
Iozone.device_binary = self.device.install(Iozone.host_binary)
|
|
|
|
|
|
|
|
def setup(self, context):
|
|
|
|
self.results = os.path.join(self.device.working_directory,
|
|
|
|
iozone_results_txt)
|
|
|
|
self.command = self._build_command()
|
|
|
|
|
|
|
|
if self.threads and self.auto_mode:
|
|
|
|
raise ConfigError("You cannot set the number of threads and enable"
|
|
|
|
" auto mode at the same time.")
|
|
|
|
|
|
|
|
def _build_command(self):
|
2015-10-08 09:16:32 +01:00
|
|
|
# pylint: disable=access-member-before-definition
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command = 'cd {} && {}'.format(self.device.working_directory,
|
|
|
|
self.device_binary)
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
if self.auto_mode:
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command += ' -a'
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
if self.tests:
|
2015-10-08 09:16:32 +01:00
|
|
|
if 0 not in self.tests:
|
|
|
|
self.tests = [0] + self.tests
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command += ''.join([' -i {}'.format(t) for t in self.tests])
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
if self.record_length > 0:
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command += ' -r {}'.format(self.record_length)
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
if self.threads > 0:
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command += ' -t {}'.format(self.threads)
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
if self.file_size > 0:
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command += ' -s {}'.format(self.file_size)
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
if self.other_params:
|
2015-09-13 20:50:17 -07:00
|
|
|
iozone_command += ' ' + self.other_params
|
|
|
|
|
|
|
|
# enable reporting mode for parsing non-thread results
|
|
|
|
iozone_command += ' -R > {}'.format(self.results)
|
|
|
|
|
|
|
|
# check if -b option is used
|
|
|
|
match = re.search(r'-b (.?\w+.?\w+?\s)', iozone_command)
|
|
|
|
if match:
|
2015-10-08 09:10:08 +01:00
|
|
|
self.user_file = match.group(1)
|
|
|
|
self.device_output_file = os.path.join(self.device.working_directory,
|
|
|
|
self.user_file)
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
return iozone_command
|
|
|
|
|
|
|
|
def run(self, context):
|
|
|
|
self.device.execute(self.command, timeout=self.timeout)
|
|
|
|
|
|
|
|
def update_result(self, context):
|
|
|
|
self.device.pull_file(self.results, context.output_directory)
|
2015-09-13 20:50:17 -07:00
|
|
|
self.outfile = os.path.join(context.output_directory,
|
|
|
|
iozone_results_txt)
|
2015-08-10 13:13:17 -07:00
|
|
|
|
2015-09-13 20:50:17 -07:00
|
|
|
if '-b' in self.other_params:
|
|
|
|
self.device.pull_file(self.device_output_file,
|
|
|
|
context.output_directory)
|
|
|
|
|
|
|
|
# if running in thread mode
|
|
|
|
if self.threads:
|
|
|
|
thread_results = self.parse_thread_results()
|
|
|
|
|
|
|
|
for name, value, units in thread_results:
|
|
|
|
context.add_metric(name, value, units)
|
|
|
|
|
|
|
|
# for non-thread mode results
|
|
|
|
else:
|
|
|
|
with open(self.outfile, 'r') as iozone_file:
|
|
|
|
iozone_file = (line.replace('\"', '') for line in iozone_file)
|
|
|
|
table_list = []
|
|
|
|
|
|
|
|
# begin parsing results
|
|
|
|
for line in iozone_file:
|
|
|
|
if 'Writer report' in line:
|
|
|
|
table_list.append(line.split())
|
|
|
|
break
|
|
|
|
|
|
|
|
for line in iozone_file:
|
|
|
|
if 'exiting' in line or 'completed' in line:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
table_list.append(line.split())
|
|
|
|
|
|
|
|
# create csv file
|
|
|
|
self.write_to_csv(context, table_list)
|
|
|
|
|
|
|
|
# parse metrics
|
|
|
|
self.parse_metrics(context, table_list)
|
|
|
|
|
|
|
|
def write_to_csv(self, context, csv_table_list):
|
|
|
|
self.test_file = os.path.join(context.output_directory,
|
|
|
|
'table_results.csv')
|
|
|
|
|
|
|
|
# create csv file for writing
|
|
|
|
csv_file = open(self.test_file, 'w')
|
|
|
|
wr = csv.writer(csv_file, delimiter=',')
|
|
|
|
|
|
|
|
# shift second row by adding extra element
|
|
|
|
# for "prettier" formatting
|
|
|
|
index = 0
|
|
|
|
for element in csv_table_list:
|
|
|
|
if element:
|
|
|
|
if index == 1:
|
|
|
|
element.insert(0, '0')
|
|
|
|
index += 1
|
|
|
|
else:
|
|
|
|
index = 0
|
|
|
|
|
|
|
|
# write to csv file
|
|
|
|
for item in csv_table_list:
|
|
|
|
wr.writerow(item)
|
|
|
|
|
|
|
|
csv_file.close()
|
|
|
|
|
|
|
|
# break list of results into smaller groups based on
|
2015-10-01 14:57:35 -07:00
|
|
|
# test name
|
2015-10-08 09:10:08 +01:00
|
|
|
def parse_metrics(self, context, plist): # pylint: disable=no-self-use
|
2015-09-13 20:50:17 -07:00
|
|
|
subvalue_list = []
|
|
|
|
value_list = []
|
|
|
|
for values in plist:
|
|
|
|
if values:
|
|
|
|
subvalue_list.append(values)
|
|
|
|
else:
|
|
|
|
value_list.append(subvalue_list)
|
|
|
|
subvalue_list = []
|
|
|
|
|
2015-10-08 09:10:08 +01:00
|
|
|
# If users run a list of specific tests, make
|
2015-10-01 14:57:35 -07:00
|
|
|
# sure that the results for the last test
|
|
|
|
# executed are appended.
|
2015-10-01 12:38:04 -07:00
|
|
|
if subvalue_list:
|
|
|
|
value_list.append(subvalue_list)
|
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
for reports in value_list:
|
|
|
|
# grab report name and convert it to a string
|
|
|
|
report_name = reports[0]
|
|
|
|
report_name = report_name[:-1]
|
|
|
|
report_name = '_'.join(report_name).lower()
|
|
|
|
|
|
|
|
record_sizes = reports[1]
|
|
|
|
values = reports[2:]
|
2015-10-01 11:52:51 -07:00
|
|
|
|
|
|
|
for v in values:
|
|
|
|
templist = OrderedDict(izip_longest(record_sizes, v))
|
|
|
|
|
2015-10-08 09:10:08 +01:00
|
|
|
for reclen, value in templist.items():
|
2015-10-01 11:37:05 -07:00
|
|
|
if reclen is '0':
|
|
|
|
fs = value
|
2015-10-01 11:52:51 -07:00
|
|
|
|
2015-10-01 11:37:05 -07:00
|
|
|
if value is None:
|
|
|
|
value = '0'
|
2015-10-01 11:52:51 -07:00
|
|
|
|
|
|
|
classifiers = {'reclen': reclen, 'file_size': fs}
|
2015-10-01 11:37:05 -07:00
|
|
|
if reclen != '0':
|
2015-10-01 11:52:51 -07:00
|
|
|
context.add_metric(report_name, int(value), 'kb/s',
|
|
|
|
classifiers=classifiers)
|
2015-09-13 20:50:17 -07:00
|
|
|
|
|
|
|
# parse thread-mode results
|
|
|
|
def parse_thread_results(self):
|
|
|
|
results = []
|
|
|
|
with open(self.outfile, 'r') as iozone_file:
|
2015-08-10 13:13:17 -07:00
|
|
|
for line in iozone_file:
|
2015-09-13 20:50:17 -07:00
|
|
|
# grab section of data we care about
|
|
|
|
if 'Throughput report' in line:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
if '=' in line:
|
|
|
|
if 'Time Resolution' not in line:
|
|
|
|
line = line.replace('=', '')
|
|
|
|
line = line.split()
|
|
|
|
|
|
|
|
# grab headers
|
|
|
|
if len(line) >= 8:
|
|
|
|
header = line[0]
|
|
|
|
subheader = ' '.join(line[-5:-2])
|
|
|
|
header += ' ' + subheader
|
|
|
|
else:
|
|
|
|
header = ' '.join(line[0:2])
|
|
|
|
|
|
|
|
units = line[-1]
|
|
|
|
value = line[-2]
|
|
|
|
tup = (header, value, units)
|
|
|
|
results.append(tup)
|
|
|
|
|
|
|
|
return results
|
2015-08-10 13:13:17 -07:00
|
|
|
|
|
|
|
def finalize(self, context):
|
|
|
|
self.device.uninstall_executable(self.device_binary)
|