34

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?

3
  • 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, 2011 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, 2011 at 18:02
  • @msanford it might help—if someone tells us how to read the readings from the PSU. Jun 20, 2011 at 12:21

16 Answers 16

38

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.

8
  • 2
    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. Jun 26, 2011 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. Jan 25, 2017 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, 2017 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, 2017 at 16:01
  • 1
    That's pretty good, but seems to show battery power only. The results are off when power adapter is connected. If the load is just right, I can see e.g. 80 mA or -120 mA. 🤣
    – user55379
    Mar 17, 2020 at 10:26
17

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
4
  • 1
    lol, I love the "Amperage" = 18446744073709551614 value. I'm guessing 1.8 or so? Dec 16, 2020 at 23:45
  • 1
    This works well on MBP13 M1. Jun 23, 2021 at 8:05
  • 4
    18446744073709551614 is 0xFFFFFFFFFFFFFFFE and probably means "don't know".
    – Michael
    Nov 12, 2021 at 12:46
  • @Jeshizaemon It seems to be negative value (discharging) displayed as unsigned, see apple.stackexchange.com/a/468996 for convering
    – Pavel
    Feb 5 at 19:14
12

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. :-)

1
  • 5
    Par excellence! Now the question is: how do iStat Menus get the sensor readings… Jun 18, 2011 at 14:24
9

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.

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.

