|
def check_read_write_speeds(self, drive: Path, size='16Gb', bs='1M', direct=1, numjobs=1, ioengine= 'windowsaio', |
|
iodepth=1, runtime=0): |
|
"""Check local read/write speeds to make sure it can keep up with acquisition |
|
|
|
:param drive: Drive testing read/write speeds. Usually the local or external storage of instrument |
|
:param size: Size of test file |
|
:param bs: Block size in bytes used for I/O units |
|
:param direct: Specifying buffered (0) or unbuffered (1) operation |
|
:param numjobs: Number of clones of this job. Each clone of job is spawned as an independent thread or process |
|
:param ioengine: Defines how the job issues I/O to the file |
|
:param iodepth: Number of I/O units to keep in flight against the file. |
|
:param runtime: Limit runtime. The test will run until it completes the configured I/O workload or until it has |
|
run for this specified amount of time, whichever occurs first |
|
""" |
|
|
|
test_filename = fr"{drive}\test.txt" |
|
f = open(test_filename, 'a') # Create empty file to check reading/writing speed |
|
f.close() |
|
try: |
|
speed_MB_s = {} |
|
for check in ['read', 'write']: |
|
output = subprocess.check_output( |
|
fr'fio --name=test --filename={test_filename} --size={size} --rw={check} --bs={bs} ' |
|
fr'--direct={direct} --numjobs={numjobs} --ioengine={ioengine} --iodepth={iodepth} ' |
|
fr'--runtime={runtime} --startdelay=0 --thread --group_reporting', shell=True) |
|
out = str(output) |
|
# Converting MiB to MB = (10**6/2**20) |
|
speed_MB_s[check] = round( |
|
float(out[out.find('BW=') + len('BW='):out.find('MiB/s')]) / (10 ** 6 / 2 ** 20)) |
|
|
|
# converting B/s to MB/s |
|
acq_speed_MB_s = (self.cfg.bytes_per_image * (1 / 1000000)) * (1 / self.cfg.get_period_time()) |
|
|
|
# Go through both speeds and specify if one or both are the problem |
|
read_too_slow = False |
|
write_too_slow = False |
|
|
|
if speed_MB_s['read'] <= acq_speed_MB_s: |
|
read_too_slow = True |
|
self.log.warning(f'{drive} read speed too slow') |
|
|
|
if speed_MB_s['write'] <= acq_speed_MB_s: |
|
write_too_slow = True |
|
self.log.warning(f'{drive} write speed too slow') |
|
|
|
if read_too_slow or write_too_slow: |
|
raise |
|
except subprocess.CalledProcessError: |
|
self.log.warning('fios not installed on computer. Cannot verify read/write speed') |
|
finally: |
|
# Delete test file |
|
os.remove(test_filename) |