Skip to content

Commit

Permalink
Add option to force GC before printing stats
Browse files Browse the repository at this point in the history
Summary:
Add option to force GC before printing stats when running a synth trace on the command-line. This allows measuring the live data when execution stopped at some interesting marker (under "heapInfo"->"Allocated bytes"). This enables estimating the impact of a diff on the live size of an application (rather than just total allocation, or allocated after the last organic collection).

Also add it for the hermes command-line tool, mostly for consistency.

Reviewed By: dulinriley

Differential Revision: D16603771

fbshipit-source-id: 69421e623a0cdc72e2071ee980fa100d0b2d6ded
  • Loading branch information
kodafb authored and facebook-github-bot committed Aug 1, 2019
1 parent c230beb commit cab0dc7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions API/hermes/TraceInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,9 @@ void TraceInterpreter::addObjectToDefs(
}

std::string TraceInterpreter::printStats() {
if (options.forceGCBeforeStats) {
rt.instrumentation().collectGarbage();
}
std::string stats = rt.instrumentation().getRecordedGCStats();
::hermes::vm::instrumentation::PerfEvents::endAndInsertStats(stats);
#ifdef HERMESVM_PROFILER_OPCODE
Expand Down
1 change: 1 addition & 0 deletions API/hermes/TraceInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TraceInterpreter final {
::hermes::vm::gcheapsize_t maxHeapSize{0};
bool allocInYoung{true};
bool revertToYGAtTTI{true};
bool forceGCBeforeStats{false};
bool shouldPrintGCStats{false};
bool shouldTrackIO{false};
uint8_t bytecodeWarmupPercent{0};
Expand Down
3 changes: 3 additions & 0 deletions include/hermes/ConsoleHost/ConsoleHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ struct ExecuteOptions {

/// Fatally crash on any JIT compilation error.
bool jitCrashOnError{false};

/// Perform a full GC just before printing any statistics.
bool forceGCBeforeStats{false};
};

/// Executes the HBC bytecode provided in HermesVM.
Expand Down
3 changes: 3 additions & 0 deletions lib/ConsoleHost/ConsoleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ bool executeHBCBytecode(
llvm::errs() << "Process stats:\n";
statSampler->stop().printJSON(llvm::errs());

if (options.forceGCBeforeStats) {
runtime->collect();
}
printStats(runtime.get(), llvm::errs());
}

Expand Down
9 changes: 8 additions & 1 deletion tools/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ static opt<bool> GCRevertToYGAtTTI(
cat(GCCategory),
init(false));

static opt<bool> GCBeforeStats(
"gc-before-stats",
desc("Perform a full GC just before printing statistics at exit"),
cat(GCCategory),
init(false));

static opt<bool> GCPrintStats(
"gc-print-stats",
desc("Output summary garbage collection statistics at exit"),
Expand Down Expand Up @@ -97,7 +103,7 @@ static int executeHBCBytecodeFromCL(
.withRandomSeed(cl::GCSanitizeRandomSeed)
.build())
.withShouldRandomizeAllocSpace(cl::GCRandomizeAllocSpace)
.withShouldRecordStats(cl::GCPrintStats)
.withShouldRecordStats(cl::GCPrintStats || cl::GCBeforeStats)
.withShouldReleaseUnused(false)
.withAllocInYoung(cl::GCAllocYoung)
.withRevertToYGAtTTI(cl::GCRevertToYGAtTTI)
Expand All @@ -123,6 +129,7 @@ static int executeHBCBytecodeFromCL(
options.dumpJITCode = cl::DumpJITCode;
options.jitCrashOnError = cl::JITCrashOnError;
options.stopAfterInit = cl::StopAfterInit;
options.forceGCBeforeStats = cl::GCBeforeStats;

bool success;
if (cl::Repeat <= 1) {
Expand Down
9 changes: 8 additions & 1 deletion tools/synth/synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ static opt<bool> GCRevertToYGAtTTI(
cat(GCCategory),
init(true));

static opt<bool> GCBeforeStats(
"gc-before-stats",
desc("Perform a full GC just before printing statistics at exit"),
cat(GCCategory),
init(false));

static opt<bool> GCPrintStats(
"gc-print-stats",
desc("Output summary garbage collection statistics at exit"),
Expand Down Expand Up @@ -111,7 +117,8 @@ int main(int argc, char **argv) {
options.maxHeapSize = cl::MaxHeapSize.bytes;
options.allocInYoung = cl::GCAllocYoung;
options.revertToYGAtTTI = cl::GCRevertToYGAtTTI;
options.shouldPrintGCStats = cl::GCPrintStats;
options.forceGCBeforeStats = cl::GCBeforeStats;
options.shouldPrintGCStats = cl::GCPrintStats || cl::GCBeforeStats;
options.shouldTrackIO = cl::TrackBytecodeIO;
options.bytecodeWarmupPercent = cl::BytecodeWarmupPercent;
options.sanitizeRate = cl::GCSanitizeRate;
Expand Down

0 comments on commit cab0dc7

Please sign in to comment.