More on OS X Mavericks Power Usage

The “Energy Impact” tab in OS X 10.9 Mavericks’ Activity Monitor is exactly what I would’ve wanted when I was testing my new Macbook Air a few months ago. Although, one thing I’ve found is that the “Avg Energy Impact” (it averages over the past 8 hours) isn’t actually a very useful/stable number, at least for measuring something that can have a very variable/spiky usage, like browsing with lots of tabs.

I knew if it was in Activity Monitor though, that the raw data must be available, and after some fruitless online searching, I just dug around my system and ended up finding some cool stuff in /usr/bin. First is a script called power_usage.sh that dumps out a report of lots of technical details.

Here’s a small sample of the output:

**** Battery and backlight usage ****

Backlight level: 862 (range 0-1024)


**** Network activity ****

out: 1.00 packets/s, 94.29 bytes/s
in:  1.50 packets/s, 212.53 bytes/s


**** Disk activity ****

read: 0.00 ops/s 0.00 KBytes/s
write: 5.49 ops/s 32.70 KBytes/s

****  Interrupt distribution ****

CPU 0:
	Vector 0x46(SMC): 2.99 interrupts/sec
	Vector 0x49(MacBookAir6,1): 0.50 interrupts/sec
	Vector 0x92(IGPU): 107.76 interrupts/sec
	Vector 0x98(ARPT): 9.48 interrupts/sec
	Vector 0x9e(SSD0): 3.99 interrupts/sec
	Vector 0xdd(TMR): 691.96 interrupts/sec
	Vector 0xde(IPI): 8.98 interrupts/sec
CPU 1:
	Vector 0xdd(TMR): 6.49 interrupts/sec
	Vector 0xde(IPI): 3.99 interrupts/sec
CPU 2:
	Vector 0xdd(TMR): 16.46 interrupts/sec
	Vector 0xde(IPI): 8.98 interrupts/sec
CPU 3:
	Vector 0xdd(TMR): 8.48 interrupts/sec
	Vector 0xde(IPI): 2.49 interrupts/sec



**** Processor usage ****

Intel energy model derived package power (CPUs+GT+SA): 0.58W

LLC flushed residency: 93.2%

System Average frequency as fraction of nominal: 85.75% (1457.75 Mhz)
Package 0 C-state residency: 93.81% (C2: 13.45% C3: 0.07% C6: 0.00% C7: 80.29% C8: 0.00% C9: 0.00% C10: 0.00% )

Core 0 C-state residency: 96.16% (C3: 0.00% C6: 0.00% C7: 96.16% )

CPU 0 duty cycles/s: active/idle [< 16 us: 20.45/11.47] [< 32 us: 7.98/15.96] [< 64 us: 70.34/13.47] [< 128 us: 23.45/11.97] [< 256 us: 14.97/6.49] [< 512 us: 18.46/2.00] [< 1024 us: 4.99/4.49] [< 2048 us: 3.49/8.98] [< 4096 us: 2.00/12.97] [< 8192 us: 0.00/24.45] [< 16384 us: 0.00/26.94] [< 32768 us: 0.00/26.94] 
CPU Average frequency as fraction of nominal: 77.55% (1318.39 Mhz)

CPU 1 duty cycles/s: active/idle [< 16 us: 15.47/4.49] [< 32 us: 1.00/2.49] [< 64 us: 2.99/2.00] [< 128 us: 1.50/0.50] [< 256 us: 4.49/1.00] [< 512 us: 1.00/1.50] [< 1024 us: 1.00/1.50] [< 2048 us: 0.50/0.50] [< 4096 us: 0.00/0.50] [< 8192 us: 0.00/2.49] [< 16384 us: 0.00/2.99] [< 32768 us: 0.00/0.00] 
CPU Average frequency as fraction of nominal: 83.51% (1419.63 Mhz)

Core 1 C-state residency: 96.81% (C3: 0.01% C6: 0.00% C7: 96.81% )

CPU 2 duty cycles/s: active/idle [< 16 us: 68.35/4.49] [< 32 us: 8.98/5.49] [< 64 us: 5.49/17.96] [< 128 us: 6.49/12.97] [< 256 us: 7.98/13.47] [< 512 us: 2.99/7.48] [< 1024 us: 2.00/2.49] [< 2048 us: 1.00/2.49] [< 4096 us: 0.00/0.50] [< 8192 us: 0.50/7.98] [< 16384 us: 0.00/9.98] [< 32768 us: 0.50/7.98] 
CPU Average frequency as fraction of nominal: 94.05% (1598.86 Mhz)

