High-precision timer in Android JNI

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 08:45:54

问题


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.


回答1:


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.




回答2:


Take a look at

System.currentTimeMillis();

and/or

System.nanoTime();

I don't think either of those are time since startup, but they are both millisecnond timestamps that you may be able to use.



来源:https://stackoverflow.com/questions/5054376/high-precision-timer-in-android-jni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!