Skip to content

Instantly share code, notes, and snippets.

@sennajox
Last active December 21, 2023 11:00
Show Gist options
  • Save sennajox/3667757 to your computer and use it in GitHub Desktop.
Save sennajox/3667757 to your computer and use it in GitHub Desktop.
A script that runs fio test and genearates a simple result for each jobs
#!/bin/bash
if [ $# -lt 2 ]; then
echo "usage:$0 dev output_dir [iodepth]"
echo "example 1: Testing the whole block device. Attention: That will destory the filesystem on the target block device"
echo "./run_fio.sh /dev/sdb fio_test"
echo ""
echo "example 2: Testing a file, but not destory filesystem. Suppose the target device mount on /data"
echo "fallocate -l 1G /data/test.dat"
echo "./run_fio.sh /data/test.dat fio_test"
echo ""
echo "Finally, it will genarate a certain result into the output_dir, like 'fio_test/fio_test.result"
exit 1
fi
DEV="$1"
OUTDIR="$2"
if [ ! -d $OUTDIR ]; then
mkdir -p $OUTDIR
fi
# default iodepth=8
IODEPTH=8
if [ $# -ge 3 ]; then
if [ $3 -gt 0 ]; then
IODEPTH=$3
fi
fi
echo "IODEPTH=$IODEPTH"
RUNTIME=30
BLOCK_SIZES=(512 4K 8K 16K 64K 128K 256K 512K)
JOBS=(write randwrite read randread randrw)
# if you test randrw, you need to specify the rwmixreads in this array
RWMIXREADS=(50 30)
gen_job_file()
{
# gen_job_file job block_size [rwmixread]
job=$1
block_size=$2
echo "[global]" > $job
echo "bs=$block_size" >> $job
echo "direct=1" >> $job
echo "rw=$job" >> $job
echo "ioengine=libaio" >> $job
echo "iodepth=$IODEPTH" >> $job
echo "runtime=$RUNTIME" >> $job
if [ "$job" == "randwrite" -o "$job" == "randread" -o "$job" == "randrw" ]; then
echo "randrepeat=0" >> $job
fi
echo "[test]" >> $job
echo "filename=$DEV" >> $job
if [ "$job" == "randrw" ]; then
echo "rwmixread=$3" >> $job
fi
}
cleanup()
{
for job in "${JOBS[@]}"
do
rm -f $job
done
rm -f *.tmp
}
run_test()
{
job=$1
block_size=$2
if [ $# -lt 3 ]; then
output="$OUTDIR/fio.$job.$block_size.1.log"
else
output="$OUTDIR/fio.$job.$block_size.$3.1.log"
fi
fio --output="$output" $job
}
# run all the jobs
for job in "${JOBS[@]}"
do
# generate job file for current job
for block_size in "${BLOCK_SIZES[@]}"
do
if [ "$job" != "randrw" ]; then
echo "run $job in $block_size"
gen_job_file $job $block_size
run_test $job $block_size
else
for rate in "${RWMIXREADS[@]}"
do
echo "run $job in $block_size, rwmixread=$rate"
gen_job_file $job $block_size $rate
run_test $job $block_size $rate
done
fi
done
done
bw_array=()
iops_array=()
lat_array=()
select_bw()
{
index=$1
file=$2
# unit:KB/S
bw=`grep "bw=" "$file" | awk -F[=,B]+ '{if(match($4, /[0-9]+K$/)) {printf("%d", substr($4, 0, length($4)-1));} else {printf("%d", int($4)/1024)}}'`
bw_array[$index]="$bw"
}
select_iops()
{
index=$1
file=$2
iops=`grep "iops=" "$file" | awk -F[=,]+ '{print $6}'`
iops_array[$index]="$iops"
}
select_lat()
{
index=$1
file=$2
# unit:ms
line=`grep "lat" "$file" | grep "avg" | grep -v -E "clat|slat"`
lat=`echo $line | awk -F[=,:]+ '{if($1 == "lat (usec)") {printf("%.2f", $7/1000);} else {printf("%.2f", $7)} }'`
lat_array[$index]="$lat"
}
# use for test randrw
bw_array_rw_read=()
iops_array_rw_read=()
lat_array_rw_read=()
bw_array_rw_write=()
iops_array_rw_write=()
lat_array_rw_write=()
select_bw_rw()
{
index=$1
file=$2
# unit:KB/S
bw_read=`grep "bw=" "$file" | grep read | awk -F[=,B]+ '{if(match($4, /[0-9]+K$/)) {printf("%d", substr($4, 0, length($4)-1));} else {printf("%d", int($4)/1024)}}'`
bw_write=`grep "bw=" "$file" | grep write | awk -F[=,B]+ '{if(match($4, /[0-9]+K$/)) {printf("%d", substr($4, 0, length($4)-1));} else {printf("%d", int($4)/1024)}}'`
bw_array_rw_read[$index]="$bw_read"
bw_array_rw_write[$index]="$bw_write"
}
select_iops_rw()
{
index=$1
file=$2
iops_read=`grep "iops=" "$file" | grep read | awk -F[=,]+ '{print $6}'`
iops_write=`grep "iops=" "$file" | grep write | awk -F[=,]+ '{print $6}'`
iops_array_rw_read[$index]="$iops_read"
iops_array_rw_write[$index]="$iops_write"
}
select_lat_rw()
{
index=$1
file=$2
# unit:ms
line=`grep "read" "$file" -A3 | grep "avg" | grep -v -E "clat|slat"`
lat_read=`echo $line | awk -F[=,:]+ '{if($1 == "lat (usec)") {printf("%.2f", $7/1000);} else {printf("%.2f", $7)} }'`
line=`grep "write" "$file" -A3 | grep "avg" | grep -v -E "clat|slat"`
lat_write=`echo $line | awk -F[=,:]+ '{if($1 == "lat (usec)") {printf("%.2f", $7/1000);} else {printf("%.2f", $7)} }'`
lat_array_rw_read[$index]="$lat_read"
lat_array_rw_write[$index]="$lat_write"
}
# generate the test result table
output_file="$OUTDIR/$OUTDIR.result"
echo > "$output_file"
for job in "${JOBS[@]}"
do
if [ "$job" != "randrw" ]; then
echo "[$job] ${BLOCK_SIZES[@]}" >> "$output_file"
for (( i = 0; i < ${#BLOCK_SIZES[@]}; ++i ))
do
block_size=${BLOCK_SIZES[$i]}
file="$OUTDIR/fio.$job.$block_size.1.log"
echo $file
select_bw $i $file
select_iops $i $file
select_lat $i $file
done
echo "[bw] ${bw_array[@]}" >> $output_file
echo "[lat] ${lat_array[@]}" >> $output_file
echo "[iops] ${iops_array[@]}" >> $output_file
echo >> $output_file
# clear array
bw_array=()
iops_array=()
lat_array=()
else
for rate in "${RWMIXREADS[@]}"
do
echo "[$job"_"$rate] ${BLOCK_SIZES[@]}" >> "$output_file"
for (( i = 0; i < ${#BLOCK_SIZES[@]}; ++i ))
do
block_size=${BLOCK_SIZES[$i]}
file="$OUTDIR/fio.$job.$block_size.$rate.1.log"
echo $file
select_bw_rw $i $file
select_iops_rw $i $file
select_lat_rw $i $file
done
echo "[bw_read] ${bw_array_rw_read[@]}" >> $output_file
echo "[lat_read] ${lat_array_rw_read[@]}" >> $output_file
echo "[iops_read] ${iops_array_rw_read[@]}" >> $output_file
echo "[bw_write] ${bw_array_rw_write[@]}" >> $output_file
echo "[lat_write] ${lat_array_rw_write[@]}" >> $output_file
echo "[iops_write] ${iops_array_rw_write[@]}" >> $output_file
echo >> $output_file
# clear array
bw_array_rw_read=()
iops_array_rw_read=()
lat_array_rw_read=()
bw_array_rw_write=()
iops_array_rw_write=()
lat_array_rw_write=()
done
fi
done
cleanup
@nooperpudd
Copy link

fio-3.28. output data is empty for the fio_test.result

[write] 512 4K 8K 16K 64K 128K 256K 512K
[bw]
[lat] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[iops]

[randwrite] 512 4K 8K 16K 64K 128K 256K 512K
[bw]
[lat] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[iops]

[read] 512 4K 8K 16K 64K 128K 256K 512K
[bw] 0 0 0 0 0 0 0 0
[lat] 0.02 17805.35 18863.64 23178.73 0.04 0.07 0.18 0.24
[iops]

[randread] 512 4K 8K 16K 64K 128K 256K 512K
[bw] 0 0 0 0 0 0 0 0
[lat] 0.02 0.02 20368.68 0.02 0.04 0.09 0.17 0.24
[iops]

[randrw_50] 512 4K 8K 16K 64K 128K 256K 512K
[bw_read]
[lat_read] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[iops_read]
[bw_write]
[lat_write] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[iops_write]

[randrw_30] 512 4K 8K 16K 64K 128K 256K 512K
[bw_read]
[lat_read] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[iops_read]
[bw_write]
[lat_write] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[iops_write]

for the file test result :

ubuntu@ip-11-0-2-91:~/fio_test$ cat fio.randread.128K.1.log
test: (g=0): rw=randread, bs=(R) 128KiB-128KiB, (W) 128KiB-128KiB, (T) 128KiB-128KiB, ioengine=libaio, iodepth=8
fio-3.28
Starting 1 process

test: (groupid=0, jobs=1): err= 0: pid=12028: Wed Dec 28 08:59:19 2022
  read: IOPS=83.6k, BW=10.2GiB/s (11.0GB/s)(1024MiB/98msec)
    slat (nsec): min=7663, max=63351, avg=10321.76, stdev=4405.05
    clat (nsec): min=1362, max=359258, avg=83615.78, stdev=15380.53
     lat (usec): min=9, max=421, avg=94.08, stdev=16.78
    clat percentiles (usec):
     |  1.00th=[   62],  5.00th=[   64], 10.00th=[   65], 20.00th=[   72],
     | 30.00th=[   75], 40.00th=[   79], 50.00th=[   82], 60.00th=[   86],
     | 70.00th=[   90], 80.00th=[   95], 90.00th=[  103], 95.00th=[  110],
     | 99.00th=[  125], 99.50th=[  133], 99.90th=[  169], 99.95th=[  217],
     | 99.99th=[  359]
  lat (usec)   : 2=0.01%, 20=0.02%, 50=0.02%, 100=87.28%, 250=12.61%
  lat (usec)   : 500=0.05%
  cpu          : usr=11.34%, sys=86.60%, ctx=0, majf=0, minf=266
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=99.9%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=8192,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=8

Run status group 0 (all jobs):
   READ: bw=10.2GiB/s (11.0GB/s), 10.2GiB/s-10.2GiB/s (11.0GB/s-11.0GB/s), io=1024MiB (1074MB), run=98-98msec

Disk stats (read/write):
  nvme1n1: ios=0/0, merge=0/0, ticks=0/0, in_queue=0, util=0.00%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment