接觸到了Android系統的Performance測試,所以有鎖定CPU的需求:
由於要首先讀取到此系統所支持的CPU頻率,之后再所支持的頻率中選取你想要的頻率,之后進行鎖定。
這個過程,手動也是可以的,直接:
1.查看所支持的CPU頻率:
adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
返回的結果是:416000 728000 900000 1040000
2.從上邊的結果中選取一個416000 ,之后進行設定:
echo 416000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 416000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
之后運行adb shell環境,輸入
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
查看設置是否有效,假如一直是416000,則證明設置生效。
由於每次都要輸入以上代碼查看之后設置,所以考慮用自動化實現,代碼如下:
setFrequence.bat文件:
@adb shell setprop persist.service.thermal 0 @adb wait-for-device @adb root @adb wait-for-device @adb remount @for /f "tokens=*" %%i in ('adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies') do @set var=%%i @echo All cpufreqs are: %var% @set /p last=please input your freq: ::@echo My cpufreq is: %last% @adb push .\run.sh /system/bin/ @adb shell chmod -R 777 /system/bin @adb shell /system/bin/run.sh --Cpufreq=%last%
run.sh文件:
#!system//bin/sh while [ $# -gt 0 ]; do case $1 in --Cpufreq=*) cpufreq=${1#--Cpufreq=} ;; esac shift done #echo cpufreq=`echo $cpufreq` echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq echo $cpufreq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo scaling_min_freq=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq` echo scaling_max_freq=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq` echo scaling_cur_freq= i=10 while [[ $i -gt 1 ]]; do cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq; sleep 5; ((i--)); done
把上邊兩個文件放到一個folder下邊,雙擊執行setFrequence.bat文件,輸入你想要的頻率即可。