mem_leak_test.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. _usage_()
  3. {
  4. echo bla bla
  5. exit 0
  6. }
  7. get_mem()
  8. {
  9. if [ -z "$1" ]
  10. then
  11. type=Data
  12. else
  13. type=$1
  14. fi
  15. MEM=$(cat /proc/$(pidof corosync)/status | grep Vm$type | sed "s/Vm$type:\(.*\) kB/\1/")
  16. echo $MEM
  17. }
  18. #
  19. # create and destroy a lot of objects
  20. #
  21. _object_test_()
  22. {
  23. TYPE=RSS
  24. temp_file=/tmp/object.txt
  25. COUNT=1
  26. corosync-objctl -c usr
  27. corosync-objctl -w usr.angus=456
  28. corosync-objctl -d usr
  29. BEFORE=$(get_mem $TYPE)
  30. # this loop is just to ignore the first iteration
  31. for f in /usr/share/man /usr/lib /usr/bin /usr/local ;
  32. do
  33. rm -f $temp_file
  34. find $f | sed "s|\.|_|g" | sed "s|/|.|g" | while read l
  35. do
  36. echo $l.count=$count >> $temp_file
  37. let COUNT="$COUNT+1"
  38. done
  39. corosync-objctl -p $temp_file
  40. corosync-objctl -d usr
  41. done
  42. AFTER=$(get_mem $TYPE)
  43. let DIFF="$AFTER - $BEFORE"
  44. rm -f $temp_file
  45. #echo $f diff $TYPE $DIFF
  46. echo $DIFF
  47. exit 0
  48. }
  49. #
  50. # run the corosync tools to cause IPC sessions to created/destroyed
  51. #
  52. _session_test_()
  53. {
  54. echo _session_test_
  55. COUNT=1
  56. find /usr/bin | sed "s|\.|_|g" | sed "s|/|.|g" | while read l
  57. do
  58. corosync-objctl -c $l
  59. corosync-objctl -w $l.value=$COUNT
  60. let COUNT="$COUNT+1"
  61. done
  62. corosync-objctl -d usr
  63. exit 0
  64. }
  65. # Note that we use `"$@"' to let each command-line parameter expand to a
  66. # separate word. The quotes around `$@' are essential!
  67. # We need TEMP as the `eval set --' would nuke the return value of getopt.
  68. TEMP=`getopt -o u12 --long help,object,session \
  69. -n '$0' -- "$@"`
  70. if [ $? != 0 ] ; then echo "Incorrect arguments..." >&2 ; _usage_ ; exit 1 ; fi
  71. # Note the quotes around `$TEMP': they are essential!
  72. eval set -- "$TEMP"
  73. while true ; do
  74. case "$1" in
  75. -u|--help) _usage_ ;;
  76. -1|--object) _object_test_ ;;
  77. -2|--session) _session_test_ ;;
  78. --) shift ; break ;;
  79. *) echo "Internal error!" ; exit 1 ;;
  80. esac
  81. done
  82. echo "Remaining arguments:"
  83. for arg do echo '--> '"\`$arg'" ; done