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