1#!/bin/bash 2 3# defines 4CPU_DIR="/sys/devices/system/cpu" 5GPU_DIR="/sys/class/kgsl/kgsl-3d0" 6 7# helper functions 8fileexists() { 9 [ `adb shell "[ -f $1 ] && echo found"` ] 10} 11getprop() { 12 if fileexists $1; then 13 echo `adb shell cat $1 | tr -d '\r'` 14 else 15 echo "FILE $1 NOT FOUND" 16 fi 17} 18setprop() { 19 if fileexists $1; then 20 adb shell "echo -n $2 > $1" 21 else 22 echo "FILE $1 NOT FOUND" 23 fi 24} 25 26# setup 27echo 28if [[ "`adb shell id | tr -d '\r' | awk -F'[()]' '{print $2}'`" != "root" ]]; then 29 adb root 30 adb wait-for-device 31fi 32 33# device name 34echo Device: `adb shell getprop ro.product.model` 35echo 36 37# collect and count all cores 38frequency= 39frequencies= 40cores=`adb shell ls /sys/devices/system/cpu/ | grep cpu[0-9].* | tr -d '\r'` 41for core in $cores; do 42 43 # display cpu 44 echo "$core:" 45 46 # display current status 47 if fileexists $CPU_DIR/$core/online && [ `getprop $CPU_DIR/$core/online` -eq 0 ]; then 48 echo " Status: OFFLINE" 49 else 50 echo " Status: ONLINE" 51 fi 52 53 # display available frequencies 54 if fileexists $CPU_DIR/$core/cpufreq/scaling_available_frequencies; then 55 frequencies=(`getprop $CPU_DIR/$core/cpufreq/scaling_available_frequencies`) 56 elif fileexists $CPU_DIR/$core/cpufreq/stats/time_in_state; then 57 frequencies=(`adb shell cat $CPU_DIR/$core/cpufreq/stats/time_in_state | cut -f1 -d " " | tr -d '\r'`) 58 fi 59 frequencies=( `printf "%s\n" "${frequencies[@]}" | sort -n` ) 60 echo " Available Frequencies: ${frequencies[@]} (Hz)" 61 62 # display current frequency 63 if fileexists $CPU_DIR/$core/cpufreq/scaling_cur_freq; then 64 frequency=`getprop $CPU_DIR/$core/cpufreq/scaling_cur_freq` 65 fi 66 echo " Current Frequency: $frequency (Hz)" 67 68done 69 70# poll gpu 71echo 72echo "GPU:" 73 74# get available gpu frequencies in sorted order 75if fileexists $GPU_DIR/devfreq/available_frequencies; then 76 frequencies=(`getprop $GPU_DIR/devfreq/available_frequencies`) 77elif fileexists $GPU_DIR/gpu_available_frequencies; then 78 frequencies=(`getprop $GPU_DIR/gpu_available_frequencies`) 79elif fileexists /d/clock/gbus/possible_rates; then 80 frequencies=(`getprop /d/clock/gbus/possible_rates`) 81else 82 echo " Unable to find available GPU frequencies" 83 echo 84 exit 85fi 86frequencies=( `printf "%s\n" "${frequencies[@]}" | sort -n` ) 87if [ ${frequencies[0]} == "(kHz)" ]; then 88 frequencies=(`printf "%s000\n" "${frequencies[@]:1}"`) 89fi 90echo " Available Frequencies: ${frequencies[@]} (Hz)" 91 92# collect and print current gpu frequency 93if fileexists $GPU_DIR/max_gpuclk; then 94 freq=`getprop $GPU_DIR/max_gpuclk` 95elif fileexists /d/clock/override.gbus/rate; then 96 freq=`getprop /d/clock/override.gbus/rate` 97else 98 echo "ERROR: unable to find current GPU frequency" 99 exit 100fi 101echo " Current Frequency: $freq (Hz)" 102echo 103 104 105