21

Is there a way to retrieve the current watt usage info on OS X Snow Leopard? I'm using mid-2010 iMac, so I'm not looking for just battery-related apps.

Does OS X even monitor power usage? Do I need to use an external reader between the power cord and the outlet?

I'm most interested in command-line/applescript based solutions for more convenient logging & stats, but I'm open for alternatives.


Both (@bmike's & @michaelmichael's) answers are undoubtedly correct. The meta–question in here was that is there any sensors/readers already on the PSU, that would work kind of like the way "kill-a-watt" works. I sense the answer for that is "no".

I know, it probably is just a wet dream, but a watt meter on board would be ideal for the computer to shout: "Look how eco-friendly I am; using just these watts!"


Ah!

@Kerri Shotts' suggested iStat Menus 3 do get the wattage readings from some sensor, along with volt and amp stats. So the meters are there, but how I could access them programmatically?


Bounty! Will be given for solid command-line sensor reading solution or for recommending exceptionally good 3rd party software (like one with statistical and historical data tools at minimum).

Just to inform: the aforementioned iStat Menus 3 lists the following power related sensors:

  • Voltage Sensors (Volts)
    • AC/DC
    • AC/DC
    • AC/DC Shunt
    • CPU
    • CPU 1.8V S0
    • CPU CTT
    • Graphics Module
    • Memory
  • Current Sensors (Amps)
    • AC/DC
    • CPU
    • CPU VTT
    • Graphics Module
  • Power Sensors (Watts)
    • AC/DC
    • CPU
    • Graphics Module

