I am running Ubuntu 20.04 on ARM board (aarch64). I want to log total power consumption every 5 seconds. I tried several tools.
Powertop
I tried running powertop command. It outputs something like following:
PowerTOP v2.11 Overview Idle stats Frequency stats Device stats Devic
Summary: 432.8 wakeups/second, 0.0 GPU ops/seconds, 0.0 VFS ops/sec and 14.7% C
Power est. Usage Events/s Category Description
322 mW 16.0 ms/s 75.2 Process [PID 1202] weston --idle-
239 mW 0.9 ms/s 60.1 kWork kernfs_notify_workfn
210 mW 9.7 ms/s 49.4 kWork memlat_monitor_work
146 mW 2.2 ms/s 36.0 Process [PID 11] [rcu_preempt]
121 mW 12.4 ms/s 25.8 Process [PID 1160] weston --idle-
91.4 mW 2.3 ms/s 22.2 Process [PID 12] [rcuog/0]
73.0 mW 12.8 ms/s 13.4 Interrupt [407] msm_drm
68.9 mW 237.3 µs/s 17.3 kWork def_work_fn
56.6 mW 2.4 ms/s 13.4 Timer tick_sched_timer
55.0 mW 1.7 ms/s 13.3 Timer hrtimer_wakeup
50.6 mW 120.4 µs/s 12.8 Timer histtimer_fn
46.7 mW 4.3 ms/s 10.1 Process [PID 2547] /home/ideaforg
29.6 mW 0.7 ms/s 7.2 Interrupt [31] apps_rsc
24.3 mW 1.1 ms/s 5.7 Process [PID 949] /usr/sbin/rsysl
23.0 mW 10.0 ms/s 1.9 Process [PID 462] /lib/systemd/sy
21.8 mW 1.9 ms/s 4.8 Process [PID 2571] /home/ideaforg
20.1 mW 6.6 ms/s 2.5 Process [PID 1] /sbin/init
But it does not seem to give single number for total power consumption.
Powerstat
I also tried to log power consumption using powerstat command:
# powerstat
Running for 300.0 seconds (30 samples at 10.0 second intervals).
Power measurements will start in 180 seconds time.
Time User Nice Sys Idle IO Run Ctxt/s IRQ/s Watts
08:55:57 0.3 0.0 0.8 98.9 0.0 2 1162 716 0.00
08:56:07 0.3 0.0 0.9 98.8 0.0 1 1220 784 0.00
08:56:17 0.3 0.0 1.1 98.6 0.0 1 1148 755 0.00
08:56:27 0.3 0.0 1.1 98.6 0.0 1 1272 804 0.00
^C-------- ----- ----- ----- ----- ----- ---- ------ ------ ------
Average 0.3 0.0 1.0 98.7 0.0 1.2 1200.5 764.8 0.00
GeoMean 0.3 0.0 1.0 98.7 0.0 1.2 1199.5 764.1 0.00
StdDev 0.0 0.0 0.1 0.1 0.0 0.4 49.5 32.9 0.00
Minimum 0.3 0.0 0.8 98.6 0.0 1.0 1148.0 716.4 0.00
Maximum 0.3 0.0 1.1 98.9 0.0 2.0 1272.0 803.7 0.00
Summary:
System: 0.00 Watts on average with standard deviation 0.00
Note: Power calculated from battery capacity drain, may not be accurate.
Somehow it keeps giving 0 watts.
Fetching from /sys/class/power_supply
sub directory:
I started looking at various sub-directories /sys/class/power_supply
. I have connected this device to DC power supply (It does not run on battery). So, I first had a look at sys/class/power_supply/dc
directory:
# cd /sys/class/power_supply/
ls
battery dc pc_port usb
cd dc
ls
current_max input_current_limit present uevent waiting_for_supplier
device online subsystem voltage_max wakeup24
hwmon0 power type voltage_now
cd power/
ls
autosuspend_delay_ms wakeup wakeup_expire_count
control wakeup_abort_count wakeup_last_time_ms
runtime_active_time wakeup_active wakeup_max_time_ms
runtime_status wakeup_active_count wakeup_prevent_sleep_time_ms
runtime_suspended_time wakeup_count wakeup_total_time_ms
But I did not find any file that might contain current power consumption. Then I tried to find in pc_port
directory:
# cd /sys/class/power_supply/pc_port
ls
current_max hwmon2 power type voltage_max wakeup26
device online subsystem uevent waiting_for_supplier
cd power/
ls
autosuspend_delay_ms wakeup wakeup_expire_count
control wakeup_abort_count wakeup_last_time_ms
runtime_active_time wakeup_active wakeup_max_time_ms
runtime_status wakeup_active_count wakeup_prevent_sleep_time_ms
runtime_suspended_time wakeup_count wakeup_total_time_ms
I still did not find any sensible file name that might indicate to contain current power consumption.
How can I obtain current total power consumption?