一图胜万言。在测试性能的时候,尤其如此。对于我们常常用到的fio 测试的结果,怎么样能快速生成图表?

确保FIO命令能够记录性能数据

参考下面的命令:

fio -filename=/dev/nvme2n1 -thread -numjobs=1 -iodepth=64 --bs=4K -direct=1 --rw=write -ioengine=libaio --group_reporting -name=perf --output-format=normal --log_avg_msec=10000 --write_bw_log=1M-write.results --write_iops_log=1M-write.results --write_lat_log=1M-write.results --runtime=21 --time_based

上面的命令执行完之后,大概会生成如下的几个性能数据文件:

[root@szw] nvme_ssd_performance_test]# ls -alrt
total 40
drwxr-xr-x 6 root root 4096 Jan 21 07:57 ..
-rw-r--r-- 1 root root  305 Jan 21 08:20 draw_result.py
-rw------- 1 root root 2999 Jan 21 14:20 nohup.out
-rw-r--r-- 1 root root  650 Jan 21 15:39 run-fio.sh
drwxr-xr-x 2 root root 4096 Jan 21 15:39 .
-rw-r--r-- 1 root root  171 Jan 21 15:40 1M-write.results_slat.1.log
-rw-r--r-- 1 root root  203 Jan 21 15:40 1M-write.results_lat.1.log
-rw-r--r-- 1 root root  203 Jan 21 15:40 1M-write.results_clat.1.log
-rw-r--r-- 1 root root  171 Jan 21 15:40 1M-write.results_iops.1.log
-rw-r--r-- 1 root root  171 Jan 21 15:40 1M-write.results_bw.1.log

准备绘图环境

在mac 环境

sudo python -mpip install matplotlib
安装完后,你可以使用 python -m pip list 命令来查看是否安装了 matplotlib 模块。

在Linux环境

Debian / Ubuntu:
sudo apt-get install python-matplotlib
Fedora / Redhat:
sudo yum install python-matplotlib

导出性能数据、制作图表

 参考下面的命令,可以绘图:
“`
chao@B00000B:~$cat draw.py

!/usr/bin/python

coding: utf-8

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

mpl.rcParams[‘font.family’] = ‘sans-serif’
mpl.rcParams[‘font.sans-serif’] = ‘NSimSun,Times New Roman’

a = np.loadtxt(‘./bw.txt’, delimiter=’,’)
print(a)

x,y,z,v = np.loadtxt(‘./bw.txt’, delimiter=’,’, unpack=True)

x, y, z = np.loadtxt(‘./bw.txt’, delimiter=’,’)

plt.plot(x, y, ‘*’, label=’Data’, color=’black’)

plt.xlabel(‘time_ms’)
plt.ylabel(‘throughput_mb’)
plt.title(‘throughput-time grapth’)
plt.plot(x,y)

plt.show()

plt.show()
“`
实际效果如下:

plt.legend()