Compare commits
2 Commits
f9d461142a
...
bad8a7ca44
| Author | SHA1 | Date |
|---|---|---|
|
|
bad8a7ca44 | |
|
|
3c7abdcef8 |
|
|
@ -1,63 +0,0 @@
|
|||
app=$1
|
||||
round=$2
|
||||
dir=$3
|
||||
|
||||
# iqiyi com.qiyi.video/com.qiyi.video.WelcomeActivity
|
||||
|
||||
prev_alloc=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_alloc)
|
||||
prev_alloc_fallback=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_fallback)
|
||||
|
||||
adb shell "simpleperf stat -e dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,page-faults,raw-stall-backend-mem --app $app --duration 3 -o /data/local/tmp/simpleperf-"$app"-"$round".txt" &
|
||||
adb shell "perfetto -c /data/misc/perfetto-configs/perfconf.txt --txt -o /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace" &
|
||||
|
||||
perfetto_pid=$!
|
||||
echo perfetto_pid is $perfetto_pid
|
||||
|
||||
# 启动应用
|
||||
sleep 1
|
||||
|
||||
if [ "$app" == "com.qiyi.video" ]; then
|
||||
activity="com.qiyi.video/com.qiyi.video.WelcomeActivity"
|
||||
elif [ "$app" == "com.netease.cloudmusic" ]; then
|
||||
activity="com.netease.cloudmusic/com.netease.cloudmusic.activity.IconChangeDefaultAlias"
|
||||
else
|
||||
activity=$(adb shell dumpsys package $app | grep -A 1 -w "android.intent.action.MAIN:" | head -n 2 | tail -n 1 | awk '{print $2}')
|
||||
fi
|
||||
|
||||
if [ -z "$activity" ]; then
|
||||
continue
|
||||
fi
|
||||
echo "starting $activity"
|
||||
adb shell am start -n $activity
|
||||
|
||||
# 睡眠15s等待perfetto退出
|
||||
sleep 12
|
||||
wait
|
||||
|
||||
# 后面的dumpsys meminfo也会分配大页
|
||||
# 所以先看分配大页数
|
||||
alloc=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_alloc)
|
||||
alloc_fallback=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_fallback)
|
||||
|
||||
adb shell "dumpsys meminfo --package $app" > $dir/meminfo-"$app"-"$round".txt
|
||||
|
||||
# 计算大页分配成功率
|
||||
inc_alloc=$((alloc-prev_alloc))
|
||||
inc_alloc_fallback=$((alloc_fallback-prev_alloc_fallback))
|
||||
inc_total=$((inc_alloc+inc_alloc_fallback))
|
||||
if [ $inc_total -ne 0 ]; then
|
||||
inc_ratio=$(echo "scale=4; $inc_alloc / $inc_total" | bc)
|
||||
else
|
||||
inc_ratio=1
|
||||
fi
|
||||
|
||||
echo -e "$inc_ratio\t$inc_total" > $dir/ratio-"$app"-"$round".txt
|
||||
|
||||
sleep 3
|
||||
|
||||
adb pull /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace $dir/
|
||||
adb pull /data/local/tmp/simpleperf-"$app"-"$round".txt $dir/
|
||||
|
||||
adb shell "rm /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace"
|
||||
adb shell "rm /data/local/tmp/simpleperf-"$app"-"$round".txt"
|
||||
|
||||
101
run.sh
101
run.sh
|
|
@ -9,7 +9,9 @@ fi
|
|||
|
||||
dir=$(/usr/bin/date +%Y-%m%d-%H%M)
|
||||
mkdir $dir
|
||||
mkdir $dir/mminfo
|
||||
mkdir $dir/system_mem
|
||||
mkdir $dir/traces
|
||||
mkdir $dir/meminfo
|
||||
echo "round app start_type start_time inc_ratio inc_total rss pss pagefaults itlbmiss dtlbmiss cpustall" > $dir/result
|
||||
|
||||
for round in $(seq 1 2); do
|
||||
|
|
@ -17,28 +19,73 @@ for round in $(seq 1 2); do
|
|||
sleep 3
|
||||
|
||||
# 抓内存相关信息
|
||||
adb shell free -h > $dir/mminfo/before_free-$app-$round
|
||||
adb shell cat /proc/meminfo > $dir/mminfo/before_meminfo-$app-$round
|
||||
adb shell cat /proc/zoneinfo > $dir/mminfo/before_zoneinfo-$app-$round
|
||||
adb shell cat /proc/buddyinfo > $dir/mminfo/before_buddyinfo-$app-$round
|
||||
adb shell cat /proc/pagetypeinfo > $dir/mminfo/before_pagetypeinfo-$app-$round
|
||||
adb shell cat /proc/vmstat > $dir/mminfo/before_vmstat-$app-$round
|
||||
adb shell free -h > $dir/system_mem/before_free-$app-$round
|
||||
adb shell cat /proc/meminfo > $dir/system_mem/before_meminfo-$app-$round
|
||||
adb shell cat /proc/zoneinfo > $dir/system_mem/before_zoneinfo-$app-$round
|
||||
adb shell cat /proc/buddyinfo > $dir/system_mem/before_buddyinfo-$app-$round
|
||||
adb shell cat /proc/pagetypeinfo > $dir/system_mem/before_pagetypeinfo-$app-$round
|
||||
adb shell cat /proc/vmstat > $dir/system_mem/before_vmstat-$app-$round
|
||||
|
||||
./cold_start_app.sh $app $round $dir
|
||||
# 开始抓simpleperf和perfetto
|
||||
adb shell "simpleperf stat -e dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,page-faults,raw-stall-backend-mem --app $app --duration 3 -o /data/local/tmp/simpleperf-"$app"-"$round".txt" &
|
||||
adb shell "perfetto -c /data/misc/perfetto-configs/perfconf.txt --txt -o /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace" &
|
||||
perfetto_pid=$!
|
||||
|
||||
# 获取应用activity
|
||||
if [ "$app" == "com.qiyi.video" ]; then
|
||||
activity="com.qiyi.video/com.qiyi.video.WelcomeActivity"
|
||||
elif [ "$app" == "com.netease.cloudmusic" ]; then
|
||||
activity="com.netease.cloudmusic/com.netease.cloudmusic.activity.IconChangeDefaultAlias"
|
||||
else
|
||||
activity=$(adb shell dumpsys package $app | grep -A 1 -w "android.intent.action.MAIN:" | head -n 2 | tail -n 1 | awk '{print $2}')
|
||||
fi
|
||||
|
||||
if [ -z "$activity" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# 睡眠1s并准备抓大页数据
|
||||
sleep 1
|
||||
echo "starting $activity"
|
||||
|
||||
prev_alloc=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_alloc)
|
||||
prev_alloc_fallback=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_fallback)
|
||||
|
||||
# 启动应用
|
||||
adb shell am start -n $activity
|
||||
|
||||
# 睡眠15s并等待perfetto退出
|
||||
sleep 10
|
||||
wait
|
||||
|
||||
# 后面的dumpsys meminfo也会分配大页
|
||||
# 所以先看分配大页数
|
||||
alloc=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_alloc)
|
||||
alloc_fallback=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_fallback)
|
||||
|
||||
# dump内存占用
|
||||
adb shell "dumpsys meminfo --package $app" > $dir/meminfo/meminfo-"$app"-"$round".txt
|
||||
|
||||
# 抓启动后的内存信息
|
||||
adb shell free -h > $dir/system_mem/after_free-$app-$round
|
||||
adb shell cat /proc/meminfo > $dir/system_mem/after_meminfo-$app-$round
|
||||
adb shell cat /proc/zoneinfo > $dir/system_mem/after_zoneinfo-$app-$round
|
||||
adb shell cat /proc/buddyinfo > $dir/system_mem/after_buddyinfo-$app-$round
|
||||
adb shell cat /proc/pagetypeinfo > $dir/system_mem/after_pagetypeinfo-$app-$round
|
||||
adb shell cat /proc/vmstat > $dir/system_mem/after_vmstat-$app-$round
|
||||
|
||||
# 睡眠3s后拉simpleperf和perfetto数据
|
||||
sleep 3
|
||||
adb pull /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace $dir/traces
|
||||
adb pull /data/local/tmp/simpleperf-"$app"-"$round".txt $dir/
|
||||
adb shell "rm /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace"
|
||||
adb shell "rm /data/local/tmp/simpleperf-"$app"-"$round".txt"
|
||||
|
||||
# 回到桌面,应用退后台
|
||||
adb shell input keyevent 3
|
||||
|
||||
adb shell free -h > $dir/mminfo/after_free-$app-$round
|
||||
adb shell cat /proc/meminfo > $dir/mminfo/after_meminfo-$app-$round
|
||||
adb shell cat /proc/zoneinfo > $dir/mminfo/after_zoneinfo-$app-$round
|
||||
adb shell cat /proc/buddyinfo > $dir/mminfo/after_buddyinfo-$app-$round
|
||||
adb shell cat /proc/pagetypeinfo > $dir/mminfo/after_pagetypeinfo-$app-$round
|
||||
adb shell cat /proc/vmstat > $dir/mminfo/after_vmstat-$app-$round
|
||||
|
||||
# 计算启动耗时
|
||||
python3 handle_perfetto.py $dir/trace-"$app"-"$round".ptrace mm > tmp.txt
|
||||
|
||||
python3 handle_perfetto.py $dir/traces/trace-"$app"-"$round".ptrace mm > tmp.txt
|
||||
if [ $(cat tmp.txt | wc -l) -ne 1 ]; then
|
||||
start_time=0
|
||||
start_type="NONE"
|
||||
|
|
@ -51,25 +98,31 @@ for round in $(seq 1 2); do
|
|||
start_time=$(echo "scale=2; $start_time / 100" | bc)
|
||||
|
||||
# 计算PSS RSS
|
||||
if [ $(cat $dir/meminfo-"$app"-"$round".txt | grep "MEMINFO in pid" -c) -ne 1 ]; then
|
||||
cat $dir/meminfo-"$app"-"$round".txt | grep "TOTAL PSS" | tail -n 1 > tmp.txt
|
||||
if [ $(cat $dir/meminfo/meminfo-"$app"-"$round".txt | grep "MEMINFO in pid" -c) -ne 1 ]; then
|
||||
cat $dir/meminfo/meminfo-"$app"-"$round".txt | grep "TOTAL PSS" | tail -n 1 > tmp.txt
|
||||
pss=$(cat tmp.txt | awk '{print $3}')
|
||||
rss=$(cat tmp.txt | awk '{print $6}')
|
||||
else
|
||||
cat $dir/meminfo-"$app"-"$round".txt | grep "TOTAL PSS" > tmp.txt
|
||||
cat $dir/meminfo/meminfo-"$app"-"$round".txt | grep "TOTAL PSS" > tmp.txt
|
||||
pss=$(cat tmp.txt | awk '{print $3}')
|
||||
rss=$(cat tmp.txt | awk '{print $6}')
|
||||
fi
|
||||
|
||||
# 计算大页分配成功率
|
||||
inc_alloc=$((alloc-prev_alloc))
|
||||
inc_alloc_fallback=$((alloc_fallback-prev_alloc_fallback))
|
||||
inc_total=$((inc_alloc+inc_alloc_fallback))
|
||||
if [ $inc_total -ne 0 ]; then
|
||||
inc_ratio=$(echo "scale=4; $inc_alloc / $inc_total" | bc)
|
||||
else
|
||||
inc_ratio=1
|
||||
fi
|
||||
|
||||
pagefaults=$(cat $dir/simpleperf-"$app"-"$round".txt | grep 'page-faults' | awk '{print $4}')
|
||||
itlbmiss=$(cat $dir/simpleperf-"$app"-"$round".txt | grep 'iTLB-load-misses' | awk '{print $4}')
|
||||
dtlbmiss=$(cat $dir/simpleperf-"$app"-"$round".txt | grep 'dTLB-load-misses' | awk '{print $4}')
|
||||
cpustall=$(cat $dir/simpleperf-"$app"-"$round".txt | grep 'raw-stall-backend-mem' | awk '{print $4}')
|
||||
|
||||
# 计算大页相关
|
||||
inc_ratio=$(cat $dir/ratio-"$app"-"$round".txt | awk '{print $1}')
|
||||
inc_total=$(cat $dir/ratio-"$app"-"$round".txt | awk '{print $2}')
|
||||
|
||||
echo $round $app $start_type $start_time $inc_ratio $inc_total $rss $pss $pagefaults $itlbmiss $dtlbmiss $cpustall >> $dir/result
|
||||
|
||||
rm tmp.txt
|
||||
|
|
|
|||
Loading…
Reference in New Issue