diff --git a/packages/react-native/ReactCommon/jsi/jsi/decorator.h b/packages/react-native/ReactCommon/jsi/jsi/decorator.h index 4dd955be04e..07705161702 100644 --- a/packages/react-native/ReactCommon/jsi/jsi/decorator.h +++ b/packages/react-native/ReactCommon/jsi/jsi/decorator.h @@ -412,12 +412,16 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { plain().instrumentation().stopHeapSampling(os); } - void createSnapshotToFile(const std::string& path) override { - plain().instrumentation().createSnapshotToFile(path); + void createSnapshotToFile( + const std::string& path, + const HeapSnapshotOptions& options) override { + plain().instrumentation().createSnapshotToFile(path, options); } - void createSnapshotToStream(std::ostream& os) override { - plain().instrumentation().createSnapshotToStream(os); + void createSnapshotToStream( + std::ostream& os, + const HeapSnapshotOptions& options) override { + plain().instrumentation().createSnapshotToStream(os, options); } std::string flushAndDisableBridgeTrafficTrace() override { diff --git a/packages/react-native/ReactCommon/jsi/jsi/instrumentation.h b/packages/react-native/ReactCommon/jsi/jsi/instrumentation.h index e841af07df8..726858ccde2 100644 --- a/packages/react-native/ReactCommon/jsi/jsi/instrumentation.h +++ b/packages/react-native/ReactCommon/jsi/jsi/instrumentation.h @@ -25,6 +25,12 @@ namespace jsi { /// it modify the values of any jsi values in the heap (although GCs are fine). class JSI_EXPORT Instrumentation { public: + /// Additional options controlling what to include when capturing a heap + /// snapshot. + struct HeapSnapshotOptions { + bool captureNumericValue{false}; + }; + virtual ~Instrumentation() = default; /// Returns GC statistics as a JSON-encoded string, with an object containing @@ -91,13 +97,19 @@ class JSI_EXPORT Instrumentation { /// Captures the heap to a file /// - /// \param path to save the heap capture - virtual void createSnapshotToFile(const std::string& path) = 0; + /// \param path to save the heap capture. + /// \param options additional options for what to capture. + virtual void createSnapshotToFile( + const std::string& path, + const HeapSnapshotOptions& options = {false}) = 0; /// Captures the heap to an output stream /// /// \param os output stream to write to. - virtual void createSnapshotToStream(std::ostream& os) = 0; + /// \param options additional options for what to capture. + virtual void createSnapshotToStream( + std::ostream& os, + const HeapSnapshotOptions& options = {false}) = 0; /// If the runtime has been created to trace to a temp file, flush /// any unwritten parts of the trace of bridge traffic to the file, diff --git a/packages/react-native/ReactCommon/jsi/jsi/jsi.cpp b/packages/react-native/ReactCommon/jsi/jsi/jsi.cpp index 2d1003f1f83..3a54aa1751c 100644 --- a/packages/react-native/ReactCommon/jsi/jsi/jsi.cpp +++ b/packages/react-native/ReactCommon/jsi/jsi/jsi.cpp @@ -109,12 +109,16 @@ Instrumentation& Runtime::instrumentation() { void startHeapSampling(size_t) override {} void stopHeapSampling(std::ostream&) override {} - void createSnapshotToFile(const std::string&) override { + void createSnapshotToFile( + const std::string& /*path*/, + const HeapSnapshotOptions& /*options*/) override { throw JSINativeException( "Default instrumentation cannot create a heap snapshot"); } - void createSnapshotToStream(std::ostream&) override { + void createSnapshotToStream( + std::ostream& /*os*/, + const HeapSnapshotOptions& /*options*/) override { throw JSINativeException( "Default instrumentation cannot create a heap snapshot"); }