NDK clock_gettime problem

3,956 views
Skip to first unread message

Mohs3n

unread,
Jan 30, 2011, 3:34:10 AM1/30/11
to android-ndk
Hello,

I'm trying to use clock_gettime in my game to calculate elapsed time
between each frame. However, the time I'm getting is not correct. I'm
using the method explained here http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/.

Has anyone been able to successfully utilize "time.h" in NDK?

провод

unread,
Jan 30, 2011, 3:45:41 AM1/30/11
to andro...@googlegroups.com
Hi.
Yes, I do successfully use clock_gettime in many projects and on lots
of phones, for both frame advance and benchmarking purposes.
Could you please be more specific about how its returned time is not correct?

2011/1/30 Mohs3n <moh...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

Message has been deleted

Mohs3n

unread,
Jan 30, 2011, 4:31:59 AM1/30/11
to android-ndk
I can run the same game on both Windows and Android platform and the
game feels like slow-motion on Android. My game is running in 60fps or
lower. But, the time steps I'm getting from clock_gettime (on Android)
is something from 0.009 to 0.016 seconds, which is clearly lower than
0.016 time steps which I get on average when running in 60fps. Any
idea what I might be doing wrong?

провод

unread,
Jan 30, 2011, 4:48:58 AM1/30/11
to andro...@googlegroups.com
What clock do you use?
If you use CLOCK_PROCESS_CPUTIME_ID or CLOCK_THREAD_CPUTIME_ID, then
you get time your process/thread spent, which is perfect for
benchmarking -- your deltas won't include other processes time, no
matter how much they take. But for the very same reason this is not
the time you'd like to use in your physics and game logic calculations
-- you won't get the real time spent, but somewhat smaller values,
and, therefore, weird-looking game slowdown. I assume that this is
what happens with your application.
For real time related calculations you should use CLOCK_MONOTONIC.

2011/1/30 Mohs3n <moh...@gmail.com>:


> I can run the same game on both Windows and Android platform and the
> game feels like slow-motion on Android. My game is running in 60fps or
> lower. But, the time steps I'm getting from clock_gettime (on Android)

> is something from 0.009 to 0.016 seconds, which is clearly lower that


> 0.016 time steps which I get on average when running in 60fps. Any
> idea what I might be doing wrong?
>

Mohs3n

unread,
Jan 30, 2011, 5:07:14 AM1/30/11
to android-ndk
I changed cpuid from CLOCK_PROCESS_CPUTIME_ID to CLOCK_MONOTONIC and
that fixed the slow-mo problem. Thanks for your advice.

Bill Hsu

unread,
Jan 30, 2011, 9:14:22 AM1/30/11
to andro...@googlegroups.com
I used to use gettimeofday, but the performance is really bad. clock_gettime works really well. 
Thanks.

On Sun, Jan 30, 2011 at 6:07 PM, Mohs3n <moh...@gmail.com> wrote:
I changed cpuid from CLOCK_PROCESS_CPUTIME_ID to CLOCK_MONOTONIC and
that fixed the slow-mo problem. Thanks for your advice.

--
Reply all
Reply to author
Forward
0 new messages