Add performance.memory API

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
This commit is contained in:
Xin Chen
2023-02-15 20:52:48 -08:00
committed by Facebook GitHub Bot
parent ee4714e369
commit 70fb2dce45
5 changed files with 102 additions and 0 deletions
@@ -7,6 +7,7 @@
#include "NativePerformance.h"
#include <glog/logging.h>
#include <jsi/instrumentation.h>
#include "PerformanceEntryReporter.h"
namespace facebook::react {
@@ -46,4 +47,14 @@ void NativePerformance::clearMeasures(
PerformanceEntryReporter::getInstance().clearMeasures(measureName);
}
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;
}
} // namespace facebook::react