9

To the best of my knowledge, MacBooks will still charge if the power supply attached provides less wattage then the laptop was designed for. Is there a way to view the current power input, preferably a simple terminal command, or would that be impossible/always the same for some reason?

If relevant, I have a MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports), but would like a way that works on other models as well.

1 Answer 1

15

There is a straightforward way to determine instantaneous* battery charging current, assuming you have developer tools installed:

ioreg -rw0 -c AppleSmartBattery | grep -o -e '"ChargingCurrent"=[0-9]*'

The number is specified in milliamps.

However, this is not going to be the same as the current entering through your AC adapter (this is most apparent when the battery is fully charged, in which case the current will be 0), so it may not help you with what you're doing. I'm not aware of a place where that information gets published, although the PMU must certainly measure it.

Similarly, you can view the instantaneous* voltage of the battery, in millivolts, with

ioreg -rw0 -c AppleSmartBattery | grep -o -e '"Voltage" = [0-9]*'

which, when multiplied by the above current, will give you the power being delivered to the battery (in microwatts, so divide by a factor of 1,000,000 to get watts). But, again, it is not the same as the power being delivered by the AC adapter.

You can view more power-related parameters with

ioreg -rw0 -c AppleSmartBattery

Update:

I experimented on two systems – a T2-based MBP with Catalina and a non-T2-based MBP with Big Sur – and found that the former has the keys AdapterPower and SystemPower contained in the BatteryData dictionary property of AppleSmartBattery:

"BatteryData" = {"StateOfCharge"=98,"PMUConfigured"=0,"DesignCapacity"=8790,"QmaxCell1"=9017,"AdapterPower"=1101610469,"SystemPower"=1104635067,"ResScale"=244,"QmaxCell2"=9048,"QmaxCell0"=9082,"CycleCount"=69,"Voltage"=12503}

So this is a promising source for determining both the power being delivered by the AC adapter as well as the power being consumed by the system. These, along with the earlier battery charge current & voltage that I showed, could give you a pretty complete picture of the power situation.

I couldn't figure out the units at first, since the numbers are too high to be W, mW, and even µW, and too low to be nW. Then I remembered that some keys are stored as floating point values, and when I converted 1101610469 into an IEEE-754 float, I got the very reasonable-looking 21.1552219391, which means that it's published in units of watts.

You can therefore – on at least certain hardware or software – view the AC adapter power consumption with

ioreg -rw0 -c AppleSmartBattery | grep BatteryData | grep -o '"AdapterPower"=[0-9]*' | cut -c 16- | xargs -I %  lldb --batch -o "print/f %" | grep -o '$0 = [0-9.]*' | cut -c 6-

and system power consumption with

ioreg -rw0 -c AppleSmartBattery | grep BatteryData | grep -o '"SystemPower"=[0-9]*' | cut -c 16- | xargs -I %  lldb --batch -o "print/f %" | grep -o '$0 = [0-9.]*' | cut -c 6-

This uses lldb to do the IEEE-754 conversion, so you, again, will need developer tools installed. It is also very straightforward to write a small CLI tool that uses the IOKit framework to dump these out without needing Xcode installed on the target system, if you needed to have that.

* - Note that these values only seem to update once a minute or so, so they aren't truly instantaneous.

5
  • Very detailed and hasty reply; thanks! Not that it really matters, but you wrote "Note that these values only seem to update once a minute or so, so they aren't instantaneous." Any idea why that might be? I would just go on the sane assumption that ioreg reads the data as soon as it's run and doesn't just sit there running 24/7 caching data in case you need it, so is it that the components themselves update some memory with the values every ~1 minute, and not when demanded by a program? Mar 10, 2021 at 22:38
  • @PixelatedFish To reduce SMC resource usage no doubt. The SMC is a low-power microcontroller and blasting frequent advisory updates would consume the limited clock and interface cycles available.
    – pion
    Mar 10, 2021 at 22:41
  • ioreg isn’t involved in this. It’s just a tool for traversing IORegistry, which is where AppleSmartBatteryManager publishes these advisory properties. ioreg does not cache anything. The properties themselves get updated by the drivers.
    – pion
    Mar 10, 2021 at 22:44
  • I am using a M2 13' MacBook Pro. When I grab the AdaptorPower number, it is hovering around 935466485. The conversion to watts is 0.0000231368267, which kinda means it uses x1000,000 less power, compared to your example of around 20 watts. Does this make sense or has the units changed?
    – Jake
    Jun 16, 2023 at 11:00
  • 1
    You can pass -a to ioreg to get the output in XML (plist) format. You can then pipe this result into plutil -extract to extract values. Ex. ioreg -rw0 -a -c AppleSmartBattery | plutil -extract '0.AdapterDetails.AdapterID' raw. This is more precise than grepping. Jul 14, 2023 at 14:52

You must log in to answer this question.

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