detect where your code consumes energy the most so you can optimize those functions
Joulehunter helps you find what part of your code is consuming considerable amounts of energy.
This repo is still a work in progress. 😄
Joulehunter runs on Linux machines with Intel RAPL support. This technology has been available since the Sandy Bridge generation.
You can install joulehunter with pip:
pip install joulehunter.
You can also clone the repo and install it directly:
git clone https://github.com/powerapi-ng/joulehunter.git cd joulehunter python setup.py install
Joulehunter works similarly to pyinstrument, as we forked the repo and replaced time measuring with energy measuring. Here's pyinstrument's documentation. Whenever
pyinstrument is present in a variable name, it should be replaced with
joulehunter (for example,
PYINSTRUMENT_PROFILE_DIR turns into
joulehunter -l will list the available domains on this machine. These include the packages and their components, such as the DRAM and core.
joulehunter main.py will execute
main.py and measure the energy consumption of the first package (CPU).
To select the package to analyze use the option
--package followed by the package number or the package name. The default value is 0.
--component allow you to measure the energy of an individual component by specifying their name or ID. If not specified, the entire package will be selected.
joulehunter -l could output this:
 package-0  core  uncore  dram  package-1  core  uncore  dram
If we run
joulehunter -p package-1 -c 2 my_file.py, joulehunter will execute
my_file.py and measure the energy consumption of package-1's DRAM.
Profiling chunks of code
As pyinstrument's documentation shows, it's also possible to profile specific chunks of code.
Joulehunter's Profiler class can receive two additional arguments:
component. They receive the ID (as a string or integer) or name of the desired package/component. If
package is not specified,
package-0 will be used. If
None, the entire package will be analyzed.
Profiling web requests in Flask
Please refer to pyinstrument's documentation for instructions on how to profile web requests in Flask. As in the previous case, joulehunter's
Profiler() accepts two additional arguments.
Profiling web requests in Django
Profiling web requests in Django as explained in pyinstrument's documentation selects package 0 as the default domain (don't forget to rename the
pyinstrument in variable names with
The user can choose a particular package and component as follows:
Query component: The query strings
component are used to select the desired package and component. For example, including
?profiler&package=0&component=dram at the end of a request URL will select the first package and the DRAM. If the component query component is present but empty, the package will be analyzed.
settings.py: The user's selection can also be defined in
settings.py with the
JOULEHUNTER_COMPONENT variables. These are later passed to
If the package or component is defined both as a query component and in
settings.py, the one defined as a query component will be selected.
Due to a security vulnerability, only root has read permission for the energy files. In order to circumvent this, run the script as root or grant read permissions for the following files:
More info here.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.