mem_leak_test.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 -w usr.angus=4123
  29. corosync-objctl -d usr
  30. BEFORE=$(get_mem $TYPE)
  31. # this loop is just to ignore the first iteration
  32. for f in /usr/share/man /usr/lib /usr/bin /usr/local ;
  33. do
  34. rm -f $temp_file
  35. find $f | sed "s|\.|_|g" | sed "s|/|.|g" | while read l
  36. do
  37. echo $l.count=$count >> $temp_file
  38. let COUNT="$COUNT+1"
  39. done
  40. corosync-objctl -p $temp_file
  41. corosync-objctl -d usr
  42. done
  43. AFTER=$(get_mem $TYPE)
  44. let DIFF="$AFTER - $BEFORE"
  45. rm -f $temp_file
  46. #echo $f diff $TYPE $DIFF
  47. echo $DIFF
  48. exit 0
  49. }
  50. #
  51. # run the corosync tools to cause IPC sessions to created/destroyed
  52. #
  53. _session_test_()
  54. {
  55. echo _session_test_
  56. COUNT=1
  57. corosync-objctl -h >/dev/null
  58. corosync-cfgtool -h >/dev/null
  59. corosync-quorumtool -h >/dev/null
  60. BEFORE=$(get_mem $TYPE)
  61. corosync-cfgtool -a >/dev/null
  62. corosync-quorumtool -s >/dev/null
  63. corosync-quorumtool -l >/dev/null
  64. find /usr/bin | sed "s|\.|_|g" | sed "s|/|.|g" | while read l
  65. do
  66. corosync-objctl -c $l
  67. corosync-objctl -w $l.value=$COUNT
  68. let COUNT="$COUNT+1"
  69. done
  70. corosync-objctl -d usr
  71. AFTER=$(get_mem $TYPE)
  72. let DIFF="$AFTER - $BEFORE"
  73. echo $DIFF
  74. exit 0
  75. }
  76. # Note that we use `"$@"' to let each command-line parameter expand to a
  77. # separate word. The quotes around `$@' are essential!
  78. # We need TEMP as the `eval set --' would nuke the return value of getopt.
  79. TEMP=`getopt -o u12 --long help,object,session \
  80. -n '$0' -- "$@"`
  81. if [ $? != 0 ] ; then echo "Incorrect arguments..." >&2 ; _usage_ ; exit 1 ; fi
  82. # Note the quotes around `$TEMP': they are essential!
  83. eval set -- "$TEMP"
  84. while true ; do
  85. case "$1" in
  86. -u|--help) _usage_ ;;
  87. -1|--object) _object_test_ ;;
  88. -2|--session) _session_test_ ;;
  89. --) shift ; break ;;
  90. *) echo "Internal error!" ; exit 1 ;;
  91. esac
  92. done
  93. echo "Remaining arguments:"
  94. for arg do echo '--> '"\`$arg'" ; done