blob: 8e2e09f060c0644f6735983a788cbe839cbbb681 [file] [log] [blame]
koder aka kdanilov70227062016-11-26 23:23:21 +02001import os
2import time
3import stat
4import random
5import subprocess
6
7
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +03008def rpc_run_fio(cfg):
9 fio_cmd_templ = "cd {exec_folder}; {fio_path}fio --output-format=json " + \
10 "--output={out_file} --alloc-size=262144 {job_file}"
11
koder aka kdanilov70227062016-11-26 23:23:21 +020012 result = {
13 "name": [float],
14 "lat_name": [[float]]
15 }
16
17 return result
koder aka kdanilov3b4da8b2016-10-17 00:17:53 +030018 # fnames_before = node.run("ls -1 " + exec_folder, nolog=True)
19 #
20 # timeout = int(exec_time + max(300, exec_time))
21 # soft_end_time = time.time() + exec_time
22 # logger.error("Fio timeouted on node {}. Killing it".format(node))
23 # end = time.time()
24 # fnames_after = node.run("ls -1 " + exec_folder, nolog=True)
25 #
26
koder aka kdanilov70227062016-11-26 23:23:21 +020027def rpc_check_file_prefilled(path, used_size_mb):
28 used_size = used_size_mb * 1024 ** 2
29 blocks_to_check = 16
30
31 try:
32 fstats = os.stat(path)
33 if stat.S_ISREG(fstats.st_mode) and fstats.st_size < used_size:
34 return True
35 except EnvironmentError:
36 return True
37
38 offsets = [random.randrange(used_size - 1024) for _ in range(blocks_to_check)]
39 offsets.append(used_size - 1024)
40 offsets.append(0)
41
42 with open(path, 'rb') as fd:
43 for offset in offsets:
44 fd.seek(offset)
45 if b"\x00" * 1024 == fd.read(1024):
46 return True
47
48 return False
49
50
51def rpc_prefill_test_files(files, force=False, fio_path='fio'):
52 cmd_templ = "{0} --name=xxx --filename={1} --direct=1" + \
53 " --bs=4m --size={2}m --rw=write"
54
55 ssize = 0
56 ddtime = 0.0
57
58 for fname, curr_sz in files.items():
59 if not force:
60 if not rpc_check_file_prefilled(fname, curr_sz):
61 continue
62
63 cmd = cmd_templ.format(fio_path, fname, curr_sz)
64 ssize += curr_sz
65
66 stime = time.time()
67 subprocess.check_call(cmd)
68 ddtime += time.time() - stime
69
70 if ddtime > 1.0:
71 return int(ssize / ddtime)
72
73 return None
74
75
76def load_fio_log_file(fname):
77 with open(fname) as fd:
78 it = [ln.split(',')[:2] for ln in fd]
79
80 return [(float(off) / 1000, # convert us to ms
81 float(val.strip()) + 0.5) # add 0.5 to compemsate average value
82 # as fio trimm all values in log to integer
83 for off, val in it]
84
85
86
87
88
89