#!/bin/bash # # fsperf - Performance measurement of filesystems # # Copyright Mathias Kettner 2004 # # You can use this software under the terms of the GNU # General Public License Version 2 or later. Please refer # to http://mathias-kettner.de/diagnosebuch_downloads.html. # function pt_mkdir { time for i in 0 1 2 3 4 5 6 7 8 9 do mkdir -p $i-{a,b,c}{,/}{1,2,3}{,/}{u,v,w}{,/}{g,h,i}{x,y,z}{3,4,5} done } function pt_find { time find > /dev/null } function pt_touch { time for i in 0 1 2 3 4 5 6 7 8 9 do touch $i-{a,b,c}{,/}{1,2,3}{,/}{u,v,w}{,/}{g,h,i}{x,y,z}{3,4,5}/HIRNI done } function pt_write1gb { time dd if=/dev/zero of=1gb bs=1M count=1024 } function pt_read1gb { time dd if=1gb of=/dev/null bs=1M count=1024 } function performance_test { for pt in mkdir find touch write1gb read1gb do echo -n $pt:' ' TIME="$(pt_$pt 2>&1 | grep real | sed 's/^real[[:space:]]*//')" printf "\033[1m%9s\033[m " "$TIME" done } function usage { cat <&2 Usage: fsperf BLOCK-DEVICE WARNUNG: BLOCK-DEVICE will be deleted! EOF exit 5 } [ "$#" == 1 ] || usage DEVICE="$1" [ -b "$DEVICE" ] || { echo "$DEVICE is not a block special device" >&2 exit 5 } mount | grep -q "^$DEVICE[[:space:]]" && { echo "$DEVICE is already mounted! Please choose another device." >&2 exit 5 } echo -n "Proceed using $DEVICE? All data will be lost! [N/y] " read SURE [ "$SURE" = y -o "$SURE" = Y ] || { echo "Cancelled." >&2 exit 5 } MOUNTPOINT=/tmp/fsperf.mp mkdir -p $MOUNTPOINT || { echo "Cannot create mount point $MOUNTPOINT" >&2 exit 5 } trap "cd / ; umount $MOUNTPOINT ; echo Killed. ; exit 9" 2 3 15 for FS in ext2 ext3 reiserfs jfs ext3 ext2 jfs reiserfs jfs do printf "%-10s " $FS yes | mkfs -t $FS $DEVICE > /dev/null 2>&1 || { echo " - failed" ; continue; } mount -t $FS $DEVICE $MOUNTPOINT cd $MOUNTPOINT performance_test cd - umount $MOUNTPOINT echo done