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

41 views
Skip to first unread message

Kacper Kamieniarz

unread,
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();
  3.  
  4.    ...
  5.  
  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

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

Maybe the thread time will help you?

BR
Alex

enh

unread,
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 https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/android_application_profiling.md#control-recording-in-application-code 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 android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/51ebeae7-dccf-4c41-a1ce-e551fb0cb952n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages