-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_monitor.sh
executable file
·32 lines (27 loc) · 1.15 KB
/
power_monitor.sh
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
#!/bin/bash
# Measure average power consumed in 30sec with 1sec sampling interval
# The values are in mW
duration=30
interval=1
RAILS=("VDD_IN /sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power0_input"
"VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-0040/iio:device0/in_power0_input"
"VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power1_input"
"VDD_SYS_SOC /sys/bus/i2c/drivers/ina3221x/0-0040/iio:device0/in_power1_input"
"VDD_SYS_DDR /sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power2_input"
"VDD_4V0_WIFI /sys/bus/i2c/drivers/ina3221x/0-0040/iio:device0/in_power2_input")
for ((i = 0; i < ${#RAILS[@]}; i++)); do
read name[$i] node[$i] pwr_sum[$i] pwr_count[$i] <<<$(echo "${RAILS[$i]} 0 0")
done
end_time=$(($(date '+%s') + duration))
while [ $(date '+%s') -le $end_time ]; do
for ((i = 0; i < ${#RAILS[@]}; i++)); do
pwr_sum[$i]=$((${pwr_sum[$i]} + $(cat ${node[$i]}))) &&
pwr_count[$i]=$((${pwr_count[$i]} + 1))
done
sleep $interval
done
echo "RAIL,POWER_AVG (mW)"
for ((i = 0; i < ${#RAILS[@]}; i++)); do
pwr_avg=$((${pwr_sum[$i]} / ${pwr_count[$i]}))
echo "${name[$i]},$pwr_avg"
done