4
0

mem_leak_test.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-cmapctl -s usr.angus u32 456
  27. corosync-cmapctl -s usr.angus u32 4123
  28. corosync-cmapctl -d usr.angus
  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 u64 $COUNT >> $temp_file
  37. let COUNT="$COUNT+1"
  38. done
  39. corosync-cmapctl -p $temp_file
  40. corosync-cmapctl -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. corosync-cmap -h >/dev/null
  57. corosync-cfgtool -h >/dev/null
  58. corosync-quorumtool -h >/dev/null
  59. BEFORE=$(get_mem $TYPE)
  60. corosync-cfgtool -a >/dev/null
  61. corosync-quorumtool -s >/dev/null
  62. corosync-quorumtool -l >/dev/null
  63. find /usr/bin | sed "s|\.|_|g" | sed "s|/|.|g" | while read l
  64. do
  65. corosync-cmapctl -s $l u32 $COUNT
  66. let COUNT="$COUNT+1"
  67. done
  68. corosync-cmapctl -D usr
  69. AFTER=$(get_mem $TYPE)
  70. let DIFF="$AFTER - $BEFORE"
  71. echo $DIFF
  72. exit 0
  73. }
  74. # Note that we use `"$@"' to let each command-line parameter expand to a
  75. # separate word. The quotes around `$@' are essential!
  76. # We need TEMP as the `eval set --' would nuke the return value of getopt.
  77. TEMP=`getopt -o u12 --long help,object,session \
  78. -n '$0' -- "$@"`
  79. if [ $? != 0 ] ; then echo "Incorrect arguments..." >&2 ; _usage_ ; exit 1 ; fi
  80. # Note the quotes around `$TEMP': they are essential!
  81. eval set -- "$TEMP"
  82. while true ; do
  83. case "$1" in
  84. -u|--help) _usage_ ;;
  85. -1|--object) _object_test_ ;;
  86. -2|--session) _session_test_ ;;
  87. --) shift ; break ;;
  88. *) echo "Internal error!" ; exit 1 ;;
  89. esac
  90. done
  91. echo "Remaining arguments:"
  92. for arg do echo '--> '"\`$arg'" ; done