Skip to content

Commit

Permalink
Unsubscribe heap callbacks on destruction
Browse files Browse the repository at this point in the history
Summary: Disable heap object stack tracing upon destruction.

Reviewed By: dannysu

Differential Revision: D49477452

fbshipit-source-id: d7984c8293351727df1cf734bcb634647a1c578c
  • Loading branch information
Matt Blagden authored and facebook-github-bot committed Sep 23, 2023
1 parent 1022ad6 commit ee2922a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions API/hermes/inspector/chrome/CDPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ class CDPHandler::Impl : public message::RequestHandler,
/// calls to didPause.
bool inDidPause_ = false;

/// Track whether heap object stack trace collection is active (i.e.
/// \p startTrackingHeapObjectStackTraces has been called without a
/// corresponding \p stopTrackingHeapObjectStackTraces).
bool trackingHeapObjectStackTraces_ = false;

Attachment currentAttachment_ = Attachment::None;
Execution currentExecution_ = Execution::Running;
std::unordered_map<int, Script> loadedScripts_;
Expand Down Expand Up @@ -412,6 +417,10 @@ CDPHandler::Impl::~Impl() {

runtime_.getDebugger().setEventObserver(nullptr);

if (trackingHeapObjectStackTraces_) {
runtime_.instrumentation().stopTrackingHeapObjectStackTraces();
}

// TODO(T161620474): Properly clean up all the other variables being protected
// by other mutex
}
Expand Down Expand Up @@ -579,6 +588,7 @@ void CDPHandler::Impl::sendSnapshot(
// snapshot.
if (stopStackTraceCapture) {
runtime_.instrumentation().stopTrackingHeapObjectStackTraces();
trackingHeapObjectStackTraces_ = false;
}

if (reportProgress) {
Expand Down Expand Up @@ -672,6 +682,7 @@ void CDPHandler::Impl::handle(
// there's a huge amount of allocation and freeing.
sendNotificationToClient(heapStatsNote);
});
trackingHeapObjectStackTraces_ = true;
sendResponseToClient(m::makeOkResponse(req.id));
});
}
Expand Down

0 comments on commit ee2922a

Please sign in to comment.