Measure energy consumption at source code level
My opinion
How useful is it to record energy consumption at code level in your own development environment?
In my view, there is only one positive aspect, but several negative aspects.
Positive:
- Displaying the energy consumption of individual function calls directly within your own code editor can certainly help to raise awareness of resource consumption and provide incentives to optimize consumption. Using a profiler manually is not always a matter of course in day-to-day development work. Having a tool running in the background that displays the hotspots directly in the code when running tests can be beneficial.
Negative:
- Why try to measure energy consumption when a profiler is sufficient to achieve the goals? In the development environment, the use of a classic profiler to record resource consumption (CPU, memory, network) should be sufficient to identify and optimize bottlenecks and hotspots.
- The development environment is usually very different from the production environment. Therefore, recording energy consumption in the development environment is only of limited use and makes more sense in an environment where the environment is more similar to a production environment (e.g. integration environment).
- Precisely measuring the energy consumption of individual processes or even methods is complex. Especially when many things are running in parallel on the same system. This is the case in the development environment. A measurement in an environment prepared for energy measurements, which can also be used for a representative comparison between versions (see Green Metrics Tool), provides a remedy.
- What is the significance of recording the energy consumption of an individual function? This can be helpful for a complex algorithm, but not for typical applications with distributed network calls and database queries.
Tools
NodeJS
Oaklean
Purpose: Measure energy consumption of NodeJS applications
Website: https://www.oaklean.io/
Source code: https://github.com/hitabisgmbh/oaklean
Java
JoularJX
Purpose: Java-based agent for software power monitoring at the source code level
Website: https://www.noureddine.org/research/joular/joularjx
Source code: https://github.com/joular/joularjx
jPowerMonitor
Purpose: Measure energy consumption of Java applications
Website: https://github.com/msg-systems/jpowermonitor
Python
pyJoules
Purpose: Measure energy consumption of Python code snippets
Website: https://github.com/powerapi-ng/pyJoules
CodeCarbon
Purpose: Estimate CO2 emissions of Python applications
Website: https://codecarbon.io/
Source code: https://github.com/mlco2/codecarbon