3 `perf` is a powerful system-wide instrumentation service that is part of
4 Linux. This article discusses how it can be relevant to power profiling.
6 **Note**: The [power profiling
7 overview](power_profiling_overview.md) is
8 worth reading at this point if you haven't already. It may make parts
9 of this document easier to understand.
13 `perf` can access the Intel RAPL energy estimates. The following example
14 shows how to invoke it for this purpose.
17 sudo perf stat -a -r 1 \
18 -e "power/energy-pkg/" \
19 -e "power/energy-cores/" \
20 -e "power/energy-gpu/" \
21 -e "power/energy-ram/" \
25 The `-a` is necessary; it means \"all cores\", and without it all the
26 measurements will be zero. The `-r 1` means `<command>` is executed
27 once; higher values can be used to get variations.
29 The output will look like the following.
32 Performance counter stats for 'system wide':
34 51.58 Joules power/energy-pkg/ [100.00%]
35 14.80 Joules power/energy-cores/ [100.00%]
36 9.93 Joules power/energy-gpu/ [100.00%]
37 27.38 Joules power/energy-ram/ [100.00%]
39 5.003049064 seconds time elapsed
42 It's not clear from the output, but the following relationship holds.
45 energy-pkg >= energy-cores + energy-gpu
48 The measurement is in Joules, which is usually less useful than Watts.
51 [rapl](tools_power_rapl.md) is usually a
52 better tool for measuring power consumption on Linux.
56 `perf` can also be used to do [high-context profiling of
57 wakeups](http://robertovitillo.com/2014/02/04/idle-wakeups-are-evil/).