How to monitor power usage in Linux

It is important to measure power consumption in operating system especially when you try to maximize the battery life of your laptop, or reduce the energy bill of rack-mounted servers in a data center. Power usage monitor can also be helpful to diagnose issues with power management, or even buggy behaviors of applications.

In this post, I will describe how to monitor power usage in Linux operating system.

For Linux-based systems, you can use PowerTop, an ncurses-based command-line tool developed by Intel to monitor process-level power consumption, and to provide suggestions to optimize power management. PowerTop supports Intel, AMD, ARM, and UltraSparc processors while it is the most reliable on Intel processors for the obvious reason.

To install PowerTop on Ubuntu or Debian:

$ sudo apt-get install powertop

To install PowerTop on CentOS, Fedora or RHEL:

$ sudo yum install powertop

To launch PowerTop, simply run:

$ sudo powertop

Once PowerTop is launched, you can press left/right arrow keys to navigate tab-based UI. PowerTop can start reporting power estimates after it has collected enough measurements, which can take a couple of minutes. Previous measurements are stored in /var/cache/powertop, and will be loaded upon subsequent PowerTop launch.

In "Tunables" menu, you can experiment with various power management settings in case some tunable parameters are not enabled on your Linux distribution.

For offline analysis, PowerTop allows you to export power monitoring results to csv or html format as follows.

$ sudo powertop --csv=output.csv
$ sudo powertop --html=output.html

To get more accurate estimates, you can run PowerTop in "calibration" mode as follows. The entire calibration process can take a couple of minutes. During calibration, PowerTop can disconnect your system from WiFi, adjust screen brightness, and generate USB device activities.

$ sudo powertop --calibrate
Loaded 27 prior measurements
Starting PowerTOP power estimate calibration 
Calibrating idle
Calibrating: disk usage 
My (0) time 14986258702 is not the same as child (0) time 15395089845
Calibrating backlight
.... device /sys/class/backlight/intel_backlight/brightness 

The screenshots of PowerTop are shown below.

PowerTop Overview

PowerTop Idle Stats

PowerTop Frequency Stats

PowerTop Device Stats

PowerTop Tunables

HTML Report Generated by PowerTop

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

6 thoughts on “How to monitor power usage in Linux

  1. Powertop has hw dependency. Only intel machine can get the full functionality. I've been stuck with my AMD Opteron machine. But I don't find better alternatives...shame but powertop is the one.

  2. I noticed a minor mispaste:
    sudo powertop --csv=output.html
    should be
    sudo powertop --html=output.html.

    Otherwise, a great article, thanks for sharing the knowledge!

  3. My powertop shows 1.12.
    The examples shows 2.1.
    Mine does not show options.
    But a very nice piece of SW
    and I would like to make it work.

Leave a comment

Your email address will not be published. Required fields are marked *