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.

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.