Created
October 28, 2016 20:39
-
-
Save jhansche/322965fa3c3a6179114bc3ac8e4337ec to your computer and use it in GitHub Desktop.
Simple script to monitor the number open file descriptors for an Android application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: ./watch-fds.sh <application_id> [delay_secs = 5] | |
APP_ID=${1:?missing application id} | |
DELAY=$(( ${2:-5} )) | |
DEVICE_LIMIT=$(( $(adb shell ulimit -n) )) | |
WARN_THRESHOLD=$(( ${DEVICE_LIMIT} / 3 )) | |
echo "Will warn at ${WARN_THRESHOLD}" | |
APP_PID=$(( $(adb shell ps | grep "${APP_ID}" | awk '{print $2}') )) | |
echo "Watching application ${APP_ID} <${APP_PID}>. Press CTRL+C to stop." | |
fds="" | |
high_mark=0 | |
while [ true ]; do | |
app_proc=$(( $(adb shell ps ${APP_PID} | grep -c ${APP_ID}) )) | |
if [ ${app_proc} -ne 1 ]; then | |
echo "Process ${APP_ID} <${APP_PID}> has died." | |
echo "Last list of File Descriptors:" | |
echo "${fds}" | |
exit | |
fi | |
fds="$(adb shell run-as ${APP_ID} ls -l /proc/${APP_PID}/fd 2>/dev/null)" | |
fd_count=$(( $(wc -l <<< "${fds}") )) | |
echo ${fd_count} | |
if [ ${fd_count} -ge ${WARN_THRESHOLD} -a ${fd_count} -gt ${high_mark} ]; then | |
echo " *** *** *** " | |
echo "Warning: FD count > warning threshold: ${fd_count}" | |
# echo "Current File Descriptors:" | |
# echo "${fds}" | |
echo " *** *** *** " | |
echo "" | |
# then ratchet the highwater mark | |
high_mark=$(( ${fd_count} )) | |
fi | |
sleep ${DELAY} | |
done |
I don't even remember publishing this 😆
can you to this for an app running on windows
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/kyze8439690/09f66f1856c2ce9e07a4ea9615ba1baf/revisions#diff-82cdeaf5fccea84ebdca4b23da20d5473e5e1dc129af39ce87255f3f02a94c59
Handle situation when you app is a multi-process application.