12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. . <(ffoom init)
  3. FFOO_INI_PATH="__FFOO_INI_PATH__"
  4. ffoo import core
  5. ffoo import recon
  6. FFOO_DEBUG=false
  7. interval=2
  8. report_limits() {
  9. echo "ulimit -m:$(ulimit -m)"
  10. echo "ulimit -Sm:$(ulimit -Sm)"
  11. echo "ulimit -Hm:$(ulimit -Hm)"
  12. echo "ulimit -n:$(ulimit -n)"
  13. echo "ulimit -Sn:$(ulimit -Sn)"
  14. echo "ulimit -Hn:$(ulimit -Hn)"
  15. }
  16. report_on_pids() {
  17. local pid
  18. for pid in "$@";
  19. do
  20. echo "$pid:name:$(ps -p $pid -o comm=)"
  21. echo "$pid:rss:$(ps -p $pid -o rss=)"
  22. echo "$pid:files:$(lsof -p $pid | wc -l)"
  23. done
  24. }
  25. usage() {
  26. usage_is "[-i INTERVAL] [-d] -p PID[,PID]..." \
  27. "[-i INTERVAL] [-d] -r REGEX[,REGEX]..."
  28. }
  29. regexes=""
  30. pids=""
  31. while true;
  32. do
  33. case $1 in
  34. -i|--interval)
  35. interval=$2
  36. shift 2
  37. ;;
  38. -d|--debug)
  39. FFOO_DEBUG=true
  40. shift 1
  41. ;;
  42. -r|--regexes)
  43. regexes=$2
  44. shift 2
  45. ;;
  46. -p|--pids)
  47. pids=$2
  48. shift 2
  49. ;;
  50. "")
  51. if test -z "$regexes" && test -z "$pids";
  52. then usage;
  53. else break;
  54. fi
  55. ;;
  56. *)
  57. usage
  58. ;;
  59. esac
  60. done
  61. pids=$(tr "," " " <<<"$pids")
  62. regexes=$(tr "," " " <<<"$regexes")
  63. report_limits
  64. while true;
  65. do
  66. # append PIDS from regexes to pids from command line
  67. current_pids="$pids $(pids_matching $regexes)"
  68. debug -v current_pids
  69. report_on_pids $current_pids
  70. sleep $interval
  71. done