Commit c2a5fa5b authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Trace events for memory pressure notification and external memory

This adds the following trace events to help diagnose GC scheduling
issues:
- V8.MemoryPressureNotification
- V8.CheckMemoryPressure
- V8.ExternalMemoryPressure

Bug: chromium:1072746
Change-Id: If850fc3d0f419395f22ec05b1779797916e39798
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2159487Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67311}
parent 308914cc
...@@ -1446,9 +1446,15 @@ void Heap::ReportExternalMemoryPressure() { ...@@ -1446,9 +1446,15 @@ void Heap::ReportExternalMemoryPressure() {
static_cast<GCCallbackFlags>( static_cast<GCCallbackFlags>(
kGCCallbackFlagSynchronousPhantomCallbackProcessing | kGCCallbackFlagSynchronousPhantomCallbackProcessing |
kGCCallbackFlagCollectAllExternalMemory); kGCCallbackFlagCollectAllExternalMemory);
if (isolate()->isolate_data()->external_memory_ > int64_t current = isolate()->isolate_data()->external_memory_;
(isolate()->isolate_data()->external_memory_low_since_mark_compact_ + int64_t baseline =
external_memory_hard_limit())) { isolate()->isolate_data()->external_memory_low_since_mark_compact_;
int64_t limit = isolate()->isolate_data()->external_memory_limit_;
TRACE_EVENT2(
"v8,devtools.timeline", "V8.ExternalMemoryPressure", "external_memory_mb",
static_cast<int>((current - baseline) / MB), "external_memory_limit_mb",
static_cast<int>((limit - baseline) / MB));
if (current > baseline + external_memory_hard_limit()) {
CollectAllGarbage( CollectAllGarbage(
kReduceMemoryFootprintMask, kReduceMemoryFootprintMask,
GarbageCollectionReason::kExternalMemoryPressure, GarbageCollectionReason::kExternalMemoryPressure,
...@@ -1472,10 +1478,7 @@ void Heap::ReportExternalMemoryPressure() { ...@@ -1472,10 +1478,7 @@ void Heap::ReportExternalMemoryPressure() {
const double kMaxStepSize = 10; const double kMaxStepSize = 10;
const double ms_step = Min( const double ms_step = Min(
kMaxStepSize, kMaxStepSize,
Max(kMinStepSize, Max(kMinStepSize, static_cast<double>(current) / limit * kMinStepSize));
static_cast<double>(isolate()->isolate_data()->external_memory_) /
isolate()->isolate_data()->external_memory_limit_ *
kMinStepSize));
const double deadline = MonotonicallyIncreasingTimeInMs() + ms_step; const double deadline = MonotonicallyIncreasingTimeInMs() + ms_step;
// Extend the gc callback flags with external memory flags. // Extend the gc callback flags with external memory flags.
current_gc_callback_flags_ = static_cast<GCCallbackFlags>( current_gc_callback_flags_ = static_cast<GCCallbackFlags>(
...@@ -3761,9 +3764,11 @@ void Heap::CheckMemoryPressure() { ...@@ -3761,9 +3764,11 @@ void Heap::CheckMemoryPressure() {
// the finalizers. // the finalizers.
memory_pressure_level_ = MemoryPressureLevel::kNone; memory_pressure_level_ = MemoryPressureLevel::kNone;
if (memory_pressure_level == MemoryPressureLevel::kCritical) { if (memory_pressure_level == MemoryPressureLevel::kCritical) {
TRACE_EVENT0("v8,devtools.timeline", "V8.CheckMemoryPressure");
CollectGarbageOnMemoryPressure(); CollectGarbageOnMemoryPressure();
} else if (memory_pressure_level == MemoryPressureLevel::kModerate) { } else if (memory_pressure_level == MemoryPressureLevel::kModerate) {
if (FLAG_incremental_marking && incremental_marking()->IsStopped()) { if (FLAG_incremental_marking && incremental_marking()->IsStopped()) {
TRACE_EVENT0("v8,devtools.timeline", "V8.CheckMemoryPressure");
StartIncrementalMarking(kReduceMemoryFootprintMask, StartIncrementalMarking(kReduceMemoryFootprintMask,
GarbageCollectionReason::kMemoryPressure); GarbageCollectionReason::kMemoryPressure);
} }
...@@ -3814,6 +3819,8 @@ void Heap::CollectGarbageOnMemoryPressure() { ...@@ -3814,6 +3819,8 @@ void Heap::CollectGarbageOnMemoryPressure() {
void Heap::MemoryPressureNotification(MemoryPressureLevel level, void Heap::MemoryPressureNotification(MemoryPressureLevel level,
bool is_isolate_locked) { bool is_isolate_locked) {
TRACE_EVENT1("v8,devtools.timeline", "V8.MemoryPressureNotification", "level",
static_cast<int>(level));
MemoryPressureLevel previous = memory_pressure_level_; MemoryPressureLevel previous = memory_pressure_level_;
memory_pressure_level_ = level; memory_pressure_level_ = level;
if ((previous != MemoryPressureLevel::kCritical && if ((previous != MemoryPressureLevel::kCritical &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment