]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/vhost/fiotest/run_fio.py
14 print("""Usage: python run_fio.py [options] [args]
16 [VMs] (ex. vm1_IP:vm1_port:vm1_disk1:vm_disk2,vm2_IP:vm2_port:vm2_disk1,etc...)
18 -h, --help Show this message.
19 -j, --job-files Paths to files with custom FIO jobs configuration.
20 -f, --fio-bin Location of FIO binary (Default "fio")
21 -o, --out Directory used to save generated job files and
22 files with test results (Default: same dir where
23 this script is located)
24 -p, --perf-vmex Enable aggregating statistic for VMEXITS for VMs
28 def exec_cmd(cmd
, blocking
):
29 # Print result to STDOUT for now, we don't have json support yet.
30 p
= subprocess
.Popen(cmd
.split(" "), stdout
=subprocess
.PIPE
,
31 stderr
=subprocess
.STDOUT
, stdin
=subprocess
.PIPE
)
33 out
, _
= p
.communicate()
34 return p
.returncode
, out
38 def save_file(path
, mode
, contents
):
39 with
open(path
, mode
) as fh
:
44 def run_fio(vms
, fio_cfg_fname
, out_path
, perf_vmex
=False):
46 fio_cfg_prefix
= fio_cfg_fname
.split(".")[0]
48 # Build command for FIO
49 fio_cmd
= " ".join([fio_bin
, "--eta=never"])
51 # vm[0] = IP address, vm[1] = Port number
52 fio_cmd
= " ".join([fio_cmd
,
53 "--client={vm_ip},{vm_port}".format(vm_ip
=vm
[0], vm_port
=vm
[1]),
54 "--remote-config /root/{cfg}".format(cfg
=fio_cfg_fname
)])
58 perf_dir
= os
.path
.join(out_path
, "perf_stats")
64 # Start gathering perf statistics for host and VM guests
65 perf_rec_file
= os
.path
.join(perf_dir
, "perf.data.kvm")
66 perf_run_cmd
= "perf kvm --host --guest " + \
67 "-o {0} stat record -a".format(perf_rec_file
)
69 perf_p
= exec_cmd(perf_run_cmd
, blocking
=False)
72 rc
, out
= exec_cmd(fio_cmd
, blocking
=True)
74 # if for some reason output contains lines with "eta" - remove them
75 out
= re
.sub(r
'.+\[eta\s+\d{2}m:\d{2}s\]', '', out
)
78 print("ERROR! While executing FIO jobs - RC: {rc}, Err message: {out}".format(rc
=rc
, out
=out
))
82 save_file(os
.path
.join(out_path
, ".".join([fio_cfg_prefix
, "log"])), "w", out
)
85 # Stop gathering perf statistics and prepare some result files
86 perf_p
.send_signal(signal
.SIGINT
)
89 perf_stat_cmd
= "perf kvm --host -i {perf_rec} stat report --event vmexit"\
90 .format(perf_rec
=perf_rec_file
)
92 rc
, out
= exec_cmd(" ".join([perf_stat_cmd
, "--event vmexit"]),
94 print("VMexit host stats:")
95 print("{perf_out}".format(perf_out
=out
))
96 save_file(os
.path
.join(perf_dir
, "vmexit_stats_" + fio_cfg_prefix
),
97 "w", "{perf_out}".format(perf_out
=out
))
99 os
.remove(perf_rec_file
)
107 abspath
= os
.path
.abspath(__file__
)
108 dname
= os
.path
.dirname(abspath
)
109 os
.chdir(os
.path
.join(dname
, "../../.."))
114 out_dir
= os
.path
.join(os
.getcwd(), "fio_results")
117 opts
, args
= getopt
.getopt(sys
.argv
[1:], "hj:f:o:p",
118 ["help", "job-file=", "fio-bin=",
119 "out=", "perf-vmex"])
120 except getopt
.GetoptError
:
125 if o
in ("-j", "--job-file"):
126 fio_cfgs
= a
.split(",")
127 elif o
in ("-h", "--help"):
130 elif o
in ("-p", "--perf-vmex"):
132 elif o
in ("-o", "--out"):
133 out_dir
= os
.path
.join(a
, "fio_results")
134 elif o
in ("-f", "--fio-bin"):
137 if len(fio_cfgs
) < 1:
138 print("ERROR! No FIO jobs provided!")
145 # Get IP, port and fio 'filename' information from positional args
146 for arg
in args
[0].split(","):
148 ip
, port
, filenames
= _
[0], _
[1], ":".join(_
[2:])
149 vms
.append((ip
, port
, filenames
))
151 if not os
.path
.exists(out_dir
):
154 for fio_cfg
in fio_cfgs
:
155 fio_cfg_fname
= os
.path
.basename(fio_cfg
)
156 print("Running job file: {0}".format(fio_cfg_fname
))
158 for i
, vm
in enumerate(vms
):
159 # VM - tuple of IP / Port / Filename for VM to run test
160 print("Preparing VM {0} - {1} for FIO job".format(i
, vm
[0]))
162 exec_cmd("./test/vhost/fiotest/vm_ssh.sh {vm_num} sh -c 'rm {cfg}'"
163 .format(vm_num
=i
, cfg
=fio_cfg_fname
), blocking
=True)
165 # Copy FIO config to VM
166 with
open(fio_cfg
, "r") as fio_cfg_fh
:
167 for line
in fio_cfg_fh
.readlines():
168 if "filename" in line
:
169 line
= "filename=" + vm
[2]
170 out
= exec_cmd("./test/vhost/fiotest/vm_ssh.sh {vm_num} sh -c 'echo {line} >> {cfg}'"
171 .format(vm_num
=i
, line
=line
.strip(), cfg
=fio_cfg_fname
), blocking
=True)
173 print("ERROR! While copying FIO job config file to VM {vm_num} - {vm_ip}"
174 .format(vm_num
=1, vm_ip
=vm
[0]))
177 run_fio(vms
, fio_cfg_fname
, out_dir
, perf_vmex
)
179 if __name__
== "__main__":