Commit 01d5da4b authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Make top-level GC histograms nestable.

This changes the GC histograms from HistogramTimer to TimedHistogram.

Bug: chromium:898613
Change-Id: Ie18c6dd3b958c3ce93f0f84faec0f306d699afa0
Reviewed-on: https://chromium-review.googlesource.com/c/1299241
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57036}
parent f3b84930
...@@ -305,6 +305,34 @@ class TimedHistogramScope { ...@@ -305,6 +305,34 @@ class TimedHistogramScope {
DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope); DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope);
}; };
enum class OptionalTimedHistogramScopeMode { TAKE_TIME, DONT_TAKE_TIME };
// Helper class for scoping a TimedHistogram.
// It will not take time for mode = DONT_TAKE_TIME.
class OptionalTimedHistogramScope {
public:
OptionalTimedHistogramScope(TimedHistogram* histogram, Isolate* isolate,
OptionalTimedHistogramScopeMode mode)
: histogram_(histogram), isolate_(isolate), mode_(mode) {
if (mode == OptionalTimedHistogramScopeMode::TAKE_TIME) {
histogram_->Start(&timer_, isolate);
}
}
~OptionalTimedHistogramScope() {
if (mode_ == OptionalTimedHistogramScopeMode::TAKE_TIME) {
histogram_->Stop(&timer_, isolate_);
}
}
private:
base::ElapsedTimer timer_;
TimedHistogram* const histogram_;
Isolate* const isolate_;
const OptionalTimedHistogramScopeMode mode_;
DISALLOW_IMPLICIT_CONSTRUCTORS(OptionalTimedHistogramScope);
};
// Helper class for recording a TimedHistogram asynchronously with manual // Helper class for recording a TimedHistogram asynchronously with manual
// controls (it will not generate a report if destroyed without explicitly // controls (it will not generate a report if destroyed without explicitly
// triggering a report). |async_counters| should be a shared_ptr to // triggering a report). |async_counters| should be a shared_ptr to
...@@ -435,27 +463,6 @@ class HistogramTimerScope { ...@@ -435,27 +463,6 @@ class HistogramTimerScope {
#endif #endif
}; };
enum class OptionalHistogramTimerScopeMode { TAKE_TIME, DONT_TAKE_TIME };
// Helper class for scoping a HistogramTimer.
// It will not take time if take_time is set to false.
class OptionalHistogramTimerScope {
public:
OptionalHistogramTimerScope(HistogramTimer* timer,
OptionalHistogramTimerScopeMode mode)
: timer_(timer), mode_(mode) {
if (mode == OptionalHistogramTimerScopeMode::TAKE_TIME) timer_->Start();
}
~OptionalHistogramTimerScope() {
if (mode_ == OptionalHistogramTimerScopeMode::TAKE_TIME) timer_->Stop();
}
private:
HistogramTimer* timer_;
OptionalHistogramTimerScopeMode mode_;
};
// A histogram timer that can aggregate events within a larger scope. // A histogram timer that can aggregate events within a larger scope.
// //
// Intended use of this timer is to have an outer (aggregating) and an inner // Intended use of this timer is to have an outer (aggregating) and an inner
...@@ -1225,21 +1232,6 @@ class RuntimeCallTimerScope { ...@@ -1225,21 +1232,6 @@ class RuntimeCallTimerScope {
#define HISTOGRAM_TIMER_LIST(HT) \ #define HISTOGRAM_TIMER_LIST(HT) \
/* Garbage collection timers. */ \ /* Garbage collection timers. */ \
HT(gc_compactor, V8.GCCompactor, 10000, MILLISECOND) \
HT(gc_compactor_background, V8.GCCompactorBackground, 10000, MILLISECOND) \
HT(gc_compactor_foreground, V8.GCCompactorForeground, 10000, MILLISECOND) \
HT(gc_finalize, V8.GCFinalizeMC, 10000, MILLISECOND) \
HT(gc_finalize_background, V8.GCFinalizeMCBackground, 10000, MILLISECOND) \
HT(gc_finalize_foreground, V8.GCFinalizeMCForeground, 10000, MILLISECOND) \
HT(gc_finalize_reduce_memory, V8.GCFinalizeMCReduceMemory, 10000, \
MILLISECOND) \
HT(gc_finalize_reduce_memory_background, \
V8.GCFinalizeMCReduceMemoryBackground, 10000, MILLISECOND) \
HT(gc_finalize_reduce_memory_foreground, \
V8.GCFinalizeMCReduceMemoryForeground, 10000, MILLISECOND) \
HT(gc_scavenger, V8.GCScavenger, 10000, MILLISECOND) \
HT(gc_scavenger_background, V8.GCScavengerBackground, 10000, MILLISECOND) \
HT(gc_scavenger_foreground, V8.GCScavengerForeground, 10000, MILLISECOND) \
HT(gc_context, V8.GCContext, 10000, \ HT(gc_context, V8.GCContext, 10000, \
MILLISECOND) /* GC context cleanup time */ \ MILLISECOND) /* GC context cleanup time */ \
HT(gc_idle_notification, V8.GCIdleNotification, 10000, MILLISECOND) \ HT(gc_idle_notification, V8.GCIdleNotification, 10000, MILLISECOND) \
...@@ -1270,6 +1262,23 @@ class RuntimeCallTimerScope { ...@@ -1270,6 +1262,23 @@ class RuntimeCallTimerScope {
MICROSECOND) MICROSECOND)
#define TIMED_HISTOGRAM_LIST(HT) \ #define TIMED_HISTOGRAM_LIST(HT) \
/* Garbage collection timers. */ \
HT(gc_compactor, V8.GCCompactor, 10000, MILLISECOND) \
HT(gc_compactor_background, V8.GCCompactorBackground, 10000, MILLISECOND) \
HT(gc_compactor_foreground, V8.GCCompactorForeground, 10000, MILLISECOND) \
HT(gc_finalize, V8.GCFinalizeMC, 10000, MILLISECOND) \
HT(gc_finalize_background, V8.GCFinalizeMCBackground, 10000, MILLISECOND) \
HT(gc_finalize_foreground, V8.GCFinalizeMCForeground, 10000, MILLISECOND) \
HT(gc_finalize_reduce_memory, V8.GCFinalizeMCReduceMemory, 10000, \
MILLISECOND) \
HT(gc_finalize_reduce_memory_background, \
V8.GCFinalizeMCReduceMemoryBackground, 10000, MILLISECOND) \
HT(gc_finalize_reduce_memory_foreground, \
V8.GCFinalizeMCReduceMemoryForeground, 10000, MILLISECOND) \
HT(gc_scavenger, V8.GCScavenger, 10000, MILLISECOND) \
HT(gc_scavenger_background, V8.GCScavengerBackground, 10000, MILLISECOND) \
HT(gc_scavenger_foreground, V8.GCScavengerForeground, 10000, MILLISECOND) \
/* Wasm timers. */ \
HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \
1000000, MICROSECOND) \ 1000000, MICROSECOND) \
HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \
......
...@@ -1096,7 +1096,7 @@ void GCTracer::AddBackgroundScopeSample( ...@@ -1096,7 +1096,7 @@ void GCTracer::AddBackgroundScopeSample(
} }
} }
void GCTracer::RecordGCPhasesHistograms(HistogramTimer* gc_timer) { void GCTracer::RecordGCPhasesHistograms(TimedHistogram* gc_timer) {
Counters* counters = heap_->isolate()->counters(); Counters* counters = heap_->isolate()->counters();
if (gc_timer == counters->gc_finalize()) { if (gc_timer == counters->gc_finalize()) {
DCHECK_EQ(Scope::FIRST_TOP_MC_SCOPE, Scope::MC_CLEAR); DCHECK_EQ(Scope::FIRST_TOP_MC_SCOPE, Scope::MC_CLEAR);
......
...@@ -321,7 +321,7 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -321,7 +321,7 @@ class V8_EXPORT_PRIVATE GCTracer {
void AddBackgroundScopeSample(BackgroundScope::ScopeId scope, double duration, void AddBackgroundScopeSample(BackgroundScope::ScopeId scope, double duration,
RuntimeCallCounter* runtime_call_counter); RuntimeCallCounter* runtime_call_counter);
void RecordGCPhasesHistograms(HistogramTimer* gc_timer); void RecordGCPhasesHistograms(TimedHistogram* gc_timer);
private: private:
FRIEND_TEST(GCTracer, AverageSpeed); FRIEND_TEST(GCTracer, AverageSpeed);
......
...@@ -994,7 +994,7 @@ void Heap::ScheduleIdleScavengeIfNeeded(int bytes_allocated) { ...@@ -994,7 +994,7 @@ void Heap::ScheduleIdleScavengeIfNeeded(int bytes_allocated) {
scavenge_job_->ScheduleIdleTaskIfNeeded(this, bytes_allocated); scavenge_job_->ScheduleIdleTaskIfNeeded(this, bytes_allocated);
} }
HistogramTimer* Heap::GCTypePriorityTimer(GarbageCollector collector) { TimedHistogram* Heap::GCTypePriorityTimer(GarbageCollector collector) {
if (IsYoungGenerationCollector(collector)) { if (IsYoungGenerationCollector(collector)) {
if (isolate_->IsIsolateInBackground()) { if (isolate_->IsIsolateInBackground()) {
return isolate_->counters()->gc_scavenger_background(); return isolate_->counters()->gc_scavenger_background();
...@@ -1022,7 +1022,7 @@ HistogramTimer* Heap::GCTypePriorityTimer(GarbageCollector collector) { ...@@ -1022,7 +1022,7 @@ HistogramTimer* Heap::GCTypePriorityTimer(GarbageCollector collector) {
} }
} }
HistogramTimer* Heap::GCTypeTimer(GarbageCollector collector) { TimedHistogram* Heap::GCTypeTimer(GarbageCollector collector) {
if (IsYoungGenerationCollector(collector)) { if (IsYoungGenerationCollector(collector)) {
return isolate_->counters()->gc_scavenger(); return isolate_->counters()->gc_scavenger();
} else { } else {
...@@ -1285,17 +1285,17 @@ bool Heap::CollectGarbage(AllocationSpace space, ...@@ -1285,17 +1285,17 @@ bool Heap::CollectGarbage(AllocationSpace space,
GarbageCollectionPrologue(); GarbageCollectionPrologue();
{ {
HistogramTimer* gc_type_timer = GCTypeTimer(collector); TimedHistogram* gc_type_timer = GCTypeTimer(collector);
HistogramTimerScope histogram_timer_scope(gc_type_timer); TimedHistogramScope histogram_timer_scope(gc_type_timer, isolate_);
TRACE_EVENT0("v8", gc_type_timer->name()); TRACE_EVENT0("v8", gc_type_timer->name());
HistogramTimer* gc_type_priority_timer = GCTypePriorityTimer(collector); TimedHistogram* gc_type_priority_timer = GCTypePriorityTimer(collector);
OptionalHistogramTimerScopeMode mode = OptionalTimedHistogramScopeMode mode =
isolate_->IsMemorySavingsModeActive() isolate_->IsMemorySavingsModeActive()
? OptionalHistogramTimerScopeMode::DONT_TAKE_TIME ? OptionalTimedHistogramScopeMode::DONT_TAKE_TIME
: OptionalHistogramTimerScopeMode::TAKE_TIME; : OptionalTimedHistogramScopeMode::TAKE_TIME;
OptionalHistogramTimerScope histogram_timer_priority_scope( OptionalTimedHistogramScope histogram_timer_priority_scope(
gc_type_priority_timer, mode); gc_type_priority_timer, isolate_, mode);
next_gc_likely_to_collect_more = next_gc_likely_to_collect_more =
PerformGarbageCollection(collector, gc_callback_flags); PerformGarbageCollection(collector, gc_callback_flags);
......
...@@ -81,6 +81,7 @@ class ScavengerCollector; ...@@ -81,6 +81,7 @@ class ScavengerCollector;
class Space; class Space;
class StoreBuffer; class StoreBuffer;
class StressScavengeObserver; class StressScavengeObserver;
class TimedHistogram;
class TracePossibleWrapperReporter; class TracePossibleWrapperReporter;
class WeakObjectRetainer; class WeakObjectRetainer;
...@@ -1528,8 +1529,8 @@ class Heap { ...@@ -1528,8 +1529,8 @@ class Heap {
// - GCFinalzeMC: finalization of incremental full GC // - GCFinalzeMC: finalization of incremental full GC
// - GCFinalizeMCReduceMemory: finalization of incremental full GC with // - GCFinalizeMCReduceMemory: finalization of incremental full GC with
// memory reduction // memory reduction
HistogramTimer* GCTypeTimer(GarbageCollector collector); TimedHistogram* GCTypeTimer(GarbageCollector collector);
HistogramTimer* GCTypePriorityTimer(GarbageCollector collector); TimedHistogram* GCTypePriorityTimer(GarbageCollector collector);
// =========================================================================== // ===========================================================================
// Pretenuring. ============================================================== // Pretenuring. ==============================================================
......
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