From 4eecab3a76f7ee3ba34681219a3ebb031f64867f Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 16 Dec 2022 11:45:06 -0800 Subject: [PATCH] API to report events Summary: Extends the WebPerformance API with ability to report events, [according to the standard](https://www.w3.org/TR/event-timing/#sec-performance-event-timing). This is an API-only change, the actual reporting comes in a separate diff, to simplify reviewing. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D42097695 fbshipit-source-id: d8b468ffed50c1c3d889151df5e8ca644d6e1a68 --- .../NativePerformanceObserver.cpp | 4 ++++ .../NativePerformanceObserver.h | 4 ++-- .../NativePerformanceObserver.js | 2 ++ .../PerformanceEntryReporter.cpp | 20 +++++++++++++++++++ .../WebPerformance/PerformanceEntryReporter.h | 13 +++++++++++- .../WebPerformance/PerformanceObserver.js | 8 ++++++-- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Libraries/WebPerformance/NativePerformanceObserver.cpp b/Libraries/WebPerformance/NativePerformanceObserver.cpp index 16070de5c40..89a69216a9a 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.cpp +++ b/Libraries/WebPerformance/NativePerformanceObserver.cpp @@ -17,6 +17,10 @@ static PerformanceEntryType stringToPerformanceEntryType( return PerformanceEntryType::MARK; } else if (entryType == "measure") { return PerformanceEntryType::MEASURE; + } else if (entryType == "event") { + return PerformanceEntryType::EVENT; + } else if (entryType == "first-input") { + return PerformanceEntryType::FIRST_INPUT; } else { return PerformanceEntryType::UNDEFINED; } diff --git a/Libraries/WebPerformance/NativePerformanceObserver.h b/Libraries/WebPerformance/NativePerformanceObserver.h index 37bb1462ad6..dbef244feb6 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.h +++ b/Libraries/WebPerformance/NativePerformanceObserver.h @@ -26,7 +26,7 @@ using RawPerformanceEntry = NativePerformanceObserverCxxBaseRawPerformanceEntry< // For "event" entries only: std::optional, std::optional, - std::optional>; + std::optional>; template <> struct Bridging @@ -37,7 +37,7 @@ struct Bridging double, std::optional, std::optional, - std::optional> {}; + std::optional> {}; using GetPendingEntriesResult = NativePerformanceObserverCxxBaseGetPendingEntriesResult< diff --git a/Libraries/WebPerformance/NativePerformanceObserver.js b/Libraries/WebPerformance/NativePerformanceObserver.js index f2446622084..c74c98b699b 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.js +++ b/Libraries/WebPerformance/NativePerformanceObserver.js @@ -16,6 +16,8 @@ export const RawPerformanceEntryTypeValues = { UNDEFINED: 0, MARK: 1, MEASURE: 2, + EVENT: 3, + FIRST_INPUT: 4, }; export type RawPerformanceEntryType = number; diff --git a/Libraries/WebPerformance/PerformanceEntryReporter.cpp b/Libraries/WebPerformance/PerformanceEntryReporter.cpp index 75436ad7ed7..b78184408c9 100644 --- a/Libraries/WebPerformance/PerformanceEntryReporter.cpp +++ b/Libraries/WebPerformance/PerformanceEntryReporter.cpp @@ -167,6 +167,26 @@ double PerformanceEntryReporter::getMarkTime( } } +void PerformanceEntryReporter::event( + const std::string &name, + double startTime, + double duration, + bool isFirstInput, + double processingStart, + double processingEnd, + uint32_t interactionId) { + logEntry( + {name, + static_cast( + isFirstInput ? PerformanceEntryType::FIRST_INPUT + : PerformanceEntryType::MEASURE), + startTime, + duration, + processingStart, + processingEnd, + interactionId}); +} + void PerformanceEntryReporter::clearEntries( std::function predicate) { int lastPos = entries_.size() - 1; diff --git a/Libraries/WebPerformance/PerformanceEntryReporter.h b/Libraries/WebPerformance/PerformanceEntryReporter.h index 9aacbde2312..d53f8ba535c 100644 --- a/Libraries/WebPerformance/PerformanceEntryReporter.h +++ b/Libraries/WebPerformance/PerformanceEntryReporter.h @@ -45,7 +45,9 @@ enum class PerformanceEntryType { UNDEFINED = 0, MARK = 1, MEASURE = 2, - _COUNT = 3, + EVENT = 3, + FIRST_INPUT = 4, + _COUNT = 5, }; class PerformanceEntryReporter { @@ -88,6 +90,15 @@ class PerformanceEntryReporter { const std::optional &endMark); void clearMeasures(const std::optional &measureName); + void event( + const std::string &name, + double startTime, + double duration, + bool isFirstInput, + double processingStart, + double processingEnd, + uint32_t interactionId); + private: PerformanceEntryReporter() {} diff --git a/Libraries/WebPerformance/PerformanceObserver.js b/Libraries/WebPerformance/PerformanceObserver.js index cf763e73018..ed95f2db795 100644 --- a/Libraries/WebPerformance/PerformanceObserver.js +++ b/Libraries/WebPerformance/PerformanceObserver.js @@ -19,7 +19,7 @@ import NativePerformanceObserver, { } from './NativePerformanceObserver'; export type HighResTimeStamp = number; -export type PerformanceEntryType = 'mark' | 'measure'; +export type PerformanceEntryType = 'mark' | 'measure' | 'event' | 'first-input'; export class PerformanceEntry { name: string; @@ -62,6 +62,10 @@ function rawToPerformanceEntryType( return 'mark'; case RawPerformanceEntryTypeValues.MEASURE: return 'measure'; + case RawPerformanceEntryTypeValues.EVENT: + return 'event'; + case RawPerformanceEntryTypeValues.FIRST_INPUT: + return 'first-input'; default: throw new TypeError( `unexpected performance entry type received: ${type}`, @@ -311,7 +315,7 @@ export default class PerformanceObserver { } static supportedEntryTypes: $ReadOnlyArray = - Object.freeze(['mark', 'measure']); + Object.freeze(['mark', 'measure', 'event', 'first-input']); } function union(a: $ReadOnlySet, b: $ReadOnlySet): Set {