Part of our efforts to reduce power consumption in Ubuntu is to provide an easy tool to hunt down which programs and devices are to blame for inordinate power consumption. powertop’s interactive mode is pretty good for this if you are sitting in a train and want to tweak some knobs to max out battery life, but we need something more reproducible and noninteractive for developers who want to file proper bug reports.
So I wrote a little script power-usage-report which calls fatrace for measuring file access activity from programs, and powertop-1.13 to measure process and device wakeups, clean up and sort their ouput, and generate a report which is appropriate to attach to bug reports, send around, put into Jenkins for measuring daily progress, etc. It is now part of fatrace version 0.4, so today’s Precise upgrades will have it.
The output has several sections for disk access (which prevent the disk from spinning down), wakeups (causing CPU power usage), and device activity. Disk/wakeups are sorted in descending order by process:
$ sudo power-usage-report Measurement will begin in 5 seconds. Please make sure that the computer is idle, i. e. do not press keys, start or operate programs, and that programs are not busy with active tasks other than the one you want to examine. Starting measurement for 60 seconds... Measurement complete. Generating report... ======= unity-panel-ser: 5 file access events ====== /usr/share/zoneinfo/UTC: 1 reads /etc/timezone: /usr/share/zoneinfo/posix/Europe/Berlin: 1 reads /etc/localtime: 3 reads ======= gnome-settings-: 1 file access events ====== /etc/fstab: 1 reads ======= telepathy-gabbl: 1 file access events ====== /home/martin/.cache/wocky/caps/caps-cache.db: 1 reads ====== Wakeups ====== 30,9% ( 52,0) compiz 16,3% ( 27,4) [iwlwifi]12,5% ( 21,0) [i915] 3,7% ( 6,3) [ahci] 2,3% ( 3,9) swapper/3 1,2% ( 2,0) gvfs-afc-volume [...] ====== Devices ====== An audio device is active 100,0% of the time: hwC0D0 Conexant CX20585 Recent USB suspend statistics Active Device name 100,0% USB device 1-1.5.4.4 : USB Mouse (A4Tech) 100,0% /sys/bus/usb/devices/1-1.5.4.2 100,0% USB device 1-1.5.4 : Kinesis Keyboard Hub (PI Engineering) 0,0% USB device 1-1.5.2 : USB2.0 Hub Controller (NEC Corporation) [...]
You can redirect output to a file, of course. The top header (“Starting measurement..” etc.) will go to stderr and thus not be part of the redirected output.
#1 by Fitoschido on 2012/02/21 - 16:48
Zitieren
Did you know that you’re awesome?
#2 by Weboide on 2012/02/22 - 19:47
Zitieren
This won’t run on Ubuntu. It looks for the binary “powertop-1.13″ instead of plain “powertop”. Why is it version-specific?
#3 by pitti on 2012/02/22 - 22:08
Zitieren
You have to install the powertop-1.13 package, as it says. The current powertop version doesn’t support a proper batch/dump mode.
Pingback: Ubuntu 12.04 Development Update
#4 by Dylan on 2012/02/23 - 18:54
Zitieren
My netbook says thanks!
Pingback: genool.ueuo.com» Blog Archive » Ubuntu 12.04 Development Update
#5 by bajsis on 2012/02/23 - 23:06
Zitieren
i get errors running the script, am i supposed to install something else but powertop-1.13?
Traceback (most recent call last):
File “./power-usage-report”, line 202, in
main()
File “./power-usage-report”, line 195, in main
output = probe()
File “./power-usage-report”, line 60, in probe
‘-p’, str(powertop.pid)], stdout=subprocess.PIPE, env=env)
File “/usr/lib/python2.7/subprocess.py”, line 679, in __init__
errread, errwrite)
File “/usr/lib/python2.7/subprocess.py”, line 1239, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
#6 by pitti on 2012/02/24 - 08:11
Zitieren
That would be “fatrace”. But the script is shipped in the fatrace package, so you should already have it. If you downloaded the script from the bzr branch’s web UI, please instasll the “fatrace” package.
Pingback: Ubuntu 12.04 Development Update | | Bowie RocksBowie Rocks
#7 by Bill on 2012/02/29 - 19:02
Zitieren
This script is great! For another great IT/power resource, check out this “Power Consumption Calculator.” It can provide an estimate of how much carbon/power your system is currently using and how it can be diminished through virtualization.
Pingback: Ubuntu 12.04 versus Windows 7 | Technology
Pingback: Ubuntu 12.04 versus Windows 7 | Linux Video
#8 by Stefan Müller on 2012/09/03 - 14:50
Zitieren
Thank you very much for this very informative and simple to use script! I would like to ask for some help as to how to go about the peculiar output I get on my Acer Aspire One netbook (ZG5, SATA-SSD).
Cat’ing the output into a log file, the first few lines show
====== lspci: 356 file access events ======
(…)
/usr/share/misc/pci.ids: 267 reads
The last entry (Recent SATA AHCI link activity statistics) does not show any data.
This is consistent over all trials. I have verified that the output of ‘ps ax | grep pci’ is void. So me thinks that something is wrong here. Though, I do not know where to continue asking for support. Would you be so kind to give me a pointer as to where I could post this issue?
Many thanks & cheers!
Stefan Müller, Switzerland