天天看点

fio_generate_plotsFio Git URLScript Path关于 gnuplot 的使用

安装 fio 源码后即可使用 fio_generate_plots。

Fio Git URL

# you can execute "git clone git://git.kernel.dk/fio.git"
git://git.kernel.dk/fio.git
           

Script Path

fio/tools/
           

该工具默认绘制 Latency、IOPS、slat、clat、BandWidth 等 5 种曲线,默认是 将相邻点连线(lines)。

  • 只绘制 IOPS 的曲线
# 可以修改 脚本 fio_generate_plots,如下:

#plot "I/O Latency" lat "Time (msec)" 1000
plot "I/O Operations Per Second" iops "IOPS" 1
#plot "I/O Submission Latency" slat "Time (μsec)" 1
#plot "I/O Completion Latency" clat "Time (msec)" 1000
#plot "I/O Bandwidth" bw "Throughput (KB/s)" 1
           
  • 只需要标记数据点
# 可将 lines 修改为 point。
PLOT_LINE=$PLOT_LINE"'$x' using (\$1/1000):(\$2/$SCALE) title \"Queue depth $DEPTH\" with point ls $i"
           
  • 修改完成后,重新编译安装 fio 即可使用
make clean && make -j8 && make install -j8
           
  • 如何使用 fio_generate_plots

关于 gnuplot 的使用

安装 gnuplot

# install for CentOS
yum install -y gnuplot
           

绘图

# 输出图片格式:
set term jpeg size 1280,720
set title 'plot for sin'
set output 'sin.jpeg'

# plot 语句
p [0:100] [-1:1] "sin.log" u 1:2 title "sin" w lp lt 1 lw 2 lc "green" pt 4 ps 2
           
  • set term jpeg size 1280,720
    • 设置输出图片大小为 1280 * 720,输出格式为 *.jpeg
  • set title ‘plot for sin’
    • 设置图片标题为 plot for sin
  • set output ‘sin.jpeg’
    • 设置输出图片名称为 sin.jpeg

上述 plot 语句使用了简写命令,

# 实际上相当于:
plot [0:100] [-1:1] "sin.log" using 1:2 title "sin" with linepoint linetype 1 linewidth 2 linecolor "green" pointtype 4 pointsize 2
           

接下来,分析下每个参数具体是什么意思:

  • p [0:100] [-1:1]
    • p 就是 plot,后面的两项分别为图片显示的 x 轴、y 轴的坐标范围。
  • “sin.log” u 1:2
    • 用 “sin.log” 中的第 1、2 列数据画图,其中第 1 列数据作为横坐标,第 2 列数据作为纵坐标。
  • title “sin”
    • 命名这条曲线为 “sin”,此处的名称为该曲线在图例中显示的名称,并不是图片的标题。
  • w lp
    • 即 with linepoint ,标记数据点并将数据点连线。with 后的属性参数有多个选择,对应不同的作图方式(style)。

      在图形界面的终端中输入 help with 或者 help style 就可以查到可供选择的 style 参数。常用的作图方式参数及对应含义如下表所示:

style 参数 简写命令 含义
line l 将相邻的数据点连线
point p 将每一个数据点用一个符号标记
linepoint lp 将每一个数据点用一个符号标记,并将相邻数据点连线
impulses i 将每一个数据点画一条垂直线至 x 轴
dots d 将每一个数据点绘制一个细点
steps st 分别用一条垂直线及水平线 来连接两点,并形成台阶状图形
errorbars e 对每一点坐标值(x, y),绘制一条由(x, ylow) 至(x, yhigh) 的线段。并在线段两端做上标记
boxes boxes 以 x 坐标为中心 绘制 柱状图
boxerrorbars boxerrorbars 相当于 errorbars 与 boxes
  • lt 1
    • 即 linetype 1 ,规定了连线的类型,-1 对应黑虚线,0 对应黑虚线,大于 0 的整数对应不同颜色的实线。
    • 1 为紫色,2 为绿色,3 为蓝色,4 为橙色、5 为黄色、6 为深蓝色、7 为红色、8 为黑色,大于 8 的数字对应的颜色与其对 8 取余对应的颜色相同。
  • lw 2
    • 即 linewidth 2 ,规定了线的宽度,数字越大,线条越宽。
  • lc “green”
    • 即 linecolor “green” ,规定了线的颜色。除了之前利用 lt 来规定线的颜色之外,也可以通过这个语句单独设置线的颜色,可供选择的颜色比 lt 中的多。

      在图形界面的终端中输入 show colorname 就可以查看不同的 RGB 对应的名称。

  • pt 4
    • 即 pointtype 4,规定了标记点的类型。不同数字对应的标记点如下:
数字 1 2 3 4 5 6 7 8 9 10 11 12 13
标记符号 + ×
  • ps 2
    • 即 pointsize 2,规定了标志的大小,数字越大,标志越大。标志 的颜色 和 线 的颜色相同。

继续阅读