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

Skip to first unread message

Kacper Kamieniarz

Jul 20, 2021, 4:15:31 PM7/20/21
to android-ndk
Hello, I've never used NDK but since I have a problem that strongly connects to hardware I figured maybe using NDK would be a solution. 

I have an application that uses OpenCV (in Java) 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
  1. public long filter(Mat input) {
  2.    long time = System.elapsedRealtime();
  4.    ...
  6.    return System.elapsedRealtime() - time;
  7. }

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)

Alex Cohn

Aug 22, 2021, 12:31:15 PM8/22/21
to android-ndk

Maybe the thread time will help you?



Aug 23, 2021, 11:21:46 AM8/23/21
to android-ndk
simpleperf is the command-line tool that collects the data shown in the Studio's profilers. the simpleperf documentation talks about how to control recording from your app (including an example). see for details.

You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages