mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f76d4dee6f
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36116 [Changelog][Internal] Add a minimal/reference JavaScript implementation for NativePerformanceObserver - the purpose is both unit testing (JS and native sides separately) and potentially shimming the part of functionality that is not dependent on native side. This is both a setup for adding general unit tests for the Performance* APIs, but also to be able to do non-trivial changes on JS side for WebPerformance (such as in (D43154319). Reviewed By: rubennorte Differential Revision: D43167392 fbshipit-source-id: 213d9534d810dece1dd464f910e92e08dbf39508
55 lines
1.6 KiB
C++
55 lines
1.6 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 "NativePerformanceObserver.h"
|
|
#include "PerformanceEntryReporter.h"
|
|
|
|
namespace facebook::react {
|
|
|
|
NativePerformanceObserver::NativePerformanceObserver(
|
|
std::shared_ptr<CallInvoker> jsInvoker)
|
|
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {
|
|
setEventLogger(&PerformanceEntryReporter::getInstance());
|
|
}
|
|
|
|
NativePerformanceObserver::~NativePerformanceObserver() {
|
|
setEventLogger(nullptr);
|
|
}
|
|
|
|
void NativePerformanceObserver::startReporting(
|
|
jsi::Runtime &rt,
|
|
int32_t entryType) {
|
|
PerformanceEntryReporter::getInstance().startReporting(
|
|
static_cast<PerformanceEntryType>(entryType));
|
|
}
|
|
|
|
void NativePerformanceObserver::stopReporting(
|
|
jsi::Runtime &rt,
|
|
int32_t entryType) {
|
|
PerformanceEntryReporter::getInstance().stopReporting(
|
|
static_cast<PerformanceEntryType>(entryType));
|
|
}
|
|
|
|
GetPendingEntriesResult NativePerformanceObserver::popPendingEntries(
|
|
jsi::Runtime &rt) {
|
|
return PerformanceEntryReporter::getInstance().popPendingEntries();
|
|
}
|
|
|
|
void NativePerformanceObserver::setOnPerformanceEntryCallback(
|
|
jsi::Runtime &rt,
|
|
std::optional<AsyncCallback<>> callback) {
|
|
PerformanceEntryReporter::getInstance().setReportingCallback(callback);
|
|
}
|
|
|
|
void NativePerformanceObserver::logRawEntry(
|
|
jsi::Runtime &rt,
|
|
RawPerformanceEntry entry) {
|
|
PerformanceEntryReporter::getInstance().logEntry(entry);
|
|
}
|
|
|
|
} // namespace facebook::react
|