From 434ca242ecab07f226f0639715e4151cd4824731 Mon Sep 17 00:00:00 2001 From: Alexey Lang Date: Fri, 10 Mar 2017 10:10:35 -0800 Subject: [PATCH] Use CLOCK_MONOTONIC instead of CLOCK_MONOTONIC_RAW in performanceNow Reviewed By: AaaChiuuu Differential Revision: D4688909 fbshipit-source-id: 30d02ea6af4cce47bcd4fe41bc1f048dccbb3b2b --- ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp index 3b067be0f..dc084b123 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp @@ -73,9 +73,15 @@ static JSValueRef nativePerformanceNow( static const int64_t NANOSECONDS_IN_SECOND = 1000000000LL; static const int64_t NANOSECONDS_IN_MILLISECOND = 1000000LL; - // This is equivalent to android.os.SystemClock.elapsedRealtime() in native + // Since SystemClock.uptimeMillis() is commonly used for performance measurement in Java + // and uptimeMillis() internally uses clock_gettime(CLOCK_MONOTONIC), + // we use the same API here. + // We need that to make sure we use the same time system on both JS and Java sides. + // Links to the source code: + // https://android.googlesource.com/platform/frameworks/native/+/jb-mr1-release/libs/utils/SystemClock.cpp + // https://android.googlesource.com/platform/system/core/+/master/libutils/Timers.cpp struct timespec now; - clock_gettime(CLOCK_MONOTONIC_RAW, &now); + clock_gettime(CLOCK_MONOTONIC, &now); int64_t nano = now.tv_sec * NANOSECONDS_IN_SECOND + now.tv_nsec; return Value::makeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND)); }