It does state "sensors", but they might be calculated as @msanford commented. How can I get my hands on that data programmatically?

  • Macs are very eco friendly and the testing of a unit is done by Apple as well as labs with calibrated test rigs. Luckily we can use the settings to maximize the macs we have while they come up with more efficient models tomorrow. – bmike Jun 18 '11 at 1:00
  • 1
    Does the PSU not report its current load (as I'm fairly sure it reports its voltage)? If so, P = IV, or Watts = Current (in amperes) • Voltage (in volts). Wattage isn't something that's directly measured but calculated from current and voltage, so I wouldn't expect a sensor to report watts if there are already reports on voltage and current. If that helps… – msanford Jun 19 '11 at 18:02
  • @msanford it might help—if someone tells us how to read the readings from the PSU. – Jari Keinänen Jun 20 '11 at 12:21

12 Answers 12

20

system_profiler SPPowerDataType seems to provide the most relevant information. On laptops it reports voltage and amperage which can give you the power consumption (mVolts × mAmperes × 10^-6 = Watts). It also reports Wattage, but that's actually a piece of metadata reported by Apple's power adapter, third-party power adapters can show blanks here. Since desktops do not have rechargeable batteries, there's no way to calculate power consumption by measuring charging and discharging of battery.

But wait, there's still hope! Apple publishes a lot of source code, and googling for Wattage or Power+mV hints that certain kernel extensions can be queried about power consumption. Unfortunately, I cannot come up with a working script right now, but it seems possible.

  • 1
    I see it is the command-line interface for the System Profiler.app. Sadly, on desktops, it just shows the settings from EnergySaver.prefpane and if an UPS is installed. – Jari Keinänen Jun 26 '11 at 8:49
  • On my rMBP 2015 15", Amperage and Voltage from section Battery Information is more or less constant, at least compared to the "System total" value from iStat, which updates every second. Also, I noticed Amperage being 0. – Johannes Bittner Jan 25 '17 at 5:57
  • Love this; short and simple. Nothing to download or install. If people are interested I (or someone else) could easily whip up a script/command to pull the necessary fields from this command and spit out the actual wattage being used. – rinogo Aug 29 '17 at 5:55
  • Update: The specified command worked for me when I needed it the first time, but when I needed it again, it didn't work. It's displaying weird values for amperage. Maybe I'm just not looking in the right place. Who knows... ymmv. – rinogo Aug 30 '17 at 16:01
11

This doesn't satisfy the command-line requirements, but give a try to iStat Menus 3. It gives you readings on just about every sensor in your machine (which for me includes AC/DC Watts, CPU Watts, and GPU Watts). I'm sure it isn't 100% accurate, but it was more than accurate enough in tuning my machine to work within the limited constraints of my APC battery.

All that said, my machine is a 2010 iMac, so depending on your machine, it may or may not work. In addition, I don't see power readings specifically for the HDD (which should be minimal), or anything specific to the display (that said, reducing LCD brightness reduces the wattage quite a bit, so it is counted in total).

Worth a try at least. IIRC there is a free version, but it was so worth it that I went ahead and paid for it. I'm a bit of a control freak, so I have memory, temperature, disk activity, network activity, etc., in my menubar and love it. :-)

  • 2
    Par excellence! Now the question is: how do iStat Menus get the sensor readings… – Jari Keinänen Jun 18 '11 at 14:24
8
+100

There is a paid application called Hardware Monitor that provides access to pretty much every sensor available on a mac including voltage, current and wattage which I believe you are looking for. It does include a command line utility to read this information.

I used this to track down a faulty logicboard in an iMac last year and found it worth the €7. It includes the ability to output the sensor values to a CSV which can be helpful for logging and visual display of the data. I'm not sure if it does PSU readings (as I don't have the app on the machine I'm on atm) but it hits pci, slots, cpu and lots of other.

You can find the software here : http://www.bresink.com/osx/HardwareMonitor.html

I'm not associated with this company at all, just found the tool to be very useful in my diagnostics arsenal.

  • Lyken wins the prize with this answer. What an amazing piece of software. Command line tool, menu bar, and full app. Unless the power supply itself is monitored in new macs, it won't give a total power rating, but this sure does a great job accessing all the data that is available. – bmike Jun 21 '11 at 20:34
  • Sorry for the late update, but, @Lyken, your +100 is well deserved: I hesitated on giving the full +200 as Hardware Monitor seemingly won't give the PSU wattage like iStat Menus 3 does; for some reason the HWM lists power sensors only for CPU A, 4 CPU High Sides and MXM Graphics Module. Great app nevertheless and I would had awarded your answer in a breeze if some other bounty answer would've met the automatic half-bounty-award rules. Like I said, +100 well deserved. – Jari Keinänen Jun 29 '11 at 9:39
  • Yes, I do believe that HWM reads the sensors on a per model basis so it depends on what is available on your version. Did iStat Menu 3 read the PSU wattage on your model also? – Digitalchild Jun 29 '11 at 23:55
  • 1
    Unfortunately Hardware Monitor announced EOL on June 19, 2017. bresink.com/osx/216202/eol.html – walterra Sep 8 '17 at 12:52
7

IANAEE (I am not an Electrical Engineer), but as I understand it's not possible to accurately measure a computer's power consumption via software. The best solution is to connect your Mac to a device like a Kill-a-Watt

If you're looking for a scriptable solution - and an interesting project - here are instructions on creating a wireless wattage monitoring system, or a "Tweet-a-Watt".

7

All of the data in iStat is just from keys in the ioregistry. You can pull a dump of it from the command line using ioreg:

ioreg -w 0 -l

That is going to be a lot of data to look through, you can carve it up in various ways. I do not believe the actual data you want is provided on iMac, the system monitors temperature in a number of places, but since it does not run on a battery it is less important to know the instantaneous current being pulled by the system, and thus probably not worth the cost of a sensor.

5

No metered sensors are present in the power supply.

The logic board measures temperature in several places to control the blowers and the CPU monitors temp to reduce clock rate when it becomes warmer than the blowers can cool it.

I suppose some PHD thesis might be done on integrating the fan speed and various temperature sensors to calculate an expected power consumption. It's possible to get a calculation and with some calibration, it might even be pretty accurate.

In reality since that data isn't exposed or recorded, you might have to measure externally. Decent home energy counters are between $150 and $300 w

You could rent or buy a unit that measures the power through the outlet and then run some test to see how much power the mac takes over an hour in certain conditions.

  • Off
  • Sleep
  • Idle
  • Various CPU loads
  • Maximum CPU, everything going

Then you could correlate these with CPU usage monitoring that is trivial over time using top and be able to add things up.

It all depends on what you really want to do with the data other than learn how the hardware works and have some cool graphs.

  • 2
    + you need to add ad infinitum more things to the list. Probably by the time I'd had all conditions calibrated I would need to replace the current iMac :-D Maybe just some external basic W & kWh meters would do the trick, if there are no meters onboard. – Jari Keinänen Jun 17 '11 at 18:24
  • 2
    :-) Glad you got the humor. My experience is that the macs draw 20 to 25% less than the specifications published by Apple even under rigorous tests to get everything drawing at max power. – bmike Jun 18 '11 at 0:58
  • 1
    @bmike I wouldn't be so sure about that, the rMBP is known to drain battery when sufficiently loaded on the CPU+GPU due to the 85W adapter providing insufficient current. – Steven Lu Jun 6 '13 at 3:41
  • 1
    @stevenlu I wouldn't be surprised if the latest 2013 era hardware pushes harder than the mid 2010 era tech that's being discussed here. Similarly, power management on 10.8 is more sophisticated than 10.6 was. Also - they draw hard on the internal battery - just not so much from the AC adapter in my experience. Even the new USB-C PD models follow that pattern of heavy internal consumption / buffered + lighter external consumption – bmike Jun 6 '13 at 9:24
