Is it possible to programmatically measure methods CPU time? (not execution time)

I have an application that uses OpenCV to process images from the camera in real-time. The processing consists of several steps, wrapped in separate methods like filtering, thresholding, etc. I would like to have an estimate of CPU time used by each of the methods to make an estimate of their energy consumption. I know that I could do something like

public long filter(Mat input) {
   long time = System.elapsedRealtime();

   return System.elapsedRealtime() - time;

to get the execution time of each method call but I think since I'd like to correlate it with energy consumption it would not be precise enough. Is there some way to maybe get the total CPU time of the current process? (I know in Android Studio's Energy Profiler I could trace CPU time of methods but I wanted to know if this is achievable at runtime programmatically)