mem_leak_test.sh 2.1 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-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. # load and unload a service a bunch of times
  51. #
  52. _service_test_()
  53. {
  54. echo _service_test_
  55. exit 0
  56. }
  57. #
  58. # run the corosync tools to cause IPC sessions to created/destroyed
  59. #
  60. _session_test_()
  61. {
  62. echo _session_test_
  63. COUNT=1
  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. exit 0
  72. }
  73. # Note that we use `"$@"' to let each command-line parameter expand to a
  74. # separate word. The quotes around `$@' are essential!
  75. # We need TEMP as the `eval set --' would nuke the return value of getopt.
  76. TEMP=`getopt -o u123 --long help,object,session,service \
  77. -n '$0' -- "$@"`
  78. if [ $? != 0 ] ; then echo "Incorrect arguments..." >&2 ; _usage_ ; exit 1 ; fi
  79. # Note the quotes around `$TEMP': they are essential!
  80. eval set -- "$TEMP"
  81. while true ; do
  82. case "$1" in
  83. -u|--help) _usage_ ;;
  84. -1|--object) _object_test_ ;;
  85. -2|--session) _session_test_ ;;
  86. -3|--service) _service_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