/* * 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 #include "NativePerformanceObserver.h" #include "PerformanceEntryReporter.h" #include "Plugins.h" std::shared_ptr NativePerformanceObserverModuleProvider( std::shared_ptr jsInvoker) { return std::make_shared( std::move(jsInvoker)); } namespace facebook::react { NativePerformanceObserver::NativePerformanceObserver( std::shared_ptr 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(entryType)); } void NativePerformanceObserver::stopReporting( jsi::Runtime &rt, int32_t entryType) { PerformanceEntryReporter::getInstance().stopReporting( static_cast(entryType)); } GetPendingEntriesResult NativePerformanceObserver::popPendingEntries( jsi::Runtime &rt) { return PerformanceEntryReporter::getInstance().popPendingEntries(); } void NativePerformanceObserver::setOnPerformanceEntryCallback( jsi::Runtime &rt, std::optional> callback) { PerformanceEntryReporter::getInstance().setReportingCallback(callback); } void NativePerformanceObserver::logRawEntry( jsi::Runtime &rt, RawPerformanceEntry entry) { PerformanceEntryReporter::getInstance().logEntry(entry); } std::vector> NativePerformanceObserver::getEventCounts(jsi::Runtime &rt) { const auto &eventCounts = PerformanceEntryReporter::getInstance().getEventCounts(); return std::vector>( eventCounts.begin(), eventCounts.end()); } void NativePerformanceObserver::setDurationThreshold( jsi::Runtime &rt, int32_t entryType, double durationThreshold) { PerformanceEntryReporter::getInstance().setDurationThreshold( static_cast(entryType), durationThreshold); } void NativePerformanceObserver::clearEntries( jsi::Runtime &rt, int32_t entryType, std::optional entryName) { PerformanceEntryReporter::getInstance().clearEntries( static_cast(entryType), entryName ? entryName->c_str() : nullptr); } std::vector NativePerformanceObserver::getEntries( jsi::Runtime &rt, std::optional entryType, std::optional entryName) { return PerformanceEntryReporter::getInstance().getEntries( entryType ? static_cast(*entryType) : PerformanceEntryType::UNDEFINED, entryName ? entryName->c_str() : nullptr); } } // namespace facebook::react