mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45492 Changelog: [internal] When testing the changes in https://github.com/facebook/react-native/pull/45473 / D55491870, I saw that the reported time spans for long tasks didn't perfectly align with the long tasks themselves in traces (Perfetto). Taking a closer look, I realized that I wasn't doing the conversion between times and durations from `chrono` and `DOMHighResTimeStamp` (a `double`) correctly, and we're doing this conversion very often. This moves the definition of `DOMHighResTimeStamp` to its own library and adds conversion methods to make sure we don't make this mistake in the future. Reviewed By: rshest Differential Revision: D59820241 fbshipit-source-id: c123920de56336da384ddc484f6ac9d287724301
32 lines
943 B
C++
32 lines
943 B
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and 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 <chrono>
|
|
|
|
namespace facebook::react {
|
|
|
|
// `DOMHighResTimeStamp` represents a time value in milliseconds (time point or
|
|
// duration), with sub-millisecond precision.
|
|
// On the Web, the precision can be reduced for security purposes, but that is
|
|
// not necessary in React Native.
|
|
using DOMHighResTimeStamp = double;
|
|
|
|
inline DOMHighResTimeStamp chronoToDOMHighResTimeStamp(
|
|
std::chrono::steady_clock::duration duration) {
|
|
return static_cast<std::chrono::duration<double, std::milli>>(duration)
|
|
.count();
|
|
}
|
|
|
|
inline DOMHighResTimeStamp chronoToDOMHighResTimeStamp(
|
|
std::chrono::steady_clock::time_point timePoint) {
|
|
return chronoToDOMHighResTimeStamp(timePoint.time_since_epoch());
|
|
}
|
|
|
|
} // namespace facebook::react
|