Better unit handling during I/O Benchmarks
* All results are in MB/s
This commit is contained in:
parent
501191b388
commit
04f7ae2f21
2 changed files with 16 additions and 7 deletions
|
|
@ -131,9 +131,9 @@ def clear_screen():
|
|||
def convert_to_bytes(size):
|
||||
"""Convert human-readable size str to bytes and return an int."""
|
||||
size = str(size)
|
||||
tmp = re.search(r'(\d+)\s+([KMGT]B)', size.upper())
|
||||
tmp = re.search(r'(\d+\.?\d*)\s+([KMGT]B)', size.upper())
|
||||
if tmp:
|
||||
size = int(tmp.group(1))
|
||||
size = float(tmp.group(1))
|
||||
units = tmp.group(2)
|
||||
if units == 'TB':
|
||||
size *= 1099511627776
|
||||
|
|
@ -143,6 +143,7 @@ def convert_to_bytes(size):
|
|||
size *= 1048576
|
||||
elif units == 'KB':
|
||||
size *= 1024
|
||||
size = int(size)
|
||||
else:
|
||||
return -1
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,14 @@ TESTS = {
|
|||
},
|
||||
}
|
||||
|
||||
def get_read_rate(s):
|
||||
"""Get read rate in bytes/s from dd progress output."""
|
||||
real_rate = None
|
||||
if re.search(r'[KMGT]B/s', s):
|
||||
human_rate = re.sub(r'^.*\s+(\d+\.?\d*)\s+(.B)/s\s*$', r'\1 \2', s)
|
||||
real_rate = convert_to_bytes(human_rate)
|
||||
return real_rate
|
||||
|
||||
def get_smart_details(dev):
|
||||
"""Get SMART data for dev if possible, returns dict."""
|
||||
cmd = 'sudo smartctl --all --json /dev/{}'.format(dev).split()
|
||||
|
|
@ -253,15 +261,15 @@ def run_iobenchmark():
|
|||
text = f.read()
|
||||
io_stats = text.replace('\r', '\n').split('\n')
|
||||
try:
|
||||
io_stats = [re.sub(r'.*\s+(\d+) MB/s\s*$', r'\1', stat)
|
||||
for stat in io_stats if 'MB/s' in stat]
|
||||
io_stats = [int(x) for x in io_stats]
|
||||
TESTS['iobenchmark']['Results'][name] = 'Read speed: {:0.0f} MB/s (Min: {}, Max: {})'.format(
|
||||
io_stats = [get_read_rate(s) for s in io_stats]
|
||||
io_stats = [float(s/1048576) for s in io_stats if s]
|
||||
TESTS['iobenchmark']['Results'][name] = 'Read speed: {:3.1f} MB/s (Min: {:3.1f}, Max: {:3.1f})'.format(
|
||||
sum(io_stats) / len(io_stats),
|
||||
min(io_stats),
|
||||
max(io_stats))
|
||||
TESTS['iobenchmark']['Status'][name] = 'CS'
|
||||
except:
|
||||
# Requires manual testing
|
||||
TESTS['iobenchmark']['Status'][name] = 'NS'
|
||||
|
||||
# Move temp file
|
||||
|
|
@ -569,7 +577,7 @@ def scan_disks():
|
|||
'/dev/{}'.format(dev)))
|
||||
dev_name = data['lsblk']['name']
|
||||
print_standard(' ')
|
||||
if ask('Run badblocks for this device anyway?'):
|
||||
if ask('Run tests on this device anyway?'):
|
||||
TESTS['NVMe/SMART']['Status'][dev_name] = 'OVERRIDE'
|
||||
else:
|
||||
TESTS['NVMe/SMART']['Status'][dev_name] = 'NS'
|
||||
|
|
|
|||
Loading…
Reference in a new issue