Bug 1804798 - Explicitly set auto page name (and corresponding debug flag) when inser...
[gecko.git] / docs / performance / activity_monitor_and_top.md
blob4e687c4dfed65a29d923cba43ce66de06239e455
1 # Activity Monitor, Battery Status Menu and top
3 This article describes the Activity Monitor, Battery Status Menu, and
4 `top` --- three related tools available on Mac OS X.
6 **Note**: The [power profiling overview](power_profiling_overview.md) is
7 worth reading at this point if you haven't already. It may make parts
8 of this document easier to understand.
10 ## Activity Monitor
12 This is a [built-in OS X tool](https://support.apple.com/en-au/HT201464)
13 that shows real-time process measurements. It is well-known and its
14 "Energy Impact" measure is likely to be consulted by users to compare
15 the power consumption of different programs. ([Apple support
16 documentation](https://support.apple.com/en-au/HT202776) specifically
17 recommends it for troubleshooting battery life problems.)
18 ***Unfortunately "Energy Impact" is not a good measure for either
19 users or software developers and it should be avoided.*** Activity
20 Monitor can still be useful, however.
22 ### Power-related measurements
24 Activity Monitor has several tabs. They can all be customized to show
25 any of the available measurements (by right-clicking on the column
26 strip) but only the "Energy" tab groups child processes with parent
27 processes, which is useful, so it's the best one to use. The following
28 screenshot shows a customized "Energy" tab.
30 ![](img/ActMon-Energy.png)
32 The power-related columns are as follows.
34 -   **Energy Impact** / **Avg Energy Impact**: See the separate section
35     below.
36 -   **% CPU**: CPU usage percentage. This can exceed 100% if multiple
37     cores are being used.
38 -   **Idle wake Ups**:
39     -   In Mac OS 10.9 this measured "package idle exit" wakeups. This
40         is the same value as
41         [powermetrics](./powermetrics.md)'
42         "Pkg idle" measurement (i.e.
43         `task_power_info::task_platform_idle_wakeups` obtained from the
44         `task_info` function.)
45     -   In Mac OS 10.10 it appears to have been changed to measure
46         interrupt-level wakeups (a superset of idle wakeups), which are
47         less interesting. This is the same value as
48         [powermetrics](./powermetrics.md)'
49         "Intr" measurement (i.e.
50         `task_power_info::task_interrupt_wakeups` obtained from the
51         `task_info` function.)
52 -   **Requires High Perf GPU**: Many Macs have two GPUs: a low-power,
53     low-performance integrated GPU, and a high-power, high-performance
54     external GPU. Using the high-performance GPU can greatly increase
55     power consumption, and should be avoided whenever possible. This
56     column indicates which GPU is being used.
58 Activity Monitor can be useful for cursory measurements, but for more
59 precise and detailed measurements other tools such as
60 [powermetrics](./powermetrics.md) are better.
62 ### What does "Energy Impact" measure?
64 "Energy Impact" is a hybrid proxy measure of power consumption.
65 [Careful
66 investigation](https://blog.mozilla.org/nnethercote/2015/08/26/what-does-the-os-x-activity-monitors-energy-impact-actually-measure/)
67 indicates that on Mac OS 10.10 and 10.11 it is computed with a formula
68 that is machine model-specific, and includes the following factors: CPU
69 usage, wakeup frequency, [quality of service
70 class](https://developer.apple.com/library/prerelease/mac/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html)
71 usage, and disk, GPU, and network activity. The weightings of each
72 factor can be found in one of the the files in
73 `/usr/share/pmenergy/Mac-<id>.plist`, where `<id>` can be determined
74 with the following command.
76     ioreg -l | grep board-id
78 In contrast, on Mac OS 10.9 it is computed via a simpler machine
79 model-independent formula that only factors in CPU usage and wakeup
80 frequency.
82 In both cases "Energy Impact" often correlates poorly with actual
83 power consumption and should be avoided in favour of direct measurements
84 that have clear physical meanings.
86 ### What does "Average Energy Impact" measure?
88 When the Energy tab of Activity Monitor is first opened, the "Average
89 Energy Impact" column is empty and the title bar says "Activity
90 Monitor (Processing\...)". After 5--10 seconds, the "Average Energy
91 Impact" column is populated with values and the title bar changes to
92 "Activity Monitor (Applications in last 8 hours)". If you have `top`
93 open during those 5--10 seconds you'll see that `systemstats` is
94 running and using a lot of CPU, and so presumably the measurements are
95 obtained from it.
97 `systemstats` is a program that runs continuously and periodically
98 measures, among other things, CPU usage and idle wakeups for each
99 running process. Tests indicate that it is almost certainly using the
100 same "Energy Impact" formula to compute the "Average Energy Impact",
101 using measurements from the past 8 hours of wake time (i.e. if a laptop
102 is closed for several hours and then reopened, those hours are not
103 included in the calculation.)
105 ## Battery status menu
107 When you click on the battery icon in the OS X menu bar you get a
108 drop-down menu that includes a list of "Apps Using Significant Energy".
109 This is crude but prominent, and therefore worth understanding --- even
110 though it's not much use for profiling applications.
112 ![Screenshot of the OS X battery statusmenu](img/battery-status-menu.png)
114 When you open this menu for the first time in a while it says
115 "Collecting Power Usage Information" for a few seconds, and if you have
116 `top` open during that time you'll see that, once again, `systemstats`
117 is running and using a lot of CPU. Furthermore, if you click on an
118 application name in the menu Activity Monitor will be opened and that
119 application's entry will be highlighted. Based on these facts it seems
120 reasonable to assume that "Energy Impact" is again being used to
121 determine which applications are "using significant energy".
123 Testing shows that once an energy-intensive application is started it
124 takes less than a minute for it to show up in the battery status menu.
125 And once the application stops using high amounts of energy it takes a
126 few minutes to disappear. The exception is when the application is
127 closed, in which case it disappears immediately. And it appears that a
128 program with an "Energy Impact" of roughly 20 or more will eventually
129 show up as significant, and programs that have much higher "Energy
130 Impact" values tend to show up more quickly.
132 All of these battery status menu observations are difficult to make
133 reliably and so should be treated with caution. It is clear, however,
134 that the window used by the battery status menu is measured in seconds
135 or minutes, which is much less than the 8 hour window used for "Average
136 Energy Impact" in Activity Monitor.
138 ## `top`
140 `top` is similar to Activity Monitor, but is a command-line utility. To
141 see power-related measurements, invoke it as follows.
144 top -stats pid,command,cpu,idlew,power -o power -d
147 **Note**: `-a` and `-e` can be used instead of `-d` to get different
148 counting modes. See the man page for details.
150 It will show periodically-updating data like the following.
152     PID            COMMAND                  %CPU         IDLEW        POWER
153     50300          firefox                  12.9         278          26.6
154     76256          plugin-container         3.4          159          11.3
155     151            coreaudiod               0.9          68           4.3
156     76505          top                      1.5          1            1.6
157     76354          Activity Monitor         1.0          0            1.0
159 -   The **PID**, **COMMAND** and **%CPU** columns are self-explanatory.
160 -   The **IDLEW** column is the number of "package idle exit" wakeups.
161 -   The **POWER** column's value is computed by the same formula as the
162     one used for "Energy Impact" by Activity Monitor in Mac OS 10.9,
163     and should also be avoided.
165 `top` is unlikely to be much use for power profiling.