3

I've made a little script based on system_profiler output. It calculates the wattage using the given voltage and amperes.

powerstat() {
    b=$(system_profiler SPPowerDataType)
    amp=$(echo "$b" | grep 'Amperage (mA):' | cut -d ':' -f 2 | xargs)
    volt=$(echo "$b" | grep 'Voltage (mV):' | cut -d ':' -f 2 | xargs)
    power=$(($amp * $volt / 1000))
    echo "$b" | grep --color=never -A 1 'Battery Information:'
    echo "$b" | grep --color=never -A 1 'Amperage (mA)'
    echo "      Total Power (mW): $power"
    echo ""
    echo "$b" | grep --color=never -A 99 'AC Charger Information:'
}

Outputs something like:

$ powerstat
    Battery Information:

      Amperage (mA): -552
      Voltage (mV): 12794
      Total Power (mW): -7062

    AC Charger Information:

      Connected: No
      Charging: No

When charging:

$ powerstat
    Battery Information:

      Amperage (mA): 1545
      Voltage (mV): 12850
      Total Power (mW): 19853

    AC Charger Information:

      Connected: Yes
      Wattage (W): 60
      Charging: No
2
// Build with: gcc psudata.cc -o psudata -framework IOKit
#include <stdio.h>
#include <string.h>
#include <IOKit/IOKitLib.h>

typedef struct {
  uint32_t key;
  char ignored[24];
  uint32_t size;
  char ignored2[10];
  char cmd;
  char ignored3[5];
  float val;
  char ignored4[28];
} smc_t;

int main(void) {
  mach_port_t mp;
  CFMutableDictionaryRef d;
  io_iterator_t it;
  io_object_t svc;
  io_connect_t ioc;
  smc_t req, resp;
  size_t sz = sizeof(resp);
  uint32_t vk  = ('V' << 24) + ('D' << 16) + ('0' << 8) + 'R';
  uint32_t ik  = ('I' << 24) + ('D' << 16) + ('0' << 8) + 'R';
  float v, i;

  IOMasterPort(MACH_PORT_NULL, &mp);
  d = IOServiceMatching("AppleSMC");
  IOServiceGetMatchingServices(mp, d, &it);
  svc = IOIteratorNext(it);
  IOObjectRelease(it);
  IOServiceOpen(svc, mach_task_self(), 0, &ioc);
  IOObjectRelease(svc);
  memset(&req, 0, sizeof(smc_t));
  memset(&resp, 0, sizeof(smc_t));
  req.cmd = 5;
  req.size = 4;
  req.key = vk;
  IOConnectCallStructMethod(ioc, 2, &req, sizeof(req), &resp, &sz);
  v = resp.val;
  req.key = ik;
  IOConnectCallStructMethod(ioc, 2, &req, sizeof(req), &resp, &sz);
  i = resp.val;
  IOServiceClose(ioc);

  printf("%fV %fA %fW\n", v, i, v*i);
  return 0;
}
  • Actually answered the wrong question, sorry... I came here as a result of a search for the charge voltage and current from a USB-C charger... and since I didn't find it, figured the above out, and posted it here. But it's not actually what you wanted; you could probably combine the DC input data (this) with the battery data (other answers) to infer the usage data. – Luyer May 12 '17 at 5:16
2
system_profiler SPPowerDataType | grep Wattage

Does the trick for me on MacBook Pro (15-inch, 2016)!

  • 2
    This reports the wattage of the AC adapter, not current power consumption. For context: system_profiler SPPowerDataType | grep -C4 Wattage – Edward Anderson Feb 12 '18 at 15:19
2

Here's an ioreg command that prints most of the power information without 'grep'. It returns much faster than system_profiler on my machine, so probably more suitable for being scripted or run in the background.

ioreg -w 0 -f -r -c AppleSmartBattery
1

I am on a MacBook 10.6.8 and ioreg -l | grep LegacyBatteryInfo worked for me.

I previously tried

ioreg -l | grep LegacyBatteryInfo | \
    cut -d '{' -f 2 | tr -d \} | tr ',' '=' | \
    awk -F'=' '{print ($2*$10/10^22)}' 

and it returned 0.

Is there a solution from Apple's Dev library?

Why not look outside on the power meter? Record your readings and then correlate to a constant and common %CPU usage. Then you can get a approximation.

0

I think that for 10.7 this should work from the terminal:

ioreg -l | grep LegacyBatteryInfo | cut -d '{' -f 2 | tr -d \} | tr ',' '=' | awk -F'=' '{print ($2*$10/10^22)}'

  • 2
    ioreg -l | grep LegacyBatteryInfo returns nothing for me on iMac. – Jari Keinänen Mar 23 '12 at 5:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .