View Single Post
Posts: 197 | Thanked: 101 times | Joined on Dec 2009 @ Netherlands
#2289
Here is a version of the script that is independent of the number of cpustates.
It assumes the lowest cpu speed with a nonzero count is the idle state.
Code:
#!/bin/sh

cur=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq`
max=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`
min=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq`
let cur=$cur/1000
let max=$max/1000
let min=$min/1000
echo "Current $cur MHz  min $min  max $max"

#bat=`cat  /sys/class/power_supply/bq27200-0/current_now`
#echo "Bat $bat"

cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state  | awk '
        { freq[NR] = $1; cnt[NR] = $2 ; sum += $2}
        END { 
                ni = NR
                while (cnt[ni] == 0) {
                        ni--
                }
                nonidle = sum - cnt[ni]
                for (i = 1; i <= NR; i++)  {
                        printf "%4d MHz overall %6d %4.1f%%", freq[i]/1000, cnt[i], cnt[i]*100.0/sum
                        if (i<ni) {
                                printf " nonidle %4.1f%%", cnt[i]*100.0/nonidle
                        }
                        printf "\n"
                }
         } '
frommy system:
Code:
Current 250 MHz  min 125  max 800
1200 MHz overall      0  0.0% nonidle  0.0%
1100 MHz overall      0  0.0% nonidle  0.0%
1000 MHz overall      0  0.0% nonidle  0.0%
 950 MHz overall      0  0.0% nonidle  0.0%
 900 MHz overall      0  0.0% nonidle  0.0%
 850 MHz overall      0  0.0% nonidle  0.0%
 810 MHz overall  30019  5.6% nonidle 48.8%
 750 MHz overall    386  0.1% nonidle  0.6%
 700 MHz overall    675  0.1% nonidle  1.1%
 600 MHz overall   7960  1.5% nonidle 12.9%
 550 MHz overall    475  0.1% nonidle  0.8%
 500 MHz overall  22007  4.1% nonidle 35.8%
 250 MHz overall 473821 88.5%
 124 MHz overall      0  0.0%
 

The Following User Says Thank You to mirakels For This Useful Post: