From bad8a7ca441f072824f16fe119e1b81fe71aeab9 Mon Sep 17 00:00:00 2001 From: Wenchao Hao Date: Thu, 15 May 2025 17:41:23 +0800 Subject: [PATCH] upda Signed-off-by: Wenchao Hao --- cold_start_app.sh | 63 ---------------------------------------- run.sh | 74 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 74 deletions(-) delete mode 100755 cold_start_app.sh diff --git a/cold_start_app.sh b/cold_start_app.sh deleted file mode 100755 index fe50e83..0000000 --- a/cold_start_app.sh +++ /dev/null @@ -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/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" - diff --git a/run.sh b/run.sh index 474fe19..42ae9f2 100755 --- a/run.sh +++ b/run.sh @@ -11,6 +11,7 @@ dir=$(/usr/bin/date +%Y-%m%d-%H%M) mkdir $dir 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 @@ -25,11 +26,47 @@ for round in $(seq 1 2); do 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=$! - # 回到桌面,应用退后台 - adb shell input keyevent 3 + # 获取应用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 @@ -37,9 +74,18 @@ for round in $(seq 1 2); do 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 + # 计算启动耗时 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" @@ -52,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