mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
aee88b6843
Summary: Changelog: [General] [Fixed] - License header cleanup Reviewed By: yungsters Differential Revision: D17952693 fbshipit-source-id: 8fcb8e58a2e04e7a3169f4d525bffc00835768e6
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <time.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
inline static int64_t getTime() {
|
|
#ifdef ANDROID
|
|
static const int64_t NANOSECONDS_IN_SECOND = 1000000000LL;
|
|
static const int64_t NANOSECONDS_IN_MILLISECOND = 1000000LL;
|
|
|
|
// 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, &now);
|
|
int64_t nano = now.tv_sec * NANOSECONDS_IN_SECOND + now.tv_nsec;
|
|
return nano / NANOSECONDS_IN_MILLISECOND;
|
|
#else
|
|
return 0l;
|
|
#endif
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|