test-fragmentation.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. dev="$1"
  3. [[ $dev = "" ]] && dev=/dev/sdb2
  4. rev_need=r666
  5. log="${0##*/}.log"
  6. max=16
  7. fragid=PHT000
  8. firstid=PHT001
  9. midid="$(printf "PHT%03u" $((max|1)))"
  10. lastid="$(printf "PHT%03u" $((2*max-1)))"
  11. testlist="$fragid $firstid $midid $lastid"
  12. if [[ $(wwt version | awk '{print $6}') < $rev_need ]]
  13. then
  14. printf '\n*** %s: Need at least wwt revision %s\n\n' "${0##*/}" "$rev_need" >&2
  15. exit 1
  16. fi
  17. if ! wwt find -q -p "$dev"
  18. then
  19. printf '\n*** %s: Not a WBFS: %s\n\n' "${0##*/}" "$dev" >&2
  20. exit 1
  21. fi
  22. {
  23. printf '\n---------- INIT ----------\n\n'
  24. wwt init $dev -qf
  25. rmlist=""
  26. for ((i=0;i<$max;i++))
  27. do
  28. wwt -p $dev -q phantom 256M 4G
  29. rmlist="$rmlist $(printf "PHT%03u" $((2*i)))"
  30. done
  31. wwt -p $dev -q rm $rmlist
  32. wwt -p $dev -q phantom 4G
  33. #wwt ll $dev --sort=none
  34. wwt -p $dev dump -lll | sed '0,/WBFS Memory Map/ d' | grep -iv inode
  35. printf '\n---------- EXTRACT ----------\n\n'
  36. for (( i=0; i<10; i++ ))
  37. do
  38. for id in $testlist
  39. do
  40. echo -n "extract $id ... "
  41. start=$(date +%s)
  42. wwt -p $dev -q extract $id=/dev/null --overwrite
  43. end=$(date +%s)
  44. printf "%3u sec\n" $((end-start))
  45. done
  46. echo
  47. done
  48. printf '\n---------- SUM ----------\n\n'
  49. } | tee $log
  50. awk='
  51. $1=="extract" && $5=="sec" { n[$2]++; s[$2]+=$4 }
  52. END { for ( i in s )
  53. printf("%s: %5u sec / %2u == %3u sec\n",
  54. i, s[i], n[i], s[i]/n[i] ); }
  55. '
  56. awk "$awk" $log | sort -n +4 | tee $log.tmp
  57. cat $log.tmp >>$log
  58. rm -f $log.tmp