Precision timer in Android JNI

I am trying to profile a JNI application. Is there something like β€œGet ticks from launch” that I can use to measure functions and / or systems? Anything with an accuracy of 1/10 millisecond will do.

Obviously, a fully native function would be nicer, I would prefer not to call the Java function for every single thing that I am trying to profile, but if this is the only option, I will do it too.

+7
source share
2 answers

clock_gettime (). You will see sample code in android-ndk-r5b / samples / hello-neon / jni / helloneon.c and android-ndk-r5b / samples / native-plasma / jni / plasma.c.

You want to find something like CLOCK_MONOTONIC to make sure you get ticks from the moment you start, not the wall clock.

+15
source

Take a look at

System.currentTimeMillis(); 

and / or

 System.nanoTime(); 

I don't think this is the time since launch, but they are milliseconds of timestamps that you can use.

+2
source

All Articles