Loading include/utils/SystemClock.h +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ namespace android { int setCurrentTimeMillis(int64_t millis); int64_t uptimeMillis(); int64_t elapsedRealtime(); int64_t elapsedRealtimeNano(); }; // namespace android Loading include/utils/Timers.h +3 −2 Original line number Diff line number Diff line Loading @@ -78,7 +78,8 @@ enum { SYSTEM_TIME_REALTIME = 0, // system-wide realtime clock SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point SYSTEM_TIME_PROCESS = 2, // high-resolution per-process clock SYSTEM_TIME_THREAD = 3 // high-resolution per-thread clock SYSTEM_TIME_THREAD = 3, // high-resolution per-thread clock SYSTEM_TIME_BOOTTIME = 4 // same as SYSTEM_TIME_MONOTONIC, but including CPU suspend time }; // return the system-time according to the specified clock Loading libs/utils/SystemClock.cpp +24 −14 Original line number Diff line number Diff line Loading @@ -105,8 +105,23 @@ int64_t uptimeMillis() * native public static long elapsedRealtime(); */ int64_t elapsedRealtime() { return nanoseconds_to_milliseconds(elapsedRealtimeNano()); } /* * native public static long elapsedRealtimeNano(); */ int64_t elapsedRealtimeNano() { #ifdef HAVE_ANDROID_OS struct timespec ts; int result = clock_gettime(CLOCK_BOOTTIME, &ts); if (result == 0) { return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; } // CLOCK_BOOTTIME doesn't exist, fallback to /dev/alarm static int s_fd = -1; if (s_fd == -1) { Loading @@ -114,25 +129,20 @@ int64_t elapsedRealtime() if (android_atomic_cmpxchg(-1, fd, &s_fd)) { close(fd); } } struct timespec ts; int result = ioctl(s_fd, result = ioctl(s_fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts); } if (result == 0) { int64_t when = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; return (int64_t) nanoseconds_to_milliseconds(when); } else { return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; } // XXX: there was an error, probably because the driver didn't // exist ... this should return // a real error, like an exception! int64_t when = systemTime(SYSTEM_TIME_MONOTONIC); return (int64_t) nanoseconds_to_milliseconds(when); } return systemTime(SYSTEM_TIME_MONOTONIC); #else int64_t when = systemTime(SYSTEM_TIME_MONOTONIC); return (int64_t) nanoseconds_to_milliseconds(when); return systemTime(SYSTEM_TIME_MONOTONIC); #endif } Loading libs/utils/Timers.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ nsecs_t systemTime(int clock) CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID, CLOCK_BOOTTIME }; struct timespec t; t.tv_sec = t.tv_nsec = 0; Loading Loading
include/utils/SystemClock.h +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ namespace android { int setCurrentTimeMillis(int64_t millis); int64_t uptimeMillis(); int64_t elapsedRealtime(); int64_t elapsedRealtimeNano(); }; // namespace android Loading
include/utils/Timers.h +3 −2 Original line number Diff line number Diff line Loading @@ -78,7 +78,8 @@ enum { SYSTEM_TIME_REALTIME = 0, // system-wide realtime clock SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point SYSTEM_TIME_PROCESS = 2, // high-resolution per-process clock SYSTEM_TIME_THREAD = 3 // high-resolution per-thread clock SYSTEM_TIME_THREAD = 3, // high-resolution per-thread clock SYSTEM_TIME_BOOTTIME = 4 // same as SYSTEM_TIME_MONOTONIC, but including CPU suspend time }; // return the system-time according to the specified clock Loading
libs/utils/SystemClock.cpp +24 −14 Original line number Diff line number Diff line Loading @@ -105,8 +105,23 @@ int64_t uptimeMillis() * native public static long elapsedRealtime(); */ int64_t elapsedRealtime() { return nanoseconds_to_milliseconds(elapsedRealtimeNano()); } /* * native public static long elapsedRealtimeNano(); */ int64_t elapsedRealtimeNano() { #ifdef HAVE_ANDROID_OS struct timespec ts; int result = clock_gettime(CLOCK_BOOTTIME, &ts); if (result == 0) { return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; } // CLOCK_BOOTTIME doesn't exist, fallback to /dev/alarm static int s_fd = -1; if (s_fd == -1) { Loading @@ -114,25 +129,20 @@ int64_t elapsedRealtime() if (android_atomic_cmpxchg(-1, fd, &s_fd)) { close(fd); } } struct timespec ts; int result = ioctl(s_fd, result = ioctl(s_fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts); } if (result == 0) { int64_t when = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; return (int64_t) nanoseconds_to_milliseconds(when); } else { return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; } // XXX: there was an error, probably because the driver didn't // exist ... this should return // a real error, like an exception! int64_t when = systemTime(SYSTEM_TIME_MONOTONIC); return (int64_t) nanoseconds_to_milliseconds(when); } return systemTime(SYSTEM_TIME_MONOTONIC); #else int64_t when = systemTime(SYSTEM_TIME_MONOTONIC); return (int64_t) nanoseconds_to_milliseconds(when); return systemTime(SYSTEM_TIME_MONOTONIC); #endif } Loading
libs/utils/Timers.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ nsecs_t systemTime(int clock) CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID, CLOCK_BOOTTIME }; struct timespec t; t.tv_sec = t.tv_nsec = 0; Loading