Files
react-native/ReactCommon/utils/TimeUtils.h
T
Valentin Shergin 4803cab8c4 Fabric: MountingTelemetry and refinments in TimeUtils
Summary: This diff implements encapsulating all time metrics in a single class for better extensibility and readability.

Reviewed By: JoshuaGross

Differential Revision: D15179835

fbshipit-source-id: 62bdf94435a0d37a87ad9bad613cc8e38043a235
2019-05-03 15:11:34 -07:00

33 lines
1.0 KiB
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#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