android clock_gettime ndk
For example, java.lang.System.nanoTime() is implemented with:
struct timespec now;clock_gettime(CLOCK_MONOTONIC, &now);return (u8)now.tv_sec*1000000000LL + now.tv_nsec;
NDK clock_gettime problem - android-ndk | Google グループ
260 /* 261 * static long nanoTime() 262 * 263 * Current monotonically-increasing time, in nanoseconds. This doesn't 264 * need to be internal to the VM, but we're already handling 265 * java.lang.System here. 266 */ 267 static void Dalvik_java_lang_System_nanoTime(const u4* args, JValue* pResult) 268 { 269 UNUSED_PARAMETER(args); 270 271 u8 when = dvmGetRelativeTimeNsec(); 272 RETURN_LONG(when); 273 }
533 /* 534 * Get a notion of the current time, in nanoseconds. This is meant for 535 * computing durations (e.g. "operation X took 52nsec"), so the result 536 * should not be used to get the current date/time. 537 */ 538 u8 dvmGetRelativeTimeNsec(void) 539 { 540 #ifdef HAVE_POSIX_CLOCKS 541 struct timespec now; 542 clock_gettime(CLOCK_MONOTONIC, &now); 543 return (u8)now.tv_sec*1000000000LL + now.tv_nsec; 544 #else 545 struct timeval now; 546 gettimeofday(&now, NULL); 547 return (u8)now.tv_sec*1000000000LL + now.tv_usec * 1000LL; 548 #endif 549 }