Guest User

Untitled

a guest
Oct 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. help() {
  4. echo "$0 -p <packageName> [-v]"
  5. }
  6.  
  7. SHORT_PARAM="vp:"
  8. LONG_PARAM="pkg"
  9.  
  10. GETOPT="getopt"
  11.  
  12. FILE_FDS="/tmp/fds"
  13. FILE_LAST_FDS="/tmp/last_fds"
  14.  
  15. if [ "$SHORT_PARAM" ] ; then GETOPT="$GETOPT -o $SHORT_PARAM" ; fi
  16. if [ "$LONG_PARAM" ] ; then GETOPT="$GETOPT --long $LONG_PARAM" ; fi
  17.  
  18. NEW_PARAMS=`$GETOPT -n $0 -- "$@"`
  19.  
  20. eval set -- "$NEW_PARAMS"
  21.  
  22. verbose=false
  23. while true ; do
  24. case $1 in
  25. -v) verbose=true ; shift ;;
  26. -p|--pkg) packageName="$2"; shift 2;;
  27. --) shift ; break ;;
  28. esac
  29. done
  30.  
  31. if [ ! "$packageName" ] ; then echo "Usage: $0 -p <packageName>"; exit 1; fi
  32.  
  33. pid=`adb shell ps -ef|grep com.android.browser$|sed 's/[[:space:]]\+/ /g'|cut -d' ' -f2`
  34.  
  35. if [ ! "$pid" ] ; then echo "pid of $packageName is not exists"; exit 1; fi
  36.  
  37. if [ -f "${FILE_FDS}_$pid" ] ; then mv "${FILE_FDS}_$pid" "${FILE_LAST_FDS}_$pid"; fi
  38.  
  39. adb shell ls -l /proc/$pid/fd |cut -d' ' -f1,2,3,4,5,8,9,10 | sort > "${FILE_FDS}_$pid"
  40.  
  41. if [ ! -f "${FILE_LAST_FDS}_$pid" ] ; then echo "Fds file init finished."; exit 0; fi
  42.  
  43. newFds=`comm -13 "${FILE_LAST_FDS}_$pid" "${FILE_FDS}_$pid"`
  44. freedFds=`comm -23 "${FILE_LAST_FDS}_$pid" "${FILE_FDS}_$pid"`
  45.  
  46. if [ "$newFds" ] ; then newCount=`echo "$newFds" |wc -l`; else newCount="0" ; fi
  47. if [ "$freedFds" ] ; then freedCount=`echo "$freedFds"|wc -l`; else freedCount="0" ; fi
  48. totalCount=`wc -l ${FILE_FDS}_$pid |cut -d' ' -f1`
  49.  
  50. if $verbose ; then
  51. if [ "$newFds" ] ; then
  52. echo "New fds: $newCount"
  53. echo "$newFds"
  54. echo
  55. fi
  56.  
  57. if [ "$freedFds" ] ; then
  58. echo "Freed fds: $freedCount"
  59. echo "$freedFds"
  60. echo
  61. fi
  62. fi
  63.  
  64. echo "total: $totalCount"
  65. echo "New fds: $newCount"
  66. echo "Freed fds: $freedCount"
Add Comment
Please, Sign In to add comment