Check out this article on how to get started with automation using C#. It shows few useful patterns to automatically compute the energy consumption for a specific part of the measurement of the energy consumption of your device.
Comments welcome below!