Reputation: 77
I know there are a lot of similar-sounding questions here, but I've looked at plenty of them and haven't found a definite answer if what I'd like to do is possible or not.
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)
Upvotes: 0
Views: 245
Reputation: 76
Are you looking for something like this:
public long filter(Mat input) {
long start = System.nanoTime();
// code you're measuring goes here
long duration = System.nanoTime() - start;
// log this duration somehow?
return result;
}
Upvotes: 0