How would you measure and optimize the CPU and battery consumption of a background service that runs continuously?