Site icon Android Tutorial Online

A proof-of-concept experiment of Gradle build energy consumption monitoring

Set up the environment

Java >= 14 is required, tested with Java 17.

CVE-2020-8694 caused all Linux distributions to change the permissions of the RAPL files. They can only be read by root.

Change the files permissions in order for this experiment to run:

chmod a+r /sys/class/powercap/intel-rapl/intel-rapl:1/energy_uj

Note that the above is not persistent and will be reset on reboot. This can be persistently changed with:

sudo apt install sysfsutils
echo "mode class/powercap/intel-rapl:1/energy_uj = 0444" | sudo tee -a /etc/sysfs.conf > /dev/null
sudo reboot # CAREFUL!

Try it out

By running the following command you will build the plugin locally and run a task that does some work:

./gradlew work

If you want to try it on your own build you can include the plugin build and apply the plugin in your settings:

settings.gradle.kts

pluginManagement {
    includeBuild("<path-to-this-repository>/gradle-energy-consumption-plugin")
}
plugins {
    id("energy-consumption")
}

Publish a build scan to see the attached custom values

./gradlew work --scan
https://ge.gradle.org/s/b4fymgqi3rxj4/custom-values

GitHub

View Github

Exit mobile version