1 #!/bin/bash 2 3 # CPU to monitor 4 CPU=${1:-0} 5 # Sampling time 6 SLEEP=${2:-1} 7 # Samples to collect 8 COUNT=${3:-3} 9 10 # Enter CPU's sysfs 11 cd /sys/devices/system/cpu 12 13 # Initial C-State residencies counter 14 ISC=$(find cpu0/cpuidle -name "state*" | wc -l) 15 for I in $(seq 0 $((ISC-1))); do 16 LCS[$I]=`cat cpu$CPU/cpuidle/state$I/usage` 17 done 18 19 # Dump header 20 printf "#%13s " "Time" 21 for I in $(seq 0 $((ISC-1))); do 22 printf "%14s " "idle$I" 23 done 24 echo 25 26 # Sampling loop 27 for I in $(seq $COUNT); do 28 29 sleep $SLEEP 30 31 # Dump CPU C-State residencies 32 now=$(date +%s) 33 printf "%14d " $now 34 for I in $(seq 0 $((ISC-1))); do 35 U=`cat cpu$CPU/cpuidle/state$I/usage` 36 CCS=$(($U - ${LCS[$I]})) 37 printf "%14d " $CCS 38 LCS[$I]=$U 39 done 40 echo 41 42 43 done 44 45 # vim: ts=2 46