Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High-precision timer in Android JNI

I'm trying to profile my JNI application. Is there something like "Get ticks since startup" that I can use to measure functions and/or systems? Anything with the precision of 1/10 of a millisecond will do.

Obviously, a fully native function would be nicer, I'd prefer not to call a Java function for every single thing I'm trying to profile, but if that's the only option, I'll take that too.

like image 311
EboMike Avatar asked Feb 20 '11 00:02

EboMike


1 Answers

clock_gettime(). You'll 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 look for something like CLOCK_MONOTONIC to make sure you're getting ticks since startup, not the wall clock.

like image 181
James Moore Avatar answered Sep 19 '22 11:09

James Moore