summaryrefslogblamecommitdiffstats
path: root/dev-tools/io_test.sh
blob: 74e88a31ce19258f1047ea75ee9ab832cd3a6ef9 (plain) (tree)
1
2
3
4
5
6
7
                        

                                    
            
                                     

                                                                               





































                                                                               

                                                                 








                                            

                                                            

                                                        



                                                                       
 

                                                                            
 



                              

                                                           

                                                                            
                                                                  




                                                                  
                                                        





                                                 













                                                                   
                                                            


                                          

                                                                 
                                                                        








                                     








                                               
    
image="$(realpath "$1")"
test_directory=/tmp/performance_test
[ ! -z $2 ] && test_directory="$2"
test_time=20
image_directory="$(dirname "$image")"
dnbd3_rootfs_directory="$(dirname "${BASH_SOURCE[0]}")/../builder/dnbd3-rootfs"
log_directory="$(dirname "${BASH_SOURCE[0]}")/io_test_logs"
mountpoint_xmount="${test_directory}/mnt_xmount"
mountpoint="${test_directory}/mnt"


source ${dnbd3_rootfs_directory}/scripts/build.sh

if [[ ! -d "$test_directory" ]]; then
    mkdir "$test_directory"
    mkdir "$mountpoint_xmount"
    mkdir "$mountpoint"
    mkdir "$log_directory"

    build_clean_xmount ${dnbd3_rootfs_directory}/binaries/xmount
    build_clean_qemu_xmount ${dnbd3_rootfs_directory}/binaries/qemu-xmount

    build_compile_xmount ${dnbd3_rootfs_directory}/binaries/xmount \
        "/" "${test_directory}/xmount"
    build_compile_qemu_xmount ${dnbd3_rootfs_directory}/binaries/qemu-xmount \
        "${test_directory}/xmount"
    cp ${dnbd3_rootfs_directory}/binaries/qemu-xmount/libxmount_input_qemu.so \
        "${test_directory}/xmount/lib/xmount/"
fi

pushd "$log_directory"

dd_test() {
    local device="$1"
    size_in_megabyte="$2"
    dd if="$device" of=/dev/null \
        bs="$size_in_megabyte"M count=1\
        iflag=direct \
        2>&1 | grep bytes
}
fio_test() {
    local device="$1"
    shift
    local name="$1"
    shift
    fio --readonly --name=job --direct=1 --write_bw_log="$name" \
       --runtime=$test_time --filename="$device" "$@"
}
test_device() {
    local device="$1"
    local name="$2"
    echo

    #echo "-------------- $2 read test (dd)"
    #dd_test "$device" 1000

    echo "-------------- $2 read test (fio seq read)"
    fio_test "$device" "$name.seq" --rw=read --ioengine=sync

    echo "-------------- $2 read test (fio random read)"
    fio_test "$device" "${name}.rand" --rw=randread --ioengine=sync

    echo "-------------- $2 read test (fio seq read libaio)"
    fio_test "$device" "${name}.seq_libaio" --rw=read --ioengine=libaio

    echo "-------------- $2 read test (fio random read libaio)"
    fio_test "$device" "${name}.rand_libaio" --rw=randread --ioengine=libaio

}
test_qemu() {
    # qemu-nbd test (no cache)
    modprobe nbd max_part=16
    qemu_nbd_version="$( qemu-nbd --version \
        | grep 'version' | cut --delimiter ' ' --field 3 )"
    qemu-nbd --connect=/dev/nbd0 --read-only --persistent --nocache "$image"
    #ln -s /dev/nbd0 "$image" # device as file (for dnbd3)
    test_device "/dev/nbd0" "qemu-nbd $qemu_nbd_version (nocache)"
    # qemu-nbd teardown
    qemu-nbd -d /dev/nbd0 >/dev/null # disconnect

    # qemu-nbd test
    qemu-nbd --connect=/dev/nbd0 --read-only --persistent "$image"
    test_device "/dev/nbd0" "qemu-nbd $qemu_nbd_version"
    # qemu-nbd teardown
    qemu-nbd -d /dev/nbd0 >/dev/null # disconnect
}

test_xmount() {
    #xmount test
    xmount_version="$( ${test_directory}/xmount/bin/xmount --info \
        | grep 'xmount v' | cut --delimiter ' ' --field 2 )"
    ${test_directory}/xmount/bin/xmount --in qemu "$image" \
        --out raw "${mountpoint_xmount}" \

    loop_device="$(losetup -f)"
    losetup "$loop_device" "${mountpoint_xmount}"/*.dd --partscan
    test_device "$loop_device" "xmount ${xmount_version}"

    # xmount teardown
    losetup -d "$loop_device"
    umount "$mountpoint_xmount"

    #xmount test with writeback
    ${test_directory}/xmount/bin/xmount --in qemu "$image" \
        --inopts bdrv_cache=writeback \
        --out raw "${mountpoint_xmount}" \

    loop_device="$(losetup -f)"
    losetup "$loop_device" "${mountpoint_xmount}"/*.dd --partscan
    test_device "$loop_device" "xmount ${xmount_version} with writeback"

    # xmount teardown
    losetup -d "$loop_device"
    umount "$mountpoint_xmount"
}

test_qemu
test_xmount
chown $(who | awk '{print $1}') *.log
# bw logs
fio2gnuplot --gnuplot -p '*seq_bw*.log'
fio2gnuplot --gnuplot -p '*rand_bw*.log'
fio2gnuplot --gnuplot -p '*seq_libaio_bw*.log'
fio2gnuplot --gnuplot -p '*rand_libaio_bw*.log'
chown $(who | awk '{print $1}') *.png
rm *2Dsmooth*
rm *2Dtrend*
rm '$3.png'
popd