4
  • 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, 2011 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. Jun 29, 2011 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? Jun 29, 2011 at 23:55
  • 3
    Unfortunately Hardware Monitor announced EOL on June 19, 2017. bresink.com/osx/216202/eol.html
    – walterra
    Sep 8, 2017 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

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
6
  • 1
    i'm using Monterrey, it displays an error on multiplier powerstat:4: bad math expression: operand expected at * / 1000'` it seems like $amp and $volt are not correctly extracted from $b Apr 8, 2022 at 22:04
  • 1
    @genuinefafa: I suppose you have an M1 or M2 based Mac?
    – ikaerom
    Jul 16, 2022 at 16:47
  • @Moreaki 2,2G i7; i don't have any "Amperage (mA)" or "Voltage (mV)" on system_profiler SPPowerDataType dump Aug 4, 2022 at 15:51
  • @genuinefafa Not exactly sure what you refer to with "2,2G i7". I reckon it's not M1 or M2, rather an Intel based. That's weird, then, since powerstat should potentially show Amperage and Voltage on Intel.
    – ikaerom
    Aug 5, 2022 at 19:43
  • 1
    @serialx I am on an M1 MBP and the Amperage and Voltage lines are not present in the output of system_profiler SPPowerDataType which causes the error. Jul 22, 2023 at 15:20
6

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.

4
  • 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. Jun 17, 2011 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, 2011 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, 2013 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, 2013 at 9:24
3
// 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;
}
2
  • 1
    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, 2017 at 5:16
  • Thanks for this code -- where can I find documentation on the struct you called smc_t?
    – drewster
    Apr 24, 2023 at 16:54
2
system_profiler SPPowerDataType | grep Wattage

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

1
  • 7
    This reports the wattage of the AC adapter, not current power consumption. For context: system_profiler SPPowerDataType | grep -C4 Wattage Feb 12, 2018 at 15:19
2

According to marchdown's answer, I add an alias in ~/.zshrc as

alias wat="system_profiler SPPowerDataType | grep 'Wattage'"

so when I type "wat" it outputs

Wattage (W): 18

Hope this helps you

0
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.

1

After taking reference to responses from this and other similar threads, I ended up making a small utility function. This only uses pre-installed dependencies. Cross verified the generated output with exelban/stats.

Tested on: MBP M1 Pro 2021

Output: (current / capacity)

43 W / 140 W

Script:

get_current_watt () {
  CHARGING=$(ioreg -rw0 -c AppleSmartBattery | egrep '^\s+"IsCharging"' | cut -d"=" -f2 | xargs)
  if [[ "No" == "$CHARGING" ]]
  then
    echo "--"
  else
    VOLT=$(ioreg -rw0 -c AppleSmartBattery | egrep '^\s+"Voltage"' | cut -d"=" -f2 | xargs)
    AMP=$(ioreg -rw0 -c AppleSmartBattery | egrep '^\s+"Amperage"' | cut -d"=" -f2 | xargs)
    WATT=$(($VOLT*$AMP/1000000))
    CAPACITY=$(ioreg -rw0 -c AppleSmartBattery | egrep '^\s+"AdapterDetails"' | sed -r 's/.*"Watts"=([0-9]+).*/\1/g')
    echo $WATT" W / $CAPACITY W"
  fi
}

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)}'

1
  • 2
    ioreg -l | grep LegacyBatteryInfo returns nothing for me on iMac. Mar 23, 2012 at 5:56
0

Based on @Luyer's amazing answer (reading charger voltage and current from SMC) and a list of SMC keys from here: we can read many other values, like the requested "current wattage" a.k.a. total system power draw, just by replacing the queried key.

// Build with: gcc psudata.cc -o psudata -framework IOKit

// original code from https://apple.stackexchange.com/a/283403 by Luyer, modified by M-1

#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;

float get_value(io_connect_t * ioc, uint32_t key) {
  smc_t req, resp;
  size_t sz = sizeof(resp);

  memset(&req, 0, sizeof(smc_t));
  memset(&resp, 0, sizeof(smc_t));
  req.cmd = 5;
  req.size = 4;
  req.key = key;
  IOConnectCallStructMethod(*ioc, 2, &req, sizeof(req), &resp, &sz);
  return resp.val;
}

int main(void) {
  mach_port_t mp;
  CFMutableDictionaryRef d;
  io_iterator_t it;
  io_object_t svc;
  io_connect_t ioc;
  float v, i, system_total;

  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);

  // SMC keys/"codes" can be found at https://logi.wiki/index.php/SMC_Sensor_Codes
  v = get_value(&ioc, ('V' << 24) + ('D' << 16) + ('0' << 8) + 'R');
  i = get_value(&ioc, ('I' << 24) + ('D' << 16) + ('0' << 8) + 'R');
  system_total = get_value(&ioc, ('P' << 24) + ('S' << 16) + ('T' << 8) + 'R');

  IOServiceClose(ioc);

  printf("DC In: %fV %fA %fW\n", v, i, v*i);
  printf("System Total: %fW\n", system_total);
  return 0;
}

This example code and a pre-built binary showing the current total power draw are on GitHub; additional things like adding more keys to read from SMC (or better parsing them from process arguments), repeating the reading at an interval or better-machine-readable output formatting are left as an exercise to the reader.

(Adding this to the existing answer would be better, if I had enough reputation to post comments.)

Edit: I just discovered istats which might be easier to use (istats scan).

0

Here is working version, based on @gub answer + @serialx answer + fixed for M1 (Apple Silicon)

wattage() {
    info=$(ioreg -w 0 -f -r -c AppleSmartBattery)
    vol=$(echo $info | grep '"Voltage" = ' | grep -oE '\d+') 
    amp=$(echo $info | grep '"Amperage" = ' | grep -oE '\d+')
    amp=$(bc <<< "if ($amp >= 2^63) $amp - 2^64 else $amp")
    wat="$(( (vol / 1000.0) * (amp / 1000.0) ))"
    printf "%.3f\n" $wat
}

Now typing wattage in terminal will show current [dis]charging speed in W (watt)

~ % wattage
-7.491

Negative value means that battery is discharging, charger seems not connected (or giving low power which is less than power consumption).

Positive value means that battery is charging.

The value should be equal to (charger wattage) minus (laptop consumption wattage).


Note: bc is used to convert unsigned 64-bit integer to signed, e.g 18446744073709551090 to -526

Note: to check just charger power, follow https://discussions.apple.com/thread/8008792

You must log in to answer this question.

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