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
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
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.
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "../primitives.h"
|
|
|
|
namespace facebook::react {
|
|
|
|
using Clock = std::chrono::steady_clock;
|
|
using TimePoint = std::chrono::time_point<Clock>;
|
|
|
|
TEST(chronoToDOMHighResTimeStamp, withDurations) {
|
|
EXPECT_EQ(chronoToDOMHighResTimeStamp(std::chrono::nanoseconds(10)), 0.00001);
|
|
EXPECT_EQ(chronoToDOMHighResTimeStamp(std::chrono::microseconds(10)), 0.01);
|
|
EXPECT_EQ(chronoToDOMHighResTimeStamp(std::chrono::milliseconds(10)), 10.0);
|
|
EXPECT_EQ(chronoToDOMHighResTimeStamp(std::chrono::seconds(10)), 10000.0);
|
|
EXPECT_EQ(
|
|
chronoToDOMHighResTimeStamp(
|
|
std::chrono::seconds(1) + std::chrono::nanoseconds(20)),
|
|
1000.000020);
|
|
}
|
|
|
|
TEST(chronoToDOMHighResTimeStamp, withTimePoints) {
|
|
EXPECT_EQ(
|
|
chronoToDOMHighResTimeStamp(TimePoint(std::chrono::nanoseconds(10))),
|
|
0.00001);
|
|
EXPECT_EQ(
|
|
chronoToDOMHighResTimeStamp(TimePoint(std::chrono::microseconds(10))),
|
|
0.01);
|
|
EXPECT_EQ(
|
|
chronoToDOMHighResTimeStamp(TimePoint(std::chrono::milliseconds(10))),
|
|
10.0);
|
|
EXPECT_EQ(
|
|
chronoToDOMHighResTimeStamp(TimePoint(std::chrono::seconds(10))),
|
|
10000.0);
|
|
EXPECT_EQ(
|
|
chronoToDOMHighResTimeStamp(
|
|
TimePoint(std::chrono::seconds(1) + std::chrono::nanoseconds(20))),
|
|
1000.000020);
|
|
}
|
|
|
|
} // namespace facebook::react
|