CPU 3 duty cycles/s: active/idle [< 16 us: 9.48/1.50] [< 32 us: 2.00/2.49] [< 64 us: 0.50/2.00] [< 128 us: 3.99/0.00] [< 256 us: 1.00/1.50] [< 512 us: 1.50/0.50] [< 1024 us: 1.00/0.50] [< 2048 us: 0.00/0.00] [< 4096 us: 0.50/0.50] [< 8192 us: 0.50/0.00] [< 16384 us: 0.00/2.99] [< 32768 us: 0.00/1.50] 
CPU Average frequency as fraction of nominal: 96.73% (1644.44 Mhz)

**** GPU usage ****

GPU 0 name IntelIG
GPU 0 C-state residency: 99.73% (0.00%, 99.73%)
GPU 0 P-state residency: 1100MHz: 0.00%, 1050MHz: 0.00%, 1000MHz: 0.00%, 950MHz: 0.00%, 900MHz: 0.00%, 850MHz: 0.00%, 800MHz: 0.00%, 750MHz: 0.00%, 700MHz: 0.00%, 650MHz: 0.00%, 600MHz: 0.00%, 550MHz: 0.00%, 500MHz: 0.00%, 450MHz: 0.00%, 400MHz: 0.00%, 350MHz: 0.28%, 300MHz: 0.00%, 250MHz: 0.00%, 200MHz: 0.00%
GPU 0 average frequency as fraction of nominal (200.00Mhz): 0.49% (0.98Mhz)
GPU 0 GPU Busy 0.28%
GPU 0 FB Test Case 0.00%

Most of the best stuff is coming from /usr/bin/powermetrics. Here's the man page for powermetrics. There's a lot of options to go through.

I couldn't get some of the --hide flags to work, but here's a quick command to pull just the power score from some apps. Suffice to say, the possibilities for this in doing power comparison are quite tantalizing:

powermetrics -i 1000 --poweravg 1 | grep 'Average cumulatively decayed power score' -A 20

Example output:

--
**** Average cumulatively decayed power score ****

                          	15 sec    	1 min     	5 min     	15 min    	1 hr
[26367]systemstats         	   157.144	   43.3773	   15.5405	
[0   ]kernel_task         	   74.2694	   74.8748	   47.8391	
[-1  ]DEAD_TASKS          	   48.8577	   24.5274	   6.72759	
[123 ]WindowServer        	   30.0174	   35.1636	   21.6378	
[388 ]iTerm               	   21.9219	   20.0339	   12.7875	
[26917]Airmail             	   18.7339	   19.6338	   9.45401	
[41829]Google Chrome He    	   10.6604	   7.92617	   4.61903	
[42323]com.apple.WebKit    	   10.1828	   17.2152	    13.345	
[41206]Safari              	    9.1336	   16.8081	   10.7422	
[42352]Activity Monitor    	   7.60748	    6.4298	   3.80237	
[96  ]hidd                	      7.59	   7.70318	     4.438	
[42612]powermetrics        	   4.74147	   4.81903	   3.23933	
[37370]SystemUIServer      	   4.36079	   4.44251	   3.02667	
[159 ]sysmond             	   3.80035	   2.93568	   1.85484	
[442 ]Moom                	   3.53523	   2.59021	   1.21046	
[389 ]Dock                	   3.43152	   2.84213	   1.58266	

I also made another cool discovery for power measurement. Originally I first tried to see if Apple's top had the power information, but sadly, it appeared like it didn't. Well, it turns out that (and the top man page) was wrong - my 11" MBA's screen simply wasn't big enough (even maximized) to show the POWER column, opening top open on my bigger desktop screen showed that this wasn't the case!

So here's an equivalent "power" command for top:

top -stats pid,command,power -o power -l 0

And the output looks something like:

PID    COMMAND          POWER
123    WindowServer     31.1
388    iTerm            25.7
42689  top              10.5
96     hidd             2.9
26917  Airmail          1.4
37370  SystemUIServer   0.4
45     fseventsd        0.3
85     mds              0.1
42323  com.apple.WebKit 0.1
31927- Dropbox          0.1
31997  WebKitPluginHost 0.1
453-   Google Drive     0.1

It'd be pretty cool to make an open source power measuring/graphing framework combined w/ a browser automation test suite. I might get to it one day, but maybe someone w/ some more free time might feel like doing it sooner? Just putting it out there.