mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c1023c73b0
Summary: This diff adds the `performance.reactNativeStartupTiming` API to the performance global object for RN. This property does not exist in web, and we are free to make up our own list of properties in the startup metrics to track RN app startup process. In our case, we have the following six properties to begin with (we may extend and add more to this list in the future): ``` - `(start|end)Time`: The time ‘zero’ for the startup timing and the end of app startup. RN has no knowledge of app start time, which will be provided by the platform. The `endTime` will be the time when the first JS bundle finishes executing (Note that RN supports multiple JS bundles, which can be loaded async) - `executeJavaScriptBundleEntryPoint(Start|End)`: The time for RN to execute the JS entry point (and finish all sync job) ``` Changelog: [General][Added] - Add new JS performance API to support getting RN app startup timings Reviewed By: rshest Differential Revision: D43326564 fbshipit-source-id: 7b4c7cae70ff64ba1714a1630cd5e183df6c06b0
86 lines
2.5 KiB
C++
86 lines
2.5 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 <memory>
|
|
|
|
#include <cxxreact/ReactMarker.h>
|
|
#include <jsi/instrumentation.h>
|
|
#include "NativePerformance.h"
|
|
#include "PerformanceEntryReporter.h"
|
|
|
|
#include "Plugins.h"
|
|
|
|
std::shared_ptr<facebook::react::TurboModule> NativePerformanceModuleProvider(
|
|
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
|
|
return std::make_shared<facebook::react::NativePerformance>(
|
|
std::move(jsInvoker));
|
|
}
|
|
|
|
namespace facebook::react {
|
|
|
|
NativePerformance::NativePerformance(std::shared_ptr<CallInvoker> jsInvoker)
|
|
: NativePerformanceCxxSpec(std::move(jsInvoker)) {}
|
|
|
|
void NativePerformance::mark(
|
|
jsi::Runtime &rt,
|
|
std::string name,
|
|
double startTime,
|
|
double duration) {
|
|
PerformanceEntryReporter::getInstance().mark(name, startTime, duration);
|
|
}
|
|
|
|
void NativePerformance::measure(
|
|
jsi::Runtime &rt,
|
|
std::string name,
|
|
double startTime,
|
|
double endTime,
|
|
std::optional<double> duration,
|
|
std::optional<std::string> startMark,
|
|
std::optional<std::string> endMark) {
|
|
PerformanceEntryReporter::getInstance().measure(
|
|
name, startTime, endTime, duration, startMark, endMark);
|
|
}
|
|
|
|
std::unordered_map<std::string, double> NativePerformance::getSimpleMemoryInfo(
|
|
jsi::Runtime &rt) {
|
|
auto heapInfo = rt.instrumentation().getHeapInfo(false);
|
|
std::unordered_map<std::string, double> heapInfoToJs;
|
|
for (auto &entry : heapInfo) {
|
|
heapInfoToJs[entry.first] = static_cast<double>(entry.second);
|
|
}
|
|
return heapInfoToJs;
|
|
}
|
|
|
|
ReactNativeStartupTiming NativePerformance::getReactNativeStartupTiming(
|
|
jsi::Runtime &rt) {
|
|
ReactNativeStartupTiming result = {0, 0, 0, 0};
|
|
result.startTime = ReactMarker::getAppStartTime();
|
|
|
|
auto startupReactMarkers =
|
|
ReactMarker::StartupLogger::getInstance().getStartupReactMarkers();
|
|
for (const auto &startupReactMarker : startupReactMarkers) {
|
|
auto time = startupReactMarker.time;
|
|
switch (startupReactMarker.markerId) {
|
|
case ReactMarker::ReactMarkerId::RUN_JS_BUNDLE_START:
|
|
result.executeJavaScriptBundleEntryPointStart = time;
|
|
break;
|
|
|
|
case ReactMarker::ReactMarkerId::RUN_JS_BUNDLE_STOP:
|
|
result.executeJavaScriptBundleEntryPointEnd = time;
|
|
result.endTime = time;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace facebook::react
|