mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
70fb2dce45
Summary: This diff adds new performance API `memory`, which is a read-only property that gets the current JS heap size from native side. Note that the JSI API returns an unordered map with unknown list of memory information, which is different from the [web spec](https://fburl.com/p0vpbt33). We may enforce specific memory info type on the JSI API so that it can be properly translate to the web spec. - Update the JS spec - Update Native implementation and return memory information with JSI API `jsi::instrumentation()::getHeapInfo()` - Add native performance module to catalyst package Changelog: [General][Added] - Add performance memory API with native memory Info Reviewed By: rubennorte Differential Revision: D43137071 fbshipit-source-id: 319f1a6ba78fce61e665b00849ecf2579094af83
59 lines
1.8 KiB
C++
59 lines
1.8 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "NativePerformanceObserver.h"
|
|
|
|
namespace facebook::react {
|
|
class PerformanceEntryReporter;
|
|
|
|
#pragma mark - Structs
|
|
|
|
#pragma mark - implementation
|
|
|
|
class NativePerformance : public NativePerformanceCxxSpec<NativePerformance>,
|
|
std::enable_shared_from_this<NativePerformance> {
|
|
public:
|
|
NativePerformance(std::shared_ptr<CallInvoker> jsInvoker);
|
|
|
|
void
|
|
mark(jsi::Runtime &rt, std::string name, double startTime, double duration);
|
|
void clearMarks(jsi::Runtime &rt, std::optional<std::string> markName);
|
|
|
|
void 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);
|
|
void clearMeasures(jsi::Runtime &rt, std::optional<std::string> measureName);
|
|
|
|
// To align with web API, we will make sure to return three properties
|
|
// (jsHeapSizeLimit, totalJSHeapSize, usedJSHeapSize) + anything needed from
|
|
// the VM side.
|
|
// `jsHeapSizeLimit`: The maximum size of the heap, in bytes, that
|
|
// is available to the context.
|
|
// `totalJSHeapSize`: The total allocated heap size, in bytes.
|
|
// `usedJSHeapSize`: The currently active segment of JS heap, in
|
|
// bytes.
|
|
//
|
|
// Note that we use int64_t here and it's ok to lose precision in JS doubles
|
|
// for heap size information, as double's 2^53 sig bytes is large enough.
|
|
std::unordered_map<std::string, double> getSimpleMemoryInfo(jsi::Runtime &rt);
|
|
|
|
private:
|
|
};
|
|
|
|
} // namespace facebook::react
|