Battery Life: Measurement - junaruga/framework-laptop-config GitHub Wiki
Before tuning and improving a battery life, it's important to measure the battery life to know if a change is good or bad for the battery life.
This page is to introduce some tools to measure a battery life.
My environment
The following results are checked on the following environment.
- Model: Framework Laptop, Batch 2
- BIOS version: 3.02 (the BIOS shows "InsydeH20 Version: GWF30.03.02")
- CPU: 11th Gen Intel i7-1165G7 (8) @ 4.700GHz
- Fedora Linux 35
- Kernel version (
uname -r
): 5.15.10-200.fc35.x86_64 - Resolution: 2256x1504 (by
neofetch
) - Window Manager: sway
PowerTop
- The project URL: https://github.com/fenrus75/powertop
- The difficultly of the installation: middle
For the installation and usage, you can see this page for detail. You need to run the powertop
command by root or sudo
.
$ sudo powertop
Then enter the interactive mode. Tab or Shift+Tab is to change the tab menu.
PowerTOP 2.14 Overview Idle stats Frequency stats Device stats Tunables WakeUp
The battery reports a discharge rate of 8.60 W
The energy consumed was 0.00 J
The estimated remaining time is 4 hours, 29 minutes
Summary: 1402.7 wakeups/second, 0.0 GPU ops/seconds, 0.0 VFS ops/sec and 10.5% CPU use
Usage Events/s Category Description
3.9 ms/s 496.0 Timer tick_sched_timer
4.0% Device Display backlight
10.3 ms/s 100.0 Process [PID 15407] /usr/lib64/firefox/firefox -co
25.1 ms/s 93.1 Process [PID 13686] /usr/lib64/firefox/firefox
...
I think the important numbers are "discharge rate" in teh OverView tab.
- OverView tab: "a discharge rate of 8.60 W"
To check the number without interactive mode to report someone, I think the following steps are convenient.
$ cd /path/to/work_dir
$ sudo powertop --csv
modprobe cpufreq_stats failedLoaded 228 prior measurements
RAPL device for cpu 0
RAPL Using PowerCap Sysfs : Domain Mask d
RAPL device for cpu 0
RAPL Using PowerCap Sysfs : Domain Mask d
Devfreq not enabled
glob returned GLOB_ABORTED
Preparing to take measurements
To show power estimates do 129 measurement(s) connected to battery only
Taking 1 measurement(s) for a duration of 20 second(s) each.
PowerTOP outputting using base filename powertop.csv
$ grep '^The battery reports a discharge rate of:' powertop.csv
The battery reports a discharge rate of: 5.72 W;
UPower
UPower is a tool that you can measure the discharge rate. It's easy to report it to someone as it is not interractive command like powertop
.
- The project URL: http://upower.freedesktop.org/
- The difficultly of the installation: easy
If you don't have the upower
command, just install like this on Fedora 35.
$ sudo dnf install upower
$ rpm -q upower
upower-0.99.13-1.fc35.x86_64
If you want to read the information, you can run like this.
$ rpm -qi upower
Here is a command to list up devices using a battery?
$ upower -e
/org/freedesktop/UPower/devices/line_power_ACAD
/org/freedesktop/UPower/devices/battery_BAT1
/org/freedesktop/UPower/devices/DisplayDevice
Check a battery's info.
$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
native-path: BAT1
vendor: NVT
model: Framewo
serial: 00B5
power supply: yes
updated: Sun 02 Jan 2022 06:54:33 PM CET (55 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
warning-level: none
energy: 35.7126 Wh
energy-empty: 0 Wh
energy-full: 54.9934 Wh
energy-full-design: 55.0088 Wh
energy-rate: 6.776 W
voltage: 15.81 V
time to empty: 5.3 hours
percentage: 64%
capacity: 99.972%
technology: lithium-ion
icon-name: 'battery-full-symbolic'
History (charge):
1641146073 64.000 discharging
History (rate):
1641146073 6.776 discharging
And here is a command to print the energy rate easily. The "energy-rate" may be same with discharge rate on powertop
.
$ upower -i "$(upower -e | grep BAT)" | grep energy-rate
energy-rate: 6.699 W
PowerStat
- The project URL: https://github.com/ColinIanKing/powerstat
- The man page: https://manpages.ubuntu.com/manpages/xenial/man8/powerstat.8.html
- The difficultly of the installation: hard
If you want to measure the energy-rate in a reliable way, I think the powerstat
is useful. It seems the command is developed by a person at Ubuntu. Unfortunately the RPM package is not available on Fedora. But you can use the command on Snap.
The below links are useful for the installation.
- a. https://snapcraft.io/install/powerstat/fedora
- b. https://www.linuxcapable.com/how-to-install-snap-snap-store-snapcraft-on-fedora-35/
First you can install Snap seeing the document a.
$ sudo dnf install snapd
$ rpm -q snapd
snapd-2.53.4-1.fc35.x86_64
$ sudo ln -s /var/lib/snapd/snap /snap
$ ls -l /snap
lrwxrwxrwx. 1 root root 19 Jan 2 16:18 /snap -> /var/lib/snapd/snap/
Then running a command to install powerstat
Snap package, I saw the following error message.
$ sudo snap install powerstat
error: too early for operation, device not yet seeded or device model not acknowledged
Seeing the document b, I see the following note.
Once Snap is installed, it is highly recommended to log out and back in again or restart your ser vice to ensure snap’s paths are updated correctly.
Did logout & login the window manager. But the snapd
daemon is still inactive.
$ sudo systemctl restart snapd
$ systemctl status snapd
○ snapd.service - Snap Daemon
Loaded: loaded (/usr/lib/systemd/system/snapd.service; disabled; vendor preset: disabled)
Active: inactive (dead) since Sun 2022-01-02 16:25:53 CET; 2s ago
TriggeredBy: ● snapd.socket
Process: 14196 ExecStart=/usr/libexec/snapd/snapd (code=exited, status=42)
Main PID: 14196 (code=exited, status=42)
CPU: 58ms
Install the Snap core
package following the document b.
$ sudo snap install core
2022-01-02T16:28:07+01:00 INFO Waiting for automatic snapd restart...
core 16-2.52.1 from Canonical✓ installed
Then I see the snapd
daemon is now active.
$ systemctl status snapd
● snapd.service - Snap Daemon
Loaded: loaded (/usr/lib/systemd/system/snapd.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-01-02 16:28:08 CET; 25s ago
TriggeredBy: ● snapd.socket
Main PID: 14634 (snapd)
Tasks: 14 (limit: 38206)
Memory: 14.3M
CPU: 579ms
CGroup: /system.slice/snapd.service
└─14634 /usr/libexec/snapd/snapd
Jan 02 16:28:08 fedora systemd[1]: Starting Snap Daemon...
Jan 02 16:28:08 fedora snapd[14634]: AppArmor status: apparmor not enabled
Jan 02 16:28:08 fedora snapd[14634]: daemon.go:242: started snapd/2.53.4-1.fc35 (series 16; clas>
Jan 02 16:28:08 fedora snapd[14634]: daemon.go:335: adjusting startup timeout by 35s (pessimisti>
Jan 02 16:28:08 fedora systemd[1]: Started Snap Daemon.
Enable the snapd
to keep starting after restarting OS too.
$ sudo systemctl enable snapd
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.service → /usr/lib/systemd/syst
em/snapd.service.
Now you can install the Snap pwoerstat
package.
$ sudo snap install powerstat
powerstat V0.02.26-3-20210917-374-g2dafb9f from Colin King (cking-kernel-tools) installed
The actual command is installed at /var/lib/snapd/snap/bin/powerstat
. You can add the following PATH
. Maybe it's better to set the path with a low priority than other system's PATH
such as /usr/bin
.
$ vi ~/.bashrc
...
PATH="${PATH}:/var/lib/snapd/snap/bin"
...
export PATH
$ . ~/.bashrc
$ which powerstat
/var/lib/snapd/snap/bin/powerstat
Here is the command help.
$ powerstat -h
powerstat, version 0.02.26
usage: /snap/powerstat/140/usr/bin/powerstat [options] [delay [count]]
-a enable all sampling collection options (-c, -f, -t and -H)
-b redo a sample if a system is busy, considered less than 98% CPU idle
-c show C-State statistics at end of the run
-d specify delay before starting, default is 180 seconds
-D show RAPL domain power measurements (enables -R option)
-f show average CPU frequency
-g show GPU power (currently just i915)
-h show help
-H show spread of measurements with power histogram
-i specify CPU idle threshold, used in conjunction with -b
-n no printing of table heading when screen scrolls
-p redo a sample if we see process fork/exec/exit activity
-r redo a sample if busy and we see process activity (same as -b -p)
-R gather stats from Intel RAPL interface
-s show process fork/exec/exit activity log
-S calculate power from capacity drain using standard average
-t show Thermal Zone temperatures (in degrees C)
-z forcibly ignore zero power rate stats from the battery
delay: delay between each sample, default is 10.0 seconds
count: number of samples to take
Here is a command to get the report with default options. It take time 180 seconds + 30 samples * 10 seconds = 480 seconds = 8 minutes. The "7.23 Watts on average" is the value that I wanted to get.
$ 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
17:37:49 3.3 0.0 1.2 95.6 0.0 1 4591 4466 8.08
17:37:59 4.8 0.0 1.4 93.8 0.0 1 5780 5275 8.73
17:38:09 0.4 0.0 0.2 99.4 0.0 1 905 547 7.85
17:38:19 0.2 0.0 0.1 99.7 0.0 1 714 440 7.26
17:38:29 0.2 0.0 0.1 99.6 0.0 1 802 434 6.94
17:38:39 0.2 0.0 0.2 99.6 0.0 1 754 426 6.76
17:38:49 0.2 0.0 0.1 99.6 0.0 1 796 436 6.68
17:38:59 0.1 0.0 0.1 99.7 0.0 1 736 447 6.54
17:39:09 0.2 0.0 0.2 99.7 0.0 1 767 464 6.56
17:39:19 0.2 0.0 0.1 99.7 0.0 1 765 425 6.56
17:39:29 0.2 0.0 0.1 99.7 0.0 1 646 363 6.49
17:39:39 1.6 0.0 0.5 98.0 0.0 3 1656 1242 6.58
17:39:49 9.2 0.0 2.0 88.8 0.0 3 7650 4624 8.36
17:39:59 10.0 0.0 2.4 87.6 0.1 3 10192 4838 9.95
17:40:09 7.0 0.0 1.7 91.3 0.0 2 6532 3643 9.98
17:40:19 2.2 0.0 0.6 97.2 0.0 1 2348 1440 8.87
17:40:29 0.2 0.0 0.2 99.7 0.0 1 756 465 7.78
17:40:39 0.5 0.0 0.3 99.3 0.0 1 1051 573 7.30
17:40:49 0.1 0.0 0.1 99.7 0.0 1 744 420 6.94
17:40:59 0.3 0.0 0.2 99.5 0.0 1 773 485 6.76
17:41:09 0.2 0.0 0.2 99.7 0.0 1 822 431 6.69
17:41:19 0.1 0.0 0.2 99.7 0.0 1 710 406 6.58
17:41:29 0.4 0.0 0.2 99.4 0.0 1 864 511 6.59
17:41:39 0.2 0.0 0.2 99.6 0.0 1 822 474 6.54
17:41:49 0.2 0.0 0.2 99.6 0.0 1 799 447 6.54
17:41:59 0.2 0.0 0.2 99.7 0.0 1 777 448 6.52
17:42:09 0.4 0.0 0.3 99.3 0.0 1 1045 568 6.64
Time User Nice Sys Idle IO Run Ctxt/s IRQ/s Watts
17:42:19 0.2 0.0 0.1 99.7 0.0 1 706 414 6.60
17:42:29 0.2 0.0 0.2 99.6 0.0 1 720 408 6.57
17:42:39 0.2 0.0 0.2 99.6 0.0 1 824 485 6.57
-------- ----- ----- ----- ----- ----- ---- ------ ------ ------
Average 1.4 0.0 0.4 98.1 0.0 1.2 1901.6 1201.5 7.23
GeoMean 0.4 0.0 0.3 98.0 0.0 1.1 1199.6 716.7 7.16
StdDev 2.7 0.0 0.6 3.3 0.0 0.6 2409.0 1538.4 1.00
-------- ----- ----- ----- ----- ----- ---- ------ ------ ------
Minimum 0.1 0.0 0.1 87.6 0.0 1.0 645.6 362.9 6.49
Maximum 10.0 0.0 2.4 99.7 0.1 3.0 10191.8 5275.3 9.98
-------- ----- ----- ----- ----- ----- ---- ------ ------ ------
Summary:
System: 7.23 Watts on average with standard deviation 1.00