Implement reporting of events from native side to WebPerformance API (#35768)

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

Changelog: [Internal]

This implements native side mechanics for reporting user events timing to JS  (PerformanceObserver API).

See the standard for more details: https://www.w3.org/TR/event-timing/

The events are only logged when there are any active subscriptions (via `PerformanceObserver.observe`), also we only log "discrete events" (i.e. no likes of mouse move), so the overhead is non-existing.

There are two main metrics of interest for an event lifecycle:
* Time the event is spent in the queue, i.e. the time between it's created and dispatched
* Time that is spend in the event handler on the JS side (event dispatch), or processing time

Both of these are measured, and the corresponding fields are populated.

Reviewed By: sammy-SC

Differential Revision: D42294947

fbshipit-source-id: 4fd7938c04b942400befa4057d4929fb2763cee1
This commit is contained in:
Ruslan Shestopalyuk
2023-01-03 11:11:37 -08:00
committed by Facebook GitHub Bot
parent 28a06d2fd1
commit 09ad0cc0c6
13 changed files with 224 additions and 22 deletions
@@ -6,7 +6,6 @@
*/
#include "NativePerformanceObserver.h"
#include <glog/logging.h>
#include "PerformanceEntryReporter.h"
namespace facebook::react {
@@ -28,7 +27,13 @@ static PerformanceEntryType stringToPerformanceEntryType(
NativePerformanceObserver::NativePerformanceObserver(
std::shared_ptr<CallInvoker> jsInvoker)
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {}
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {
setEventLogger(&PerformanceEntryReporter::getInstance());
}
NativePerformanceObserver::~NativePerformanceObserver() {
setEventLogger(nullptr);
}
void NativePerformanceObserver::startReporting(
jsi::Runtime &rt,