Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory profiler patches #399

Merged
merged 6 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API/hermes/TraceInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ bool TraceInterpreter::ifObjectAddToDefs(

std::string TraceInterpreter::printStats() {
if (options_.forceGCBeforeStats) {
rt_.instrumentation().collectGarbage();
rt_.instrumentation().collectGarbage("forced for stats");
}
std::string stats = rt_.instrumentation().getRecordedGCStats();
::hermes::vm::instrumentation::PerfEvents::endAndInsertStats(stats);
Expand Down
12 changes: 8 additions & 4 deletions API/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,17 @@ class HermesRuntimeImpl final : public HermesRuntime,
}

// Overridden from jsi::Instrumentation
void collectGarbage() override {
runtime_.getHeap().collect();
void collectGarbage(std::string cause) override {
runtime_.collect(std::move(cause));
}

// Overridden from jsi::Instrumentation
void startTrackingHeapObjectStackTraces() override {
runtime_.enableAllocationLocationTracker();
void startTrackingHeapObjectStackTraces(
std::function<void(
uint64_t,
std::chrono::microseconds,
std::vector<HeapStatsUpdate>)> fragmentCallback) override {
runtime_.enableAllocationLocationTracker(std::move(fragmentCallback));
}

// Overridden from jsi::Instrumentation
Expand Down
13 changes: 9 additions & 4 deletions API/jsi/jsi/decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,17 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
return plain().instrumentation().getHeapInfo(includeExpensive);
}

void collectGarbage() override {
plain().instrumentation().collectGarbage();
void collectGarbage(std::string cause) override {
plain().instrumentation().collectGarbage(std::move(cause));
}

void startTrackingHeapObjectStackTraces() override {
plain().instrumentation().startTrackingHeapObjectStackTraces();
void startTrackingHeapObjectStackTraces(
std::function<void(
uint64_t,
std::chrono::microseconds,
std::vector<HeapStatsUpdate>)> callback) override {
plain().instrumentation().startTrackingHeapObjectStackTraces(
std::move(callback));
}

void stopTrackingHeapObjectStackTraces() override {
Expand Down
23 changes: 20 additions & 3 deletions API/jsi/jsi/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#pragma once

#include <chrono>
#include <iosfwd>
#include <string>
#include <tuple>
#include <unordered_map>

#include <jsi/jsi.h>
Expand Down Expand Up @@ -49,12 +51,27 @@ class JSI_EXPORT Instrumentation {
virtual std::unordered_map<std::string, int64_t> getHeapInfo(
bool includeExpensive) = 0;

/// perform a full garbage collection
virtual void collectGarbage() = 0;
/// Perform a full garbage collection.
/// \param cause The cause of this collection, as it should be reported in
/// logs.
virtual void collectGarbage(std::string cause) = 0;

/// A HeapStatsUpdate is a tuple of the fragment index, the number of objects
/// in that fragment, and the number of bytes used by those objects.
/// A "fragment" is a view of all objects allocated within a time slice.
using HeapStatsUpdate = std::tuple<uint64_t, uint64_t, uint64_t>;

/// Start capturing JS stack-traces for all JS heap allocated objects. These
/// can be accessed via \c ::createSnapshotToFile().
virtual void startTrackingHeapObjectStackTraces() = 0;
/// \param fragmentCallback If present, invoke this callback every so often
/// with the most recently seen object ID, and a list of fragments that have
/// been updated. This callback will be invoked on the same thread that the
/// runtime is using.
virtual void startTrackingHeapObjectStackTraces(
std::function<void(
uint64_t lastSeenObjectID,
std::chrono::microseconds timestamp,
std::vector<HeapStatsUpdate> stats)> fragmentCallback) = 0;

/// Stop capture JS stack-traces for JS heap allocated objects.
virtual void stopTrackingHeapObjectStackTraces() = 0;
Expand Down
8 changes: 6 additions & 2 deletions API/jsi/jsi/jsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ Instrumentation& Runtime::instrumentation() {
return std::unordered_map<std::string, int64_t>{};
}

void collectGarbage() override {}
void collectGarbage(std::string) override {}

void startTrackingHeapObjectStackTraces() override {}
void startTrackingHeapObjectStackTraces(
std::function<void(
uint64_t,
std::chrono::microseconds,
std::vector<HeapStatsUpdate>)>) override {}
void stopTrackingHeapObjectStackTraces() override {}

void createSnapshotToFile(const std::string&) override {
Expand Down
99 changes: 0 additions & 99 deletions include/hermes/Support/SamplingThread.h

This file was deleted.

Loading