开发者

High-precision timer in Android JNI

开发者 https://www.devze.com 2023-02-12 17:03 出处:网络
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? Any开发者_开发知识库thing with the precision of 1/10

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? Any开发者_开发知识库thing 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消