Files
react-native/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntry.h
T
Ruslan Lesiutin f03268b896 Replace DOMHighResTimeStamp alias in ReactCommon with new abstractions (#51512)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51512

Pull Request resolved: https://github.com/facebook/react-native/pull/50585

# Changelog: [Internal]

Replaces `DOMHighResTimeStamp` alias completely in `ReactCommon` with `HighResTimeStamp`.

`DOMHighResTimeStamp` as a type is now expected to be used only in JavaScript.

I didn't update places where we explcitly use `std::chrono::high_resolution_clock`, since it is platform-specific and there is no guarantee that `std::chrono::high_resolution_clock` == `std::chrono::steady_clock`.

Also, places that are isolated and not part of the Web Performance APIs, such as Telemetry for Fabric, are not updates as part of this diff. Although these subsystems are also using `std::chrono::steady_clock` as a low-level representation, they are not sharing it with other parts of the React Native core.

Reviewed By: rubennorte

Differential Revision: D75185613

fbshipit-source-id: 889719368de163e6f529689df6cc16d816fde66c
2025-05-22 10:16:45 -07:00

93 lines
2.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.
*/
#pragma once
#include <react/timing/primitives.h>
#include <optional>
#include <string>
#include <variant>
namespace facebook::react {
using PerformanceEntryInteractionId = uint32_t;
enum class PerformanceEntryType {
// We need to preserve these values for backwards compatibility.
MARK = 1,
MEASURE = 2,
EVENT = 3,
LONGTASK = 4,
RESOURCE = 5,
_NEXT = 6,
};
struct AbstractPerformanceEntry {
std::string name;
HighResTimeStamp startTime;
HighResDuration duration = HighResDuration::zero();
};
struct PerformanceMark : AbstractPerformanceEntry {
static constexpr PerformanceEntryType entryType = PerformanceEntryType::MARK;
};
struct PerformanceMeasure : AbstractPerformanceEntry {
static constexpr PerformanceEntryType entryType =
PerformanceEntryType::MEASURE;
};
struct PerformanceEventTiming : AbstractPerformanceEntry {
static constexpr PerformanceEntryType entryType = PerformanceEntryType::EVENT;
HighResTimeStamp processingStart;
HighResTimeStamp processingEnd;
PerformanceEntryInteractionId interactionId;
};
struct PerformanceLongTaskTiming : AbstractPerformanceEntry {
static constexpr PerformanceEntryType entryType =
PerformanceEntryType::LONGTASK;
};
struct PerformanceResourceTiming : AbstractPerformanceEntry {
static constexpr PerformanceEntryType entryType =
PerformanceEntryType::RESOURCE;
/** Aligns with `startTime`. */
HighResTimeStamp fetchStart;
HighResTimeStamp requestStart;
std::optional<HighResTimeStamp> connectStart;
std::optional<HighResTimeStamp> connectEnd;
std::optional<HighResTimeStamp> responseStart;
/** Aligns with `duration`. */
std::optional<HighResTimeStamp> responseEnd;
std::optional<int> responseStatus;
};
using PerformanceEntry = std::variant<
PerformanceMark,
PerformanceMeasure,
PerformanceEventTiming,
PerformanceLongTaskTiming,
PerformanceResourceTiming>;
struct PerformanceEntrySorter {
bool operator()(const PerformanceEntry& lhs, const PerformanceEntry& rhs) {
return std::visit(
[](const auto& left, const auto& right) {
if (left.startTime != right.startTime) {
return left.startTime < right.startTime;
}
return left.duration < right.duration;
},
lhs,
rhs);
}
};
} // namespace facebook::react