Close Menu
    X (Twitter)
    Hectic GeekHectic Geek
    • Apps
      • Apps for Mac
      • Apps for PCs
      • Best Apps
    • Concepts
      • Comparison
      • For Geeks
      • IT Careers
    • Gadgets
      • Accessories
      • Best Work Laptops
      • Budget Laptops
    • GNU/Linux
      • Ubuntu
    • How To
      • Virtualization
      • Windows
      • Windows How-To
    Hectic GeekHectic Geek
    Home ยป powerstat: Power Consumption Calculator for Ubuntu Linux
    Ubuntu

    powerstat: Power Consumption Calculator for Ubuntu Linux

    GayanBy GayanOctober 9, 2021Updated:October 9, 202128 Comments10 Mins Read
    Twitter Reddit Telegram WhatsApp Email
    Share
    Twitter Reddit Telegram WhatsApp Email

    Most users won’t be needing tools like these, but if you’re a bit of a power user, then having the ability to measure the real power consumption rate of your mobile computer (laptop, notebook etc) under Ubuntu Linux can be quite useful.

    For instance, let’s say that you recently upgraded your Kernel (a part of your operating systemย that communicates directly with the hardware), and the developers claimed that it will enhance the power consumption, then after the upgrade, how can you know if it has really decreased the power usage or not?

    So if you had some sort of a tool that can measure the power consumption of your laptop, then you can use it before and after the upgrade, and then compare the results later and it should do the trick, right?

    Now there aren’t that many power consumption monitoring tools in GNU/Linux yet, but in recent times, especially thanks to the upcoming 12.04 Precise Pangolin, Ubuntu developers are putting some effort into enhancing the battery life. When compared with Windows, GNU/Linux has not been managing power that efficiently and in the future mobile computers will eventually outrun desktops, so it is crucial for the survival of Ubuntu because and no one won’t bother installing an OS if has a bad reputation while managing power.

    Thanks to those efforts, a Kernel developer of Ubuntu, called “Colin Ian” has written few tools that let you monitor the power consumption related things in Ubuntu Linux with ease. One, in particular, is called “powerstat”, and it is a pretty excellent little tool that calculates the power consumption of your Laptop/Notebook etc when running on your battery.

    powerstat running in Ubuntu

    So if you’re interested in trying to improve your battery life under Ubuntu and searching for a tool to start measuring it, to begin with, then powerstat is a must-have.

    Few main features of powerstat

    *. Once run, it basically monitors your system for about 10 seconds and it is performed over and over again until 48 samples are collected over 480 seconds. While running, it shows information (fetched from your Kernel’s output) such as:

    1. Time – the startup time of each monitoring instance.

    2. User – CPU usage of processes initiated by the current user.

    3. Nice – a special value (Kernel function) that prioritize the CPU time for applications. Depending on the “importance” of the process, the “nice” value changes, giving more or less CPU time for the process.

    So if you have some apps that require a lot of your CPU time while “powerstat” is running, then you’ll see those values under “Nice”.

    individual fields

    4. Sys – CPU usage for the system software, such as CPU time used by your Kernel for instance.

    4. Idle – in simple terms, “idle” values represent the “waiting seconds” of your CPU. In other words, it’s the only time your poor CPU gets to rest (well, other than when you turn off the computer :D).

    For instance, if you see a value of 96%, then that simply means, for that period, 96% of the CPU was at an idle state (low power mode, saving energy consumption by without doing any work). And only 4% of the CPU was consumed by applications.

    5. IOย  – (This refers to “IO Wait” rather than I/O itself, I think)

    “I/O” stand for the “input/output” protocol, which is the building block of inter-device communication.

    However, an “I/O wait” is a bit more complicated term and many individuals have different opinions about it. So I won’t go into all the details (to be honest, I don’t have thorough knowledge about it :/).

    But as a simple explanation (so anyone can get a simple idea), an “I/O Wait” is the waiting time of your CPU, after sending a signal to hardware asking to do something. Until the CPU gets a reply from that particular hardware, and if has nothing else to do, then it has to wait till the data arrives for processing.

    It’s like sending a letter to someone asking whether they could help you out or not. Until they give you a replay, for that matter, even if you have fulfilled all the other necessities to solve it, you cannot do anything else but wait.

    So your friend is acting as a “bottleneck”, which is the same with “I/O waits” (most of the time) because although the CPU has all the muscles it needs to process the heck out of it until the hardware slowly (compared with the CPU) gathers the data, there’s nothing your CPU can do to improve the process.

    Again, this is just a simple example, and in complicated technical terms, it might not be that accurate.

    6. Run – Under this, it shows the currently running processes.

    7. Ctxt/s (context switch rate) – Let’s assume that you have a single CPU (no multiple cores) and three programs are trying to run simultaneously (let’s call them “A”, “B” and “C”). Now since it’s a single-core CPU, the CPU will have to switch between each program really fast, (I meant super fast! :D) thus it would seem like those three programs wwere running simultaneously.

    But in reality, the CPU executes each program for a short while (partially) and then moves over to the next one (B) run it for a bit,ย  and then goes to the other one (C), and so on. Then when it comes back again to the first process (A), it has to remember where it “left” it the last time, otherwise, it’ll have to execute the program from the beginning and it is a waste of time.

    So in order to help the CPU to resume programs (by storing data that contain details such as where it stopped the last time), a special method is used, and it’s called “Context switching”.

    So under “Ctxt/s”, it shows how many times the CPU paused and resumed programs per second (again this is in really simple terms).

    8. IRQ/s = IRQ per second – IRQ is a special signal (I/O technique) that hardware devices use to communicate with your CPU to get the work done. So under this field, it shows the amount of IRQ requests from your hardware.

    9. Fork – A method that a running process uses to create a copy of itself. The value under its name just initiates how many processes were forked.

    10. Exec – A function of the Kernel that replaces a currently running process with a new one. Although the process is totally different from the old one, unlike starting a totally new process (from scratch, with a new “id” etc), the newly executed process will have the same “id” and some of the other attributes from the now old, terminated process.

    In this instance, in the output if it says “4”, then that means, for that period, 4 processes were replaced with new ones.

    11. Exit – After doing its job, each process exits or terminates all by itself and notifies the OS by using a special notification called the “exit” command. Again, under this value, you’ll see how many processes exited during that time.

    12. Watts – Oh well, that’s pretty apparent :D.

    Anyhow, this is the value that we’re quite interested in as we can get almost all the above-mentioned info by default with somewhat ease. Under this field, it shows the current power consumption rate (energy units per second). So as you can see from the below screenshot, depending on your system’s load, the power consumption will give different values.

    calculated watts

    *. After collecting the samples, it’ll display, “Average”, “Minimum” and “Maximum” values under each field. And at the very end, it shows the “Average” power consumption rate plus a “Deviation” value for the whole 480 seconds.

    summary

    Please remember that, if all you want to know is the average power consumption rate of your PC in the “idle” state (by default powerstat assumes having 98% of a CPU idle value as it is in an”idle” state), then don’t run any apps while “powerstat” is running.

    *. Of course, you can run some power-intensive programs, if you want to measure the Maximum power consumption of your mobile PC.

    Now I know no one really needs all these ramblings. But the reason I thought I’d put a simple description under each field is that it kinda helps to get a simple idea of what the output says and how it effects the system’s performance (power usage).

    If interested, you can install “powerstat” in Ubuntu 12.04 Precise Pangolin, 11.10 Oneiric Ocelot, 11.04 Natty Narwhal, 10.10 and 10.04 by simply using its PPA, again, provided by Colin (thanks mate! :D).

    For that, open your Terminal and enter the below commands.

    sudo apt-add-repository ppa:colin-king/powermanagement

    sudo apt-get update

    sudo apt-get install powerstat

    Simple Examples of Power Consumption Calculator for Ubuntu Linux

    You can run this program with normal user privileges or as the administrator (which would give you slightly more details in the output). And as a way of letting your PC drop into a “balanced” state (say the system was a bit busy when you first ran powerstat), “powerstat” waits for about 3 minutes before start monitoring.

    But if you don’t want to wait that long, then you can use the “-d” argument to change the execution time. For that, you’ll need to run it using the “sudo” privileges.

    For instance, if you want to execute the program as soon as you type its command, without any delays, then you can use something like the below one.

    sudo powerstat -d 0

    running without a delay

    However, as said before, by default it requires a 98% of CPU idle value for accepting that your system is in an idle state. But, if your PC usually has a slightly higher CPU idle value (due to some heavy system services for instance), then you can manually bypass the default idle value with the “-i” argument, to get the power usage of your PC’s actual idle value.

    So let’s say I want to use 90% as the default CPU idle value in powerstat, then I’d use something like the below command.

    sudo powerstat -i 90

    It has few other additional commands. For that, please refer to its manual, you can use the below command to start reading it.

    man powerstat

    Now as said in the beginning, the upcoming Ubuntu 12.04 is undergoing some nice changes (improvements), especially concerning the power consumption related ones. So the developers have set up an excellently written Wiki page where you can find tips & various other ways of improving the battery life (some are hardware-specific, for instance, some optimizations are only valid for Intel Sandy Bridge chips etc).

    So I humbly advise you to read this Kernel power-management Ubuntu Wiki page as it will come in handy for some. And if you’re a developer, then you can acquire the source code by visiting this page as well.

    As an ending note, as an experienced Ubuntu Linux user, if you’re looking for an easy to use, powerful tool to measure the power consumption rate of your mobile computer, then “powerstat” is an awesome tool that fills a “gap” (quite elegantly! :D) that had been there for some time now. A big thanks go to “Colin King” for creating it.

    You might also wanna read Colin’s Blog as he often updates you on the latest power-management related issues/improvements in Ubuntu. Good luck.

    Linux Tips Ubuntu
    Share. Twitter Reddit Telegram WhatsApp Email
    Gayan

    An RHCE, 'Linux' user with 14+ years of experience. Extreme lover of Linux and FOSS. He is passionate to test every Linux distribution & compare with the previous release to write in-depth articles to help the FOSS community.

    Related Posts

    How to Check Linux CPU Usage?

    February 5, 2024

    Linux export Command: A Comprehensive Tutorial

    February 3, 2024

    Pop!_OS VS Linux Mint, Which One to Select in 2023

    July 27, 2023

    Debian vs Ubuntu Server: A Brief Comparison for Beginners

    July 2, 2023

    CPU Based Simple System Stability and Benchmark Tester for Ubuntu Linux – systester

    June 16, 2023

    Top Linux Distros for Web Development in 2023

    May 20, 2023

    28 Comments

    1. Colin Ian King on March 14, 2012 9:57 am

      Thanks for reviewing this. The source code is available here: http://kernel.ubuntu.com/git?p=cking/powerstat.gi…

      git://kernel.ubuntu.com/cking/powerstat.git

      Colin

      Reply
      • Gayan on March 14, 2012 1:43 pm

        Hi Colin,

        Thank you (I updated the post), and you're welcome too ;-).

        Reply
      • brijesh on February 2, 2013 11:13 am

        hi colin is there any tool that can actually monitor the power consumption per each process that is actually running in the linux system

        Reply
    2. Necolas on March 28, 2012 7:47 am

      Wow, that's an awesome tool!

      by the time i downloaded it, it had a much better GUI interface which is stunning!

      Let the experiments start!

      Nice one!

      Reply
      • Gayan on March 28, 2012 2:35 pm

        Enjoy it! ๐Ÿ˜‰ …

        Reply
    3. Danish on March 10, 2013 5:53 pm

      Hi! Colin
      I am setting a headless server. Wanted to measeure the server’s power consumptiona dn hence ran the powerstat program on a laptop only connected to DC without a battery. The program is giving a message saying that since the battery is not discharging power consumption cannot be measured.
      Is there any option or tweak reqired to monitor sch consumption?
      Thanks in advance.

      Dan

      Reply
    4. scriptwarlock on July 12, 2013 7:17 am

      is this good only for laptops w/ batteries? how about pc? need to know my wattage consumption.

      Reply
      • Gayan on July 12, 2013 8:04 am

        Hello there,

        For this tool to work, you must have a battery.

        Reply
    5. A K Saha on March 6, 2014 5:47 pm

      Nice explanation …. Let me know, whether possible to know only the power consumption by CPU rather than the whole system.. Means say Power consumption is 18 watt. Out of this, how much is consumed by only CPU or Microprocessor rather than the whole system ???

      Reply
      • Gayan on March 7, 2014 7:13 pm

        You’re welcome. As for the question, no, ‘powerstat’ cannot measure the power usage of different hardware as it simply displays the overall power usage readings, taken directly from the battery.

        Reply
    6. Shaheryar Najam on October 25, 2014 6:19 pm

      Hey,
      I want to have a power store in some variable so that i can process it. IS it possible?

      Reply
      • Gayan on October 25, 2014 7:58 pm

        Yes, it’s possible. For that you can use the below command:

        powerstat > power_usage_output.txt

        If you prefer ‘powerstat’ to start immediately, then it with the ‘-d’ option:

        powerstat -d 0 > power_usage_output.txt

        When it’s done running, you should be able to access the output through the ‘power_usage_output.txt’ file.

        Reply
    7. Shaheryar Najam on October 25, 2014 9:00 pm

      Thanks,but is it possibel to just see watts and save average watts in some variable so that i can access that variable in some other code to take some decision ?
      can you please tell me is there any documnet on powerstat which can help me see other things that can do with powerstat

      regards

      Reply
      • Gayan on October 26, 2014 8:20 am

        I don’t know if that’s possible. You can try asking in AskUbuntu website for that. However, if all you want is to print the average power consumption, then you can use the below command:

        powerstat -d0 > power_usage_output.txt && grep 'Watts on Average' < power_usage_output.txt > average_power_consumption.txt

        This will save the average power consumption on a file called ‘average_power_consumption.txt’ on your ‘Home’ folder. You can play with the ‘-d0’ or can remove it completely if you prefer as well. For learning more about ‘powerstat, you can refer to its manual using the below command.

        man powerstat

        Reply
    8. Shaheryar Najam on November 21, 2014 10:02 pm

      Hey,
      Powerstat take too much time in calculating average power. Is it possible to define less sample for its calculation so that time require to get power may get decrease

      Reply
      • Gayan on November 25, 2014 7:30 am

        Yes it’s possible. Please refer to its manual (follow the below link or type ‘man powerstat’ into the terminal):

        http://manpages.ubuntu.com/manpages/quantal/man8/powerstat.8.html

        But please remember that the default time-frame & the samples are optimized for accuracy, so if you change them, then you might lose the readings’ accuracy.

        P.S: Sorry about the late response.

        Reply
    9. kartik on April 1, 2015 10:27 am

      hello there…
      I am using Ubuntu 14.04 LTS and tried to install powerstat. The installation was successful but when i run “sudo powerstat -d 2”, it shows an error message as follows:
      “Machine is not discharging, cannot measure power usage.”
      Please note that my laptop was not on charging. If you could please help me with this, it will be very great…

      Reply
      • Gayan on April 2, 2015 7:58 am

        Hi Kartik,

        To measure power, your laptop should be running using the battery power. If this was indeed the case and didn’t work, then try rebooting the laptop…

        Reply
    10. narges on May 24, 2015 2:37 pm

      hi
      I am using Ubuntu 12.04 on vmware and I install powerstat, when i want to use that it shows an error message as follows:
      โ€œMachine is not discharging, cannot measure power usage.โ€
      can you help me please?

      Reply
      • Gayan on May 25, 2015 7:30 am

        Hi narges,

        First of all, ‘powerstat’ requires the presence of a battery. And secondly, make sure the virtual-machine has access to it (is the battery icon is shown in the notification area?). If they’re both true, then it could be something else…

        Reply
    11. Colin King on July 24, 2015 7:16 pm

      Just to let you all know, I’ve updated powerstat so it now uses the Intel RAPL power interface, so you can see the power being consumed by the CPU package. It also now supports features such as C-state stats and average CPU frequency stats too.

      http://kernel.ubuntu.com/~cking/powerstat/

      Colin

      Reply
      • Gayan on July 31, 2015 1:01 pm

        Thank you Colin. Since I got a chance, let me just say that my OS reviews wouldn’t have never felt ‘finished’ without this tool!, I love it.

        Oh and forgive me about the delay, my father got hospitalized a couple of days ago (he’s alright now, ๐Ÿ™‚ ) so I couldn’t manage things out here on ‘HecticGeek’. I’ll come up with a separate article featuring the new features. Thanks again.

        Reply
    12. Jopla on November 10, 2016 2:28 pm

      Hello,

      Powerstat seems me a nice tool, but am I right that it doesn’t work with a desktop? I got the message:
      “j@j:~$ sudo powerstat
      Machine is not discharging, cannot measure power usage.”

      Reply
      • Gayan on November 11, 2016 7:11 am

        Hi,

        You need to turn off A/C power before running it.

        Reply
        • Jopla on November 11, 2016 12:07 pm

          If I turn off the AC power my computer will save a lot off energy ๐Ÿ™‚ it is not a laptop.

          Is there a tool to show the energyusage of a desktop?

          Reply
          • Gayan on November 11, 2016 2:54 pm

            I don’t there is one Jopla, because this software tool uses the power usage output coming from the battery’s software. On a desktop computer, you’ll have to use hardware device.

            Reply
            • Jopla on November 11, 2016 5:15 pm

              Ok, Thanks for your reaction.

            • Gayan on November 12, 2016 2:45 pm

              You’re welcome.

    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Latest Posts

    Transforming Geek Culture with Advanced Software Development

    April 8, 2024

    The Role of Technology in Enhancing Digital Signage Solutions

    February 21, 2024

    How to Check Linux CPU Usage?

    February 5, 2024

    Linux export Command: A Comprehensive Tutorial

    February 3, 2024

    [Fixed] HDMI No Signal to TV or Monitor on Windows 10/11

    November 7, 2023

    AlmaLinux vs Ubuntu – How to Select the Best One?

    October 22, 2023

    Subscribe to Updates

    Get the latest news and updates from Hectic Geek. We won't overload you or sell your data!

    Contact
    • About Us
    • Contact Us
    • Privacy Policy
    • Write for Us
    X (Twitter)
    © 2026 Hectic Geek.

    Type above and press Enter to search. Press Esc to cancel.