/* * 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 #include #include "NativePerformance.h" #include "PerformanceEntryReporter.h" #include "Plugins.h" std::shared_ptr NativePerformanceModuleProvider( std::shared_ptr jsInvoker) { return std::make_shared( std::move(jsInvoker)); } namespace facebook::react { NativePerformance::NativePerformance(std::shared_ptr jsInvoker) : NativePerformanceCxxSpec(std::move(jsInvoker)) {} void NativePerformance::mark( jsi::Runtime& rt, std::string name, double startTime) { PerformanceEntryReporter::getInstance().mark(name, startTime); } void NativePerformance::measure( jsi::Runtime& rt, std::string name, double startTime, double endTime, std::optional duration, std::optional startMark, std::optional endMark) { PerformanceEntryReporter::getInstance().measure( name, startTime, endTime, duration, startMark, endMark); } std::unordered_map NativePerformance::getSimpleMemoryInfo( jsi::Runtime& rt) { auto heapInfo = rt.instrumentation().getHeapInfo(false); std::unordered_map heapInfoToJs; for (auto& entry : heapInfo) { heapInfoToJs[entry.first] = static_cast(entry.second); } return heapInfoToJs; } std::unordered_map NativePerformance::getReactNativeStartupTiming(jsi::Runtime& rt) { std::unordered_map result; ReactMarker::StartupLogger& startupLogger = ReactMarker::StartupLogger::getInstance(); if (!std::isnan(startupLogger.getAppStartupStartTime())) { result["startTime"] = startupLogger.getAppStartupStartTime(); } else if (!std::isnan(startupLogger.getInitReactRuntimeStartTime())) { result["startTime"] = startupLogger.getInitReactRuntimeStartTime(); } if (!std::isnan(startupLogger.getInitReactRuntimeStartTime())) { result["initializeRuntimeStart"] = startupLogger.getInitReactRuntimeStartTime(); } if (!std::isnan(startupLogger.getRunJSBundleStartTime())) { result["executeJavaScriptBundleEntryPointStart"] = startupLogger.getRunJSBundleStartTime(); } if (!std::isnan(startupLogger.getRunJSBundleEndTime())) { result["executeJavaScriptBundleEntryPointEnd"] = startupLogger.getRunJSBundleEndTime(); } if (!std::isnan(startupLogger.getInitReactRuntimeEndTime())) { result["initializeRuntimeEnd"] = startupLogger.getInitReactRuntimeEndTime(); } if (!std::isnan(startupLogger.getAppStartupEndTime())) { result["endTime"] = startupLogger.getAppStartupEndTime(); } return result; } } // namespace facebook::react