Signed-off-by: Wenchao Hao <haowenchao22@gmail.com>
This commit is contained in:
Wenchao Hao 2025-05-15 14:19:59 +08:00
parent 9aacdcd7bf
commit c6354d9127
2 changed files with 42 additions and 112 deletions

View File

@ -6,105 +6,24 @@ prev_alloc=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/st
prev_alloc_fallback=$(adb shell cat /sys/kernel/mm/transparent_hugepage/hugepages-64kB/stats/anon_fault_fallback) 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 "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" &
echo "即将抓的perfetto, 请1秒后启动应用 $app" perfetto_pid=$!
echo perfetto_pid is $perfetto_pid
adb shell perfetto -c - --txt -o /data/misc/perfetto-traces/trace-"$app"-"$round".ptrace \ ps -ef | grep $perfetto_pid
<<EOF
buffers: { # 启动应用
size_kb: 707200 sleep 1
fill_policy: DISCARD activity=$(adb shell dumpsys package $app | grep -A 1 -w "android.intent.action.MAIN:" | head -n 2 | tail -n 1 | awk '{print $2}')
} if [ -z "$activity" ]; then
buffers: { continue
size_kb: 707200 fi
fill_policy: DISCARD echo "starting $app"
} adb shell am start -n $activity
data_sources: {
config {
name: "linux.process_stats"
target_buffer: 1
process_stats_config {
scan_all_processes_on_start: true
proc_stats_poll_ms: 1000
}
}
}
data_sources: {
config {
name: "android.surfaceflinger.frametimeline"
}
}
data_sources: {
config {
name: "linux.sys_stats"
sys_stats_config {
meminfo_period_ms: 250
meminfo_counters: MEMINFO_MEM_FREE
meminfo_counters: MEMINFO_MEM_AVAILABLE
cpufreq_period_ms: 250
}
}
}
data_sources: {
config {
name: "linux.ftrace"
ftrace_config {
buffer_size_kb: 81920
drain_period_ms: 100
symbolize_ksyms: true
ftrace_events: "power/cpu_frequency"
ftrace_events: "sched/sched_switch"
ftrace_events: "power/suspend_resume"
ftrace_events: "sched/sched_wakeup"
ftrace_events: "sched/sched_wakeup_new"
ftrace_events: "sched/sched_waking"
ftrace_events: "power/cpu_idle"
ftrace_events: "vmscan/mm_vmscan_kswapd_wake"
ftrace_events: "vmscan/mm_vmscan_kswapd_sleep"
ftrace_events: "vmscan/mm_vmscan_direct_reclaim_begin"
ftrace_events: "vmscan/mm_vmscan_direct_reclaim_end"
ftrace_events: "compaction/mm_compaction_begin"
ftrace_events: "compaction/mm_compaction_end"
ftrace_events: "mm_filemap_add_to_page_cache"
ftrace_events: "mm_filemap_delete_from_page_cache"
ftrace_events: "sched/sched_process_exit"
ftrace_events: "sched/sched_process_free"
ftrace_events: "task/task_newtask"
ftrace_events: "task/task_rename"
ftrace_events: "lowmemorykiller/lowmemory_kill"
ftrace_events: "oom/oom_score_adj_update"
ftrace_events: "ftrace/print"
ftrace_events: "binder/*"
ftrace_events: "power/gpu_frequency"
ftrace_events: "sched/sched_blocked_reason"
atrace_categories: "input"
atrace_categories: "gfx"
atrace_categories: "view"
atrace_categories: "webview"
atrace_categories: "camera"
atrace_categories: "dalvik"
atrace_categories: "power"
atrace_categories: "wm"
atrace_categories: "am"
atrace_categories: "ss"
atrace_categories: "sched"
atrace_categories: "freq"
atrace_categories: "binder_driver"
atrace_categories: "aidl"
atrace_categories: "binder_lock"
atrace_apps: "*"
}
}
}
duration_ms: 10000
write_into_file: true
flush_period_ms: 30000
incremental_state_config {
clear_period_ms: 5000
}
EOF # 睡眠15s等待perfetto退出
sleep 15
# 后面的dumpsys meminfo也会分配大页 # 后面的dumpsys meminfo也会分配大页
# 所以先看分配大页数 # 所以先看分配大页数
@ -125,6 +44,8 @@ fi
echo -e "$inc_ratio\t$inc_total" > $dir/ratio-"$app"-"$round".txt 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/misc/perfetto-traces/trace-"$app"-"$round".ptrace $dir/
adb pull /data/local/tmp/simpleperf-"$app"-"$round".txt $dir/ adb pull /data/local/tmp/simpleperf-"$app"-"$round".txt $dir/

43
run.sh
View File

@ -1,35 +1,41 @@
#$dirput: round app start_time start_type rss pss ratio pagefault itlbmiss dtlbmiss cpustalled #$dirput: round app start_time start_type rss pss ratio pagefault itlbmiss dtlbmiss cpustalled
dir=$(/usr/bin/date +%Y-%m-%d-%H-%M-%S) adb push perfconf.txt /data/misc/perfetto-configs
dir=$(/usr/bin/date +%Y-%m%d-%H%M)
mkdir $dir mkdir $dir
mkdir $dir/mminfo
echo "round app start_type start_time inc_ratio inc_total rss pss pagefaults itlbmiss dtlbmiss cpustall" > $dir/result 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 for round in $(seq 1 2); do
for app in `cat applist`; do for app in `cat applist`; do
sleep 10
echo "开始测试应用 $app" echo "开始测试应用 $app"
read -p "输入q退出, 输入其他任意内容继续" cmd # read -p "输入q退出, 输入其他任意内容继续" cmd
if [ "$cmd" == "q" ]; then #if [ "$cmd" == "q" ]; then
exit # exit
fi #fi
# 抓内存相关信息 # 抓内存相关信息
adb shell free -h > $dir/before_free-$app-$round adb shell free -h > $dir/mminfo/before_free-$app-$round
adb shell cat /proc/meminfo > $dir/before_meminfo-$app-$round adb shell cat /proc/meminfo > $dir/mminfo/before_meminfo-$app-$round
adb shell cat /proc/zoneinfo > $dir/before_zoneinfo-$app-$round adb shell cat /proc/zoneinfo > $dir/mminfo/before_zoneinfo-$app-$round
adb shell cat /proc/buddyinfo > $dir/before_buddyinfo-$app-$round adb shell cat /proc/buddyinfo > $dir/mminfo/before_buddyinfo-$app-$round
adb shell cat /proc/pagetypeinfo > $dir/before_pagetypeinfo-$app-$round adb shell cat /proc/pagetypeinfo > $dir/mminfo/before_pagetypeinfo-$app-$round
adb shell cat /proc/vmstat > $dir/before_vmstat-$app-$round adb shell cat /proc/vmstat > $dir/mminfo/before_vmstat-$app-$round
./cold_start_app.sh $app $round $dir ./cold_start_app.sh $app $round $dir
# 回到桌面,应用退后台
adb shell input keyevent 3 adb shell input keyevent 3
adb shell free -h > $dir/after_free-$app-$round adb shell free -h > $dir/mminfo/after_free-$app-$round
adb shell cat /proc/meminfo > $dir/after_meminfo-$app-$round adb shell cat /proc/meminfo > $dir/mminfo/after_meminfo-$app-$round
adb shell cat /proc/zoneinfo > $dir/after_zoneinfo-$app-$round adb shell cat /proc/zoneinfo > $dir/mminfo/after_zoneinfo-$app-$round
adb shell cat /proc/buddyinfo > $dir/after_buddyinfo-$app-$round adb shell cat /proc/buddyinfo > $dir/mminfo/after_buddyinfo-$app-$round
adb shell cat /proc/pagetypeinfo > $dir/after_pagetypeinfo-$app-$round adb shell cat /proc/pagetypeinfo > $dir/mminfo/after_pagetypeinfo-$app-$round
adb shell cat /proc/vmstat > $dir/after_vmstat-$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/trace-"$app"-"$round".ptrace mm > tmp.txt
@ -41,6 +47,9 @@ for round in $(seq 1 2); do
start_time=$(cat tmp.txt | awk '{print $1}') start_time=$(cat tmp.txt | awk '{print $1}')
start_type=$(cat tmp.txt | awk '{print $2}') start_type=$(cat tmp.txt | awk '{print $2}')
fi fi
start_time=$((start_time/10000))
start_time=$(echo "scale=2; $start_time / 100" | bc)
# 计算PSS RSS # 计算PSS RSS
if [ $(cat $dir/meminfo-"$app"-"$round".txt | grep "MEMINFO in pid" -c) -ne 1 ]; then if [ $(cat $dir/meminfo-"$app"-"$round".txt | grep "MEMINFO in pid" -c) -ne 1 ]; then