admin管理员组

文章数量:1533026

2023年12月28日发(作者:)

local ssd_log=$1 if [ -f "${ssd_log}" ] then sed -i 's/=/,/g' ${ssd_log} sed -i 's/KBs/,KBs/' ${ssd_log} local log_bw=/tmp/bw_$ local bw_sum=0 local bw_avg=0 { awk -F ',' '{print $4}' ${ssd_log} |awk -F '.' '{print $1}' } > ${log_bw} local count_line=$(wc -l ${log_bw} |awk '{print $1}') while read line do let bw_sum=bw_sum+$line done < ${log_bw} let bw_avg=$bw_sum/$count_line local log_iops=/tmp/iops_$ local iops_sum=0 local iops_avg=0 { awk -F ',' '{print $7}' ${ssd_log} } > ${log_iops} local count_line=$(wc -l ${log_iops} |awk '{print $1}') while read line1 do let iops_sum=iops_sum+$line1 done < ${log_iops} let iops_avg=$iops_sum/$count_line echo "$1,bw_avg,$bw_avg KB/S,iops_avg,$iops_avg" fi}function result_ssd(){ { result_ssd_template "${dir_path}/ssd_read_$" "read" result_ssd_template "${dir_path}/ssd_randread_$" "randread" result_ssd_template "${dir_path}/ssd_write_$" "write" result_ssd_template "${dir_path}/ssd_randwrite_$" "randwrite" echo } |tee -a ${dir_path}/ssd_ cat ${dir_path}/ssd_ >> ${source_path}/log/ssd_}function ssd_size_setting(){ if [ "${mem_enable}" -eq 1 ] then local bigfile=${ssd_path}/bigfile [ -f "${bigfile}" ] && rm ${bigfile} local mem_total=$(jq -r '.para___total' ) local mem_threshold=$(jq -r '.para___proportion' ) local mem_actual_per=$(df /dev/nvme0n1 |awk '{print $5}'|tail -1) local mem_actual=0.$(echo "$mem_actual_per" |awk -F "%" '{print $1}') local mem_compare=$(echo "${mem_actual} < ${mem_threshold}" |bc) if [ "${mem_compare}" -eq 1 ] then local mem_diff=$(echo "${mem_threshold} - ${mem_actual}" |bc) local mem_diff_size=$(echo "${mem_total} * ${mem_diff}" |bc) fallocate -l ${mem_diff_size}G ${ssd_path}/bigfile fi fi mem_actual_use=$(df /dev/nvme0n1 |awk '{print $5}'|tail -1)}function ssd_depend_package()

{ which bc > /dev/null if [ "$?" -ne 0 ] then local platform=$(uname -m) if [ "${platform}" == "armv7l" ] then dpkg -i ${source_path}/lib/deb_package/bb_bc/bc_1.06.95-9build1_

fi fi

}function ssd_config_check(){ # ssd type and ssd mount path detection if [ -b "${ssd_type}" ] then local mounted_path=$(df -h |grep "${ssd_type}" |awk '{print $6}') if [ -d "${mounted_path}" ] then umount -l ${mounted_path} fi else printf "${source_path}/ "para__type" error or not existn" exit 1 fi}function ssd_cpu_stress(){ # cpu N core stress if [ "${cpu_enable}" -eq 1 ] then local cpu_time_num=$(jq -r ".para___num" ${source_path}/) local cpu_time_unit=$(jq -r ".para___unit" ${source_path}/) stress-ng -c ${cpu_num} -t ${cpu_time_num}${cpu_time_unit} fi}function ssd_cpu_stress_ctrlc(){ local pid_stress=$(pgrep stress-ng) local pid_num=$(echo "${pid_stress}" |wc -l) if [ "${pid_num}" -gt 0 ] then local platform=$(uname -m) if [ "${platform}" == "armv7l" ] then for i in $(echo "$pid_stress") do kill -9 $i done elif [ "${platform}" == "aarch64" ] then sudo killall stress-ng &> ${c_d_null} fi fi printf "$$n" |xargs kill -9}function ssd_test_condition(){ cat <<-eof [$(date "+%T")] platform : $(uname -m) [$(date "+%T")] ssd type : ${ssd_type} [$(date "+%T")] cpu enable : ${cpu_enable} [$(date "+%T")] cpu num : ${cpu_num}00% [$(date "+%T")] mem enable : ${mem_enable}

[$(date "+%T")] mem use : ${mem_actual_use} [$(date "+%T")] fio bs : ${fio_bs}KB [$(date "+%T")] fio direct : ${fio_direct} [$(date "+%T")] fio iodepth : ${fio_iodepth} [$(date "+%T")] fio ioengine: ${fio_ioengine} [$(date "+%T")] fio runtime : ${fio_runtime} [$(date "+%T")] fio size : ${fio_size} [$(date "+%T")] test temp : ${ssd_temp} eof sleep 2}function ssd_png_set(){ which gnuplot > /dev/null if [ "$?" -eq 0 ] then echo " set terminal png size 1280,720 set output "${dir_path}/ssd_speed_" set border lc rgb "orange" set multiplot layout 1,2 set grid x,y lc rgb "orange" set datafile sep ',' set key box reverse set xlabel "${fio_bs}KB" font ",15" set xrange [-1:$ssd_cycle] set ytics $ssd_png_ytics

set origin 0,0 set title "FIO Sequential ($ssd_type)n(Temp: $ssd_temp; CPU: $cpu_enable-$cpu_num; Disk-Use: $mem_actual_use)" font ",16" set ylabel "KB/s" font ",15" plot "$dir_path/ssd_read_$" u 4 smooth csplines w l lc 1 lw 2 t "Read", "$dir_path/ssd_write_$" u 4 smooth csplines w l lc 6 lw 2 t "Write"

set origin 0.5,0 set title "FIO Random ($ssd_type)n(Temp: $ssd_temp; CPU: $cpu_enable-$cpu_num; Disk-Use: $mem_actual_use)" font ",16" set ylabel "IOps" font ",15" plot "$dir_path/ssd_randread_$" u 7 smooth csplines w l lc 1 lw 2 t "Read", "$dir_path/ssd_randwrite_$" u 7 smooth csplines w l lc 6 lw 2 t "Write" " |gnuplot fi}function ssd_stress_excute(){ for ((i=1;i<=${ssd_cycle};i++)) do ssd_function ${fio_bs} && echo done result_ssd ${fio_bs} ssd_png_set ${fio_bs}}function main(){ local source_path=$(pwd) local c_d_null=/dev/null local c_d_zero=/dev/zero local cpu_enable=$(jq -r ".para___enable" ${source_path}/) local cpu_num=$(jq -r ".para___num" ${source_path}/) local fio_bs=$(jq -r ".para___bs" ${source_path}/) local fio_direct=$(jq -r ".para___direct" ${source_path}/) local fio_iodepth=$(jq -r ".para___iodepth" ${source_path}/) local fio_ioengine=$(jq -r ".para___ioengine" ${source_path}/) local fio_runtime=$(jq -r ".para___runtime" ${source_path}/) local fio_size=$(jq -r ".para___size" ${source_path}/) local mem_enable=$(jq -r ".para___enable" ${source_path}/) local ssd_cycle=$(jq -r ".para__cycle" ${source_path}/)

local ssd_path=$(jq -r ".para__mounted" ${source_path}/) local ssd_temp=$(jq -r ".para__temp" ${source_path}/) local ssd_type=$(jq -r ".para__type" ${source_path}/) local dir_date=$(date "+%Y-%m-%d-%H-%M-%S") local dir_path=${source_path}/log/ssd_speed_${fio_bs}kb_cpu_${cpu_enable}_${cpu_num}00/${dir_date} trap "ssd_cpu_stress_ctrlc" HUP INT QUIT trap "ssd_cpu_stress_ctrlc" EXIT [ ! -d ${dir_path} ] && mkdir -p ${dir_path} ssd_config_check ssd_depend_package ssd_size_setting ssd_test_condition ssd_cpu_stress & ssd_stress_excute}main

本文标签: 读写硬盘测试性能脚本