Android上的命令内存相关

targetProcess=com.example

timeStr=`date -d today +"%Y%m%d%H%M%S"`
fileName="meminfo"_$timeStr".txt"

echo timeStr is:===== $timeStr
echo begin dump procrank to $fileName
echo $targetProcess
##dump procrank to file
# adb shell procrank >> $fileName
adb shell ps > phoneps.txt
#因为adb shell ps出来后没行后有0D0A回车,故转为unix格式
dos2unix phoneps.txt
#get process id and
cat phoneps.txt | while read line
do
	pid=`echo $line | cut -d " " -f 2`
	ppid=`echo $line | cut -d " " -f 3`
	name=`echo $line | cut -d " " -f 9`
	
	if [ "$name" == "$targetProcess" ]; then
		echo $line >> $fileName
		echo -e "\n\n----------------------prorank meminfo $targetProcess-------------------------" >> $fileName
		echo -e " PID      Vss           Rss                Pss          Uss        cmdline" >> $fileName
		adb shell procrank |grep $pid >> $fileName
		echo -e "\n\n----------------------meminfo of $targetProcess-------------------------" >> $fileName
		adb shell dumpsys meminfo $targetProcess >> $fileName
		echo -e "\n\n------------------------showmap of $targetProcess:--------------------"  >> $fileName
		adb shell showmap $pid >> $fileName
		echo -e "\n\n--------------------------showmap of ppid $ppid:------------------------------" >> $fileName
		adb shell showmap $ppid >> $fileName
		echo -e "\n\n---------------------smaps of $targetProcess:---------------------------"  >> $fileName
		adb shell cat /proc/$pid/smaps >> $fileName
	fi
done

相关推荐