Skip to content

Commit

Permalink
Plumb through memory allocation profiler feature to Chrome Inspector
Browse files Browse the repository at this point in the history
Summary: Changelog: Make allocation profiler feature of Chome Inspector work

Reviewed By: dulinriley

Differential Revision: D20383003

fbshipit-source-id: 8a10c310d5a639a6644763adb53f2f0017057587
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Mar 31, 2020
1 parent 7c7f915 commit 71cffc8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion API/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,16 @@ class HermesRuntimeImpl final : public HermesRuntime,
runtime_.getHeap().collect();
}

// Overridden from jsi::Instrumentation
void startTrackingHeapObjectStackTraces() override {
runtime_.enableAllocationLocationTracker();
}

// Overridden from jsi::Instrumentation
void stopTrackingHeapObjectStackTraces() override {
runtime_.disableAllocationLocationTracker();
}

// Overridden from jsi::Instrumentation
void createSnapshotToFile(const std::string &path) override {
std::error_code code;
Expand Down Expand Up @@ -932,7 +942,7 @@ class HermesRuntimeImpl final : public HermesRuntime,
template <typename T>
struct ManagedValues {
#ifdef ASSERT_ON_DANGLING_VM_REFS
// If we have active HermesValuePointers whhen deconstructing, these will
// If we have active HermesValuePointers when deconstructing, these will
// now be dangling. We deliberately allocate and immediately leak heap
// memory to hold the internal list. This keeps alive memory holding the
// ref-count of the now dangling references, allowing them to detect the
Expand Down
8 changes: 8 additions & 0 deletions API/jsi/jsi/decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
plain().instrumentation().collectGarbage();
}

void startTrackingHeapObjectStackTraces() override {
plain().instrumentation().startTrackingHeapObjectStackTraces();
}

void stopTrackingHeapObjectStackTraces() override {
plain().instrumentation().stopTrackingHeapObjectStackTraces();
}

void createSnapshotToFile(const std::string& path) override {
plain().instrumentation().createSnapshotToFile(path);
}
Expand Down
7 changes: 7 additions & 0 deletions API/jsi/jsi/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class Instrumentation {
/// perform a full garbage collection
virtual void collectGarbage() = 0;

/// Start capturing JS stack-traces for all JS heap allocated objects. These
/// can be accessed via \c ::createSnapshotToFile().
virtual void startTrackingHeapObjectStackTraces() = 0;

/// Stop capture JS stack-traces for JS heap allocated objects.
virtual void stopTrackingHeapObjectStackTraces() = 0;

/// Captures the heap to a file
///
/// \param path to save the heap capture
Expand Down
3 changes: 3 additions & 0 deletions API/jsi/jsi/jsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Instrumentation& Runtime::instrumentation() {

void collectGarbage() override {}

void startTrackingHeapObjectStackTraces() override {}
void stopTrackingHeapObjectStackTraces() override {}

void createSnapshotToFile(const std::string&) override {
throw JSINativeException(
"Default instrumentation cannot create a heap snapshot");
Expand Down

0 comments on commit 71cffc8

Please sign in